Outils pour utilisateurs

Outils du site


issue197:latex

Ceci est une ancienne révision du document !


Now that the main body of the cookbook is starting to look like the way we want it, we will give some attention to what Tex calls the back matter. In this instalment, we will add an index and a glossary. The index will list on what pages certain ingredients are found. If the cook knows what they have on hand, they can find one or more recipes that use that particular ingredient. For cooks with experience of Chinese recipes, the glossary may not be needed, but there may be some cooks who need short explanations about what a particular ingredient is or what a particular method requires.

Like some other tasks we have already done, making an index requires a few additions to the main cookbook file, and additions to every recipe. The additions to the main cookbook file are quite simple. There are only three new instructions.

\usepackage{makeidx}

\makeindex

Both must appear in the preamble, and

\printindex

will appear at the location where we want the index to appear. The printindex instruction starts a new page, and puts the chapter title “Index” at the top of the page.

Words (or phrases) that should be listed in the index are identified using the command \index{…}. Of course, we must put the word or phrase into the curly braces, not the three dots. This is the process that needs to be done in each recipe. The index instruction can be used anywhere on the page where the key word appears. I find it convenient to put it right beside the ingredient name but it can be placed at the beginning or end of the list of ingredients, or even at the beginning or end of the recipe (as long as the recipe fits on one page). The index indicates the page where the key word is found.

When the main cookbook file is processed, each recipe file is output in turn. The index instruction makes a file of all the index key words and the page references. This generated file has the same name as the file with the makeindex instruction, and the file extension (file type) is idx. In our case, we get a file called fcm196index.idx. That file has to generate a sorted file which can be used by the printindex instruction to generate the index in the final PDF file. This second generated file has the same name as the idx file, but the file type (file extension) is now ind.

There is a menu item in TexStudio which will generate the necessary ind file. It is called Index, and is in the Tools menu. In Gummi, look in the Document menu for the Make Index item. Other GUIs for Tex should have a similar item somewhere in their menus.

After generating the ind file, then process the main file again in order for the printindex instruction to use the ind file and print the index in the chosen location.

To summarize: 1/ Compile / process the main file to generate a PDF and an idx file. 2/ Run makeindex to generate an ind file. 3/ Compile / process the main file to generate the final version of the PDF with an index.

There are options for the index instruction which will make the index entry look the way you wish. Here are some examples.

\index{flour} will display flour, 4

\index{flour!wholewheat}

will indent wholewheat as a sub-entry under flour followed by the page number. Sub-entries can go to a maximum of three levels (two exclamation marks)

\index{pork|see{meat}}

will give an entry without a page number that points the user to another index entry. ‘See’ can be replaced with ‘seealso’ to get See also in the index. The vertical line before see (or seealso) is required.

A number of packages on CTAN have additional functionality beyond that provided by makeidx. I refer you to ctan.org for more information about other packages as well as about other options for formatting index (page ranges, adding colour and text formatting, etc).

Glossary

In textbooks and other books of instruction, a glossary is a list of words or terms (almost always in alphabetical order) with explanations or definitions. The words or terms listed are often words or terms that occur repeatedly in the text. To define or explain the words or terms over and over would be tedious for the author, and boring for the reader. So those words and terms are gathered together in one section of the book, usually at the end before the index.

In Tex / Latex, a glossary is also a list of words or terms with definitions. As far as I can tell from the very limited information available, a Latex glossary is not a separate section in the back matter the way an index is. Instead it is a list of substitutes for acronyms which the user enters in the text. If the user types some instruction when the text is converted to a PDF the instruction expands to its full form. For example, if I use \tlx in several places it might expand to Tex/Latex in this article.

For the cookbook to have a traditional glossary, it needs to be set up as a chapter. I have built a separate file, and use the include instruction to add it to the back matter.

There is a separate environment which can be used to show terms and definitions. I have included a screenshot of the glossary chapter tex file so you can see the code. In Latex terms, what I used is a description list. It follows the patterns for the numbered and bulleted lists described in a much earlier article (FCM #181). The begin{} and end {} instructions start and stop the list. In a description list, the item instruction has two parameters: the term and the description. If you use the GUI TexStudio, you will have guidance in building lists and most other Latex instructions.

Look at the percent symbol in the glossary. There is a small detail you may have skipped over. In the code, there is a backslash before the percent symbol. Percent symbols can be used to specify certain Latex commands. If you wish to use it as a mathematical symbol, as I did in the glossary, then put the backslash in front of it.

Author’s Suggestion

If you are serious about using Latex/Tex for your own work, then I strongly urge you to join TUG, the Tex Users Group (tug.org). There is an annual subscription fee of $105 which has a $30 discount for students, seniors and residents of countries with modest economies. There is an additional $30 discount if you want an electronic membership, no materials will be shipped to you. Being a member entitles you to both printed and electronic versions of the latest edition of The Latex Companion. This is a two-volume work which contains more information about Latex than anyone will ever use. Each of the two volumes is about 950 pages, truly doorstop-sized encyclopedias. Even if you do not join TUG, the website has some resources you might use. Do not forget ctan.org has thousands of packages that can modify your installation of Tex/Latex so that it does what you need.

issue197/latex.1696088393.txt.gz · Dernière modification : 2023/09/30 17:39 de auntiee