Outils pour utilisateurs

Outils du site


issue181:latex

Ceci est une ancienne révision du document !


Erik covered a lot of ground quickly in the previous nine articles about Latex. By the way the “X” in TeX is pronounced in the same way as the German or Scottish “ch” – very similar to the English “k”. It is quite different from the “x” in Texas. So Latex sounds like “latek”, and does not rhyme with the synthetic fabric Spandex.

To start my part in this series, I am going to step back a bit from typing code and define some basic Latex terms. If you have ever typed HTML code (not just used some software to generate HTML code), you should notice some similarities between HTML and Latex. Latex pre-dates HTML by more than ten years, perhaps Berners-Lee was familiar with Latex when he designed HTML.

Environment: There can be many working environments in a Latex document. Any time you use \begin{something} you are working in an environment. Environments are like container elements in HTML. There must always be a matching \end{…} for every \begin{…}. One advantage of using an IDE like TeXstudio is it completes or closes the environment for you so you do not get a compiling error.

Erik has already introduced you to these environments: document, figure, table, tabular, abstract, equation. Environments can be called within each other. For example, you can put a figure environment, inside a tabular environment, inside a table environment. Environments have to be closed in the reverse order they are opened. Using this example, figure was opened last, and so it must be closed first, then tabular is closed, then table is closed – like this (top right).

As you know, if you have followed this series, every Latex project has to start with the document environment. All other environments are used with the document environment.

Unlike word processors, Latex forces a document to have one consistent structure or style or “look”. People use Latex because of this built-in consistency. Two documents with identical preambles will have exactly the same look. That has enormous benefits for organizations. If you are writing a note to your favourite aunt, this consistency probably does not matter. If your writing represents your employer, it is (or should be) very important to your employer that your documents look the same as the documents produced by your colleagues.

This consistency also means that, if you change the preamble, then the look of your document changes. If you write an article for Journal A, you will use Journal A’s Latex style. If Journal A decides not to publish your article, you can change the preamble to match Journal B’s Latex style and submit it to Journal B without making any other changes in your document. Doing the same thing in a word processor is almost always much more work.

In Part 7, FCM#174, Erik already showed a C.V. style from latextemplates.com. We will do some more work with styles later in this series. This time, I am going to introduce two other environments, the ones used for lists. In word processors (and in web pages), you may have built two types of lists: numbered lists and bulleted lists.

In Latex numbered lists are built in the “enumerate” environment. The code looks like this:

\begin{enumerate} which must be closed with \end{enumerate}

To get a numbered list, each item starts with the command \item. It does what you would expect: starts an item in the list. Items are enumerated by numbers by default. If you wish to use numbering other than standard Arabic numerals, then insert \usepackage{enumerate} in the preamble of your document, the block between documentclass[]{} and begin{document}. Then you can use a variety of “numbers” for the items in the list: for example lower and Upper case Roman numerals, or lower and Upper case letters. You can also add parentheses, or periods, or text, [Example i]. The modification to the numbering scheme is placed between square brackets after \begin{enumerate}[…]

The environment for the other type of list is “itemize”. It is used for what are normally called “bulleted lists”. It also uses the command \item for each item in the list. \item can have the type of bullet in square brackets if the writer wishes to use something other than the default bullet which is a small black circle. For example to have a dash in front of each item use \item[-] (shown second down on the right, and in the image bottom right)

Remember the % sign starts a comment which is visible in the Latex code but not in the final PDF.

As in word processors and HTML, Latex lists can be nested. If you do nest two or more lists, remember the rule: nested environments must be closed in the reverse order they are opened. Environments are opened from the outside to the inside, they must be closed from the inside to the outside.

Bulleted lists and numbered lists can be nested in each other. If you add \usepackage{enumerate} to the preamble of your documents (the block between documentclass{…} and begin{document}), you can vary the numbering used in lists (see code next page top left, and image bottom left).

issue181/latex.1653673472.txt.gz · Dernière modification : 2022/05/27 19:44 de d52fr