Ceci est une ancienne révision du document !
We finished with the cookbook last issue and I said we would explore some of the pre-installed packages in this issue and several more issues in the future. With over two thousand to explore, we could be busy for a long time. I could put the list of installed packages into several columns over a few pages and submit that as my article. However I suspect the editor would not be pleased with me if I did that.
One of my interests is typesetting, particularly font use and page design. I start my exploration of the installed packages with some font packages. There are twenty-two packages that contain the word “font” and which name a particular font, a set of definitions for character shapes which can be used to make words in most cases. There are a few fonts which are sets of icons and other shapes. I am lazy and did not review the complete list of packages looking for font names I recognize. I can tell you there are over one hundred pages of fonts in volume 2 (pages 11 – 126) of The Latex Companion (Mittelbach and Fischer, ISBN 978-0-201-36300-5).
These pages contain discussion of the features of almost two hundred different fonts which work in Latex. With only two exceptions (Cambria and Lucida), all of these fonts are free. If you use Windows or MS Office products, you already have a license to use Cambria. I realize many will be offended that I mention Microsoft in FCM. However many of you have devices using different operating systems, and remember Latex / Tex is operating system agnostic. So Cambria is probably already installed on your “other” computer. Lucida is available to purchase from TUG.org (tug.org/store/lucida). Individual licenses are US$110 if you are a TUG member, and US$190 if you are a non-member. If you think this is expensive, check the prices of licensed fonts from commercial font foundries.
Fonts can be used in two ways. The entire document can be formatted using a particular font or font family. That is what I did with the cookbook: \usepackage{notosans}. Or, set a document font and use one or more other fonts as required, something like putting a circle of red paint on a yellow background. There is an example in figure 1. Shown above are the Latex instructions for that example.
I used Noto as the default because it is installed on my machine. However, it is not one of the fonts installed by default. So this code will not work on your machine unless you install Noto. If you remove or comment out the instruction \usepackage{noto}, then the second paragraph will be displayed in the default font which was developed by Donald Knuth and called Computer Modern.
If you are not interested in fonts, you have probably had enough discussion about font packages!
Next, we will look at page layout, in particular what are the defaults built into Latex and how to alter those values using the geometry package. Quoting from the documentation file for the geometry package:
Paper width and height are determined in the first line of every TEX document. The documentclass instruction dictates paper size and also sets printing as one-sided or two-sided. As with many Latex instructions, there are defaults. Documentclass has five document types: article, book, report, slides, letter. Base font size options are 10pt, 11pt and 12pt. Paper sizes can be letterpaper, legal paper, executive paper, A4, A5 and B5. By default, paper is printed in portrait format but can be landscape. There is a draft printing option. Printing on one side of the paper is the default except for book class which is two-sided. Articles, books and reports can be two columns if desired. There are some other options, and some packages can be loaded which will give other choices (for example the memoir document class). All of these choices can be set as options in documentclass. Each choice automatically determines many of the other dimensions of the page.
An easy example is paper size. It determines the text area in the document which automatically sets the margin sizes. (It might be more accurate to say the paper size sets the margin sizes which then dictate the text height and width.) As noted above, if the document is a book, it will automatically be published two-sided, which means the margin names become inside and outside. Normally, inside margins are wider than outside margins to allow for the space required when the book is bound. The geometry package allows the writer to customize the page layout, to override the defaults, to suit their particular requirements.
In the example copied from the geometry package documentation, there is the instruction usepackage[margin=1.5in]{geometry}. No matter what class of document is being written, this instruction makes all margins the same size. The previous instruction \usepackage[text={7in,10in},centering]{geometry}, makes the text area to be 7 inches wide and 10 inches high. In addition, the text area will be centred on the page. This instruction forces Latex to calculate the appropriate margins for whatever page size is being used. These settings will cause problems for A5 and B5 paper sizes since these sizes of paper are too small for a 7 inch x 10 inch text area.
The geometry package has a number of complex options. The Latex Companion book (Mittelbach and Fischer, 2023, ISBN 978-0-13-465894-0) discusses them in some detail in five pages, and there are references to the package on several other pages. I am not going to copy the information from the book, I suggest you take a look for yourself or at least download and review the documentation for the geometry package found at ctan.org. As a starting point here is the example from p. 377 of the book (shown top right).
Notice the parameters are defined before the package name is specified. Notice the parameters are shown as key=value pairs (except for landscape). Notice the top margin, the left margin and the margin ratio are specified but not the right margin or the bottom margin, neither has the size of the text area. The sizes not specified are calculated by the package from the information given by the paper size and these three parameters. The package will check to make sure what is entered meets certain criteria. If not, then the user is warned and at least one of the selected criteria will be ignored. For example the package will not allow the left and right margins to overlap.
The paper parameter accepts a0 paper to a6 paper, b0 paper to b6 paper, c0 paper to c6 paper, plus b0j to b6j for Japanese users, and letterpaper, legal paper and executive paper for those users not using ISO standard paper sizes. Paper sizes can be indicated without the key name, for example just a4 paper instead of papersize=a4paper. Custom paper sizes can be entered using the keys paperwidth and paperheight. Paper can be two-side, as well as landscape or portrait. If a portion of the paper will be consumed during binding, a value for binding offset can be added. This will be added to any inner margin. Type can be displayed as two-column, and the space between columns set using columnsep.
The area on the page that will contain the text can be specified by setting the “outside” sizes (margins, header, footer, etc), or by setting the ”inside” size with textwidth and textheight, and the geometry package will do its best to calculate the other values. If you specify both margins and text body sizes, and they overlap, geometry assumes the margins are correct and reduces the text body size.
You probably noticed the key “margin ratio”. This is the ratio of left:right and top:bottom margins. In the case of the sample, the left margin is set to 52pt so the right margin is twice that or 104pt (1,4 inches or 37mm). Since the top margin is set to 62pt, the bottom margin is 132pt or 46mm. In some limited ways, it is possible to reset page geometry part way through a document. This is done with the newgeometry command. This command issues a clearpage command, which finishes the current page and starts a new page. The new page initially has all its key=value pairs set to the defaults except for keys in the preamble specifying the physical paper. To return to the original settings, use the command restoregeometry, which also closes the current page and starts a new page with the settings from the preamble. If a document has several layouts, it is possible to save each variant with a name using the savegeometry{name} command after the newgeometry command. Then use the load geometry{name} to use the saved layout.
By default, it is not possible to insert a landscape page into a Latex document when the preamble says portrait. The “problem” of inserting a landscape page into a portrait document is solved with the lscape package. This situation often occurs when inserting spreadsheet information (i.e. large tables in Latex). Lscape issues the clearpage command when invoked so that the landscape section starts on a new page no matter how much text is on the previous portrait page. Of course, when the landscape content is finished, it issues another clearpage command when returned to portrait mode.
I hope this article helps move you further along in your knowledge of Latex. I have included two graphics with this article to show you names of the key/value pairs used in the geometry package.
More fun with Latex next issue.