Outils pour utilisateurs

Outils du site


issue201:latex

Ceci est une ancienne révision du document !


This time we will work with what we already know and take an adventure into a new area: style sheets. Assume you run a publishing company that specializes in cookbooks. You want all your cookbooks to have the same look. To make this easier for us we will use the “look” developed for “Favourite Chinese Recipes”, the last project in this series of articles. Of course no one likes typing the same information over and over. This is a great way to induce boredom and boredom leads to mistakes. How can we make sure every cookbook starts with the same set of formatting instructions? Simply place all of the desired formatting instructions into a file, save the file, then include that file in the preamble for every cookbook. To make identifying this style file easier in the jumble of files Latex uses the convention is to name a style file with an “sty” file type (file extension). I am going to call it “cookbook.sty”.

Theoretically we should then be able to use this customized style file in any document simply by telling Latex usepackage{cookbook.sty}. Of course it is not quite that simple. There are two more steps. First, any custom style files need to be stored in the same folder / directory as the default style files. Second, Latex-Tex needs to know there is an additional style file available. Where are the default style files stored? That will depend on your distribution, most likely somewhere in the texlive or texfm part of the directory tree. On my system it is /usr/share/texlive/texmf-dist/tex/latex and then a separate directory for each style file. So cookbook.sty needs to be put into the /usr/share/texlive/texmf-dist/tex/latex/cookbook directory. Once that is done then run the command texhash. This command records the locations of many of the parts of the Tex engine. Now it includes a pointer to the customized cookbook.sty file. Instead of typing all the instructions we used last time we only need to tell Latex to usepackage{cookbook} and all those instructions will automatically be used when the new cookbook PDF is generated. Just in case you are new to this series or forget what we had to type last time here is the listing (above).

We have not taken advantage of this usepackage feature of Latex. So far we have only used to to “turn on” certain desired features in our cookbook. I like the Noto font family and so used that package. Your book may use the default font family or a different font family. I wanted the cover to have a particular look (image within a frame and a shaded background to the image). I wanted the clickable links to use the default colours. Your choices could be different. I urge you to experiment with the various options available with these packages. I also urge you to find and use other packages with Latex. Now we know where to look let’s see if we can discover some useful and / or style files. My installation has over two thousand directories with style files. Some directories contain more than one style file. That is a lot of possible additions to the basic Latex package. CTAN has more than 6500 packages in its database. We will start our exploration of packages with gcard. In order to understand how some packages should be used we have to read the documentation. Here are some excerpts from the documentation for gcard. Load the package with \usepackage{gcard}

Before \begin{document} if you want to use margins different from the de#faults (0.2in for all), set four lengths to values of your choice: [content deleted] Then, after \begin document specify the contents of each panel with the frontcover, backcover, insideleft, and insideright environments. Each environment sets its contents in a minipage of width \panelwidth and height \panelheight. Those two lengths may be referenced, but not changed, anywhere after \begindocument. The material is vertically centered in the panel by default; to move it, use vertical spacing commands such as \vspace{} and \vfill. For example, you could specify the material for the front cover of the card with \begin{frontcover} \Large We heard you had a little trouble with the law \ldots \end{frontcover} The text will appear vertically centered on the front cover, with normal justification. You do not need to supply all four environments; panels corresponding to missing environments will be left blank. [End of documentation excerpt]

A little experimentation will show which panels you need to use for whatever design for a greeting card you want to use. This example uses only text but it is easy enough to add an image or two or three following the steps in the Latex article in Full Circle #184. Another example is the bizcard style file developed by Sebastian Kirsch for Latex 2e, which is the previous version of Latex. Even though it is more than twenty years old it works well with the current version. In order to know how to use bizcard properly go to CTAN, then download and read the documentation supplied by the author. Since bizcard is part of a default installation there is no need to download the package. The documentation is only five pages and the information that will be important to most users is on pages 2 and 3. I copied the code from the documentation into an image for this article. It shows the code needed to generate business cards for the developer of the package.

There is no line-by-line explanation of the code in the documentation. However the code should be reasonably understandable to most computer users. If you decide to make some business cards using this style file then you can experiment with the various measurements and options to get what is best for your situation. Remember to save various iterations of your experiments for reference later. (Of course if you do not need the special German characters then you can delete the unneeded code for them.) Another of the more than two thousand built-in styles is exercise. The documentation says: “This package offers a simple environment to typeset exercises, and their questions, sub-questions, indications, answers and so on. The layout of the exercises is fully customisable. Moreover, the answers of the exercise could be typeset immediately or later in the document.” A search on CTAN brings up a link to a 36-page instruction document. This is obviously designed for teachers. It includes ways to keep answers hidden from tests as in a graded or reveal answers as in a self-test.

There are over twenty styles starting with “beamer”. These are related to Latex styles that will build PDF files that are slides and can be used in presentations. The main beamer documentation is 225 pages long. It contains an example, instructions on how to make a first beamer presentation and a lot of details about the many parts of a beamer presentation. A search in CTAN using beamer gives 83 results. Some of those are variations on beamer for different languages or for the requirements for different institutions or base fonts. There is a little style package called datetime which comes with a thirteen-page document. It has quite a number of variations covering languages from Basque to Welsh. Along with the babel package (many languages) datetime allows for localisation of the display of dates and / or times. An important set of packages start with bibtex. Tex / Latex was originally designed by Donald Knuth for use by academics (particularly in mathematics and natural sciences). Bibliographies are very important when the results of research and experimentation are published. Because of its age bibtex and its derivatives do not support Unicode fonts. If your work requires Unicode compatibility then you should use the bibLatex and biber packages.

I included the cooking-units package when I developed the little cookbook example in the last few issues. I did not explain much about it then. It comes with forty-eight pages of documentation. The abstract says “this package enables user to globally format units, to switch between them and change your recipes to a given number of persons.” It supports text in English, French and German and can show amounts in factions if needed. Decimal numbers are automatically rounded to two digits, temperatures (four possible scales) are rounded to whole numbers. Conversions from one unit to another can be done in the recipe using the cooking-units package. For example oven temperatures can be shown as 350°F (175°C). Standard metric units (kg, metre, litre) and Imperial (lb, foot, quart) units of mass and volume are used by default, however new units can be defined. Ingredient amounts can be adjusted when the PDF is compiled using specific instructions explained in the documentation. For example a recipe can be coded for 4 servings but increased to 8 or 10 servings by using an appropriate instruction. That is the end of fun with Latex for this month. We will take a look at some more of the installed packages over the next several issues.

issue201/latex.1707198482.txt.gz · Dernière modification : 2024/02/06 06:48 de d52fr