Outils pour utilisateurs

Outils du site


issue199:latex

Ceci est une ancienne révision du document !


This might be the easiest and simplest task to do in Latex that we have encountered. To add hypertext links to a document, add the hyperref package to the document preamble. According to the documentation, it must be the last package. In the cookbook I have been building, that means the use package instruction will now look like this: \usepackage{inputenc, cooking, cooking-units, makeidx, hyperref}

Cela pourrait être la tâche la plus facile et la plus simple à faire dans Latex que nous avons rencontré.

Pour ajouter des liens hypertextes à un document, ajoutez le paquet hyperref au préambule du document. Selon la documentation, il doit s’agir du dernier paquet. Dans le livre de recettes que j’ai fait, cela signifie que les instructions d’utilisation ressembleront maintenant à ceci :

\usepackage{inputenc, cooking, cooking-units, makeidx, hyperref}

As you can see in Figure 1, there are now links in the Table of Contents to all of the chapter headings. This happens automatically with the hyperref package. The formatting you see is the default formatting with this package. I do not like the red boxes around each link, and I will change those using features of the hyperref package. Looking at the recipe for Steamed Buns, you can see a citation. There is also a hot link to the work in the Bibliography to match this citation. This kind of link has a green box around it, again it’s not the formatting I like, so I hope to change it. I did not build any links for the items in the Glossary. I could add those links into the relevant files. I note there is no way in the initial document to return to the Table of Contents after having read a recipe. I will also take a look at using the Table of Contents to make a Bookmarks column in the generated PDF.

Comme vous pouvez le voir à la figure 1, il y a maintenant des liens dans la table des matières vers tous les titres de chapitre. Cela se produit automatiquement avec le paquet hyperref. Le formatage que vous voyez est le formatage par défaut avec ce paquet. Je n’aime pas les cadres rouges autour de chaque lien, et je vais les changer en utilisant les fonctionnalités du paquet hyperref.

En regardant la recette pour les petits pains cuits à la vapeur, vous pouvez voir une citation. Il y a aussi un lien vers l'entrée correspondant à cette citation dans la bibliographie. Ce type de lien a un cadre vert autour de lui, encore une fois ce n’est pas le formatage que j’aime, donc j’espère le changer.

Je n’ai pas créé de liens pour les éléments du glossaire. Je pourrais ajouter ces liens dans les fichiers pertinents. Je constate qu’il n’y a aucun moyen dans le document initial de revenir à la table des matières après avoir lu une recette. Je vais également jeter un coup d’œil à l’utilisation de la table des matières pour créer une colonne Signets dans le PDF généré.

Formatting links In order to learn how to format the automatically generated links using hyperref, I read through the documentation for the hyperref package. I know reading the manual is counter-intuitive for many people involved in IT. Things should be self-explanatory. I agree – most software should be self-explanatory, but most software is not. That is why software developers write manuals. If you intend to use an unfamiliar package in your work with Latex, I encourage you to read any documentation that comes with the package and / or read the relevant pages in The Latex Companion by Mittelbach and Fischer. (The third edition was released earlier this year, ISBN 978-0-465894-0.) The documentation that comes with the hyperref package is not beginner-friendly. In particular, it could use more examples. Perhaps a separate document containing examples would be better than more text. A large number of possible options are available. In the case of this cookbook, I wanted some indication there were links, but I wanted to eliminate the boxes. I used the instruction hypersetup with two options. \hypersetup{pdfborder=0 0 0, colorlinks=true}

Mise en forme des liens

Afin d’apprendre à formater les liens générés automatiquement en utilisant hyperref, j’ai lu la documentation pour le paquet hyperref. Je sais que la lecture du manuel est contre-intuitive pour de nombreuses personnes impliquées dans l'IT. Les choses devraient être explicites. Je suis d’accord : la plupart des logiciels devraient être explicites, mais la plupart des logiciels ne le sont pas. C’est pourquoi les développeurs de logiciels rédigent des manuels. Si vous avez l’intention d’utiliser un paquet inconnu dans votre travail avec Latex, je vous encourage à lire toute documentation fournie avec le paquet et à lire les pages pertinentes dans The Latex Companion de Mittelbach et Fischer. (La troisième édition a été publiée plus tôt cette année, ISBN 978-0-465894-0.)

La documentation fournie avec le paquet hyperref n’est pas adaptée aux débutants. En particulier, elle pourrait utiliser plus d’exemples. Peut-être qu’un document séparé contenant des exemples serait mieux que plus de texte. Un grand nombre d’options possibles sont disponibles. Dans le cas de ce livre de cuisine, je voulais qu’il y ait des liens, mais je voulais éliminer les cadres. J’ai utilisé l’instruction hypersetup avec deux options.

\hypersetup{pdfborder=0 0 0, colorlinks=true}

The default for pdfborder is 0 0 1. Setting the last digit to 0 turns off the boxes. Having any positive value as the last digit makes the boxes visible. I used colorlinks=-true in order to have a visible indication some text was different from the main text. The default is colorlinks=false, no color for any of the hyperlinks. As you can see from the image, all of the text in the Table of Contents is now red, with no boxes or lines. If you view the PDF, the mouse cursor will change shape to indicate clickable links. The “back links” from recipes to the Table of Contents are also red. Links to the Bibliography are indicated by green text.

Links to Glossary

Setting up links between text in the recipes and the Glossary is not difficult. I could use the same process described in Return links to the Table of Contents. However, the return links should all point back to the same spot unless you want to make a lot of “back links” in the Glossary. For example, there is an entry in the Glossary for sesame oil. Several recipes use sesame oil. (Check the index to see how many pages have this ingredient.) You could set up separate links to every recipe using sesame oil. Then the reader would have to choose which one to get back to the recipe they were reading or using. Having all the back links point to the Table of Contents means the reader would need to remember which recipe they were using, then click from the Glossary to the Table of Contents, and then to the recipe they wish to use. While this is a little inconvenient for the user, it simplifies the coding, greatly reduces the time needed for coding, and generates only one back link for each entry in the Glossary, not one back link for every recipe where a specific ingredient occurs.

The simplest approach would be to put “see Glossary” in parentheses after the name of the ingredient. That might get tedious for the reader and would certainly get tiresome to input all those extra bits of text. Another solution would be to make a footnote in each recipe that contained an ingredient listed in the Glossary. The footnote would be “see Glossary”. Again that would be tiresome to type (or copy and paste) in all the relevant recipes but not so obtrusive for the reader. Neither of these methods takes advantage of the electronic links that are available with Latex in an on-screen PDF.

Ideally, every item in the Glossary would be matched to a pop-up item. If the user of the book hovers over an unknown term a box would pop up giving the information in the glossary. If I add the pdfcomment package to the document, this kind of popup or comment or annotation can be made available in the PDF version of the document. I hope it is obvious why popups are not available in printed documents. I hope it is also obvious why popups for the glossary are not necessary in a printed copy of this cookbook.

A simple electronic solution for chapter navigation would be a bookmark system, very common in PDF (and HTML) files – see below for PDF bookmarks.

Return links to Table of Contents

To go from one place in a document to another, the clickable link has to be coded and the target for the link also has to be coded. One way to do this is to use label and pageref instructions. The target, the Table of Contents, has to include an appropriate label.

\label{toc}

Once the hyperref package is being used, the pageref information automatically becomes a clickable link in the PDF document.

\pageref{toc}

Label names have to be unique within a document (or set of documents which is what we have built). I chose “toc” because it is easy to remember and obviously identifies the Table of Contents. However any alphanumeric combination is acceptable. The sentence I used is:

Return to Table of Contents \pageref{toc}

That is clear enough for just about anyone to understand, I think.

Table of Contents to Bookmarks

This is the easiest part. There is nothing to be done. Use a regular PDF document viewer to open the generated PDF document. The bookmarks are not visible in the view of the PDF document in Texstudio. However a regular PDF viewer will show you the Table of Contents as standard PDF bookmarks. If you do not see them, go through the menus in the PDF viewer and turn the bookmarks on.

Next Time

Next issue, I will experiment with modifications of the title page. It needs to look more professional than standard text. After that, I will be ready to finish modifying this little cookbook and move on to another project using Latex.

issue199/latex.1701178917.txt.gz · Dernière modification : 2023/11/28 14:41 de darkjam