LaTeX/FAQ
| Getting Started
Common Elements
Mechanics Technical Texts
Special Pages Special Documents Creating Graphics Programming Miscellaneous Help and Recommendations
Appendices |
Margins are not necessarily so wide
LaTeX default margins may seem too large; actually this is a well thought out matter for more convenient reading.
Anyway you can easily change them with
|
\usepackage{geometry} |
See Page Layout.
Avoid too much double line breaks in source code
Too many paragraphs of one line or two do not really look great.
Remember the TeX rule.
- If two or more consecutive line breaks are found, TeX starts a new paragraph.
- If only one linebreak is found, TeX inserts a space if there is no space directly before or after it.
You might be tempted to put blank lines all the time to have a clear source code. This will have an impact on formatting.
The trade-off is simple: put a comment at the very beginning of the blank lines. This will prevent TeX from seeing another line break, all characters after a comment are ignored up to the line break included.
Example:
|
We are in the first paragraph here. |
Using special characters is simple
You do not have to use the TeX commands for diacritics (e.g. accents).
|
R\'esum\'e can also be written résumé. |
Simply use UTF-8 for that. There two things to do:
- make sure your text editor is set to save your file in UTF-8;
- add the \usepackage[utf8]{inputenc} line in the preamble.
Avoid using latin1. See Special Characters.
Writing the euro symbol directly
Yes this is possible. Add to following lines in your preamble.
|
\usepackage[utf8]{inputenc} |
LaTeX paragraphs title and content on the same line
Most new users do not like that \paragraph{...} writes the title on the same line as the content. This is not weird at all, it is very common in a lot of documents.
The solution is not to hack LaTeX, but to get used to it instead. Remember, LaTeX does the formatting with a high respect to typography, and typography is not simple. So when LaTeX and the user disagree, LaTeX is mostly right.
Still, there is a solution for the obstinate user. See Paragraphs line break.
Fonts are ugly/jagged/bitmaps or PDF search fails or Copy/paste from PDF is messy
You must be using diacritics (e.g. accents) with OT1 encoding (the default). Switch to T1 encoding:
|
\usepackage[T1]{fontenc} |
If you have ugly jagged fonts after the font encoding change, then you have no Type1 compatible fonts available. Install Computer Modern Super or Latin Modern (package name may be lm). To use Latin Modern you need to include the package:
|
\usepackage{lmodern} |
See Fonts for an explanation.
Manual formatting: use of line breaks and page breaks
You should really avoid breaking lines and pages manually. The TeX engine is in charge of that. The big problem with manual formatting is that it is not dynamic. If it looks right on the first place, the content is likely to render really badly if you change anything before the point you manually formatted.
The only place where page breaks are recommended is at the upper level of sectioning in your documents, e.g. parts or chapters.
Besides you should use \clearpage or \cleardoublepage which print currently floating figures before starting a new page.
Always finish commands with {}
TeX has a quite unexpected rule: if a control sequence (a command) is not followed by a pair of braces (with a parameter in between or not), then all the following spaces do not print any space.
Solution: always use braces, even without parameters. Example:
|
\LaTeX is great. % BAD ! |
Explanation: a control sequence name can only be composed of characters with catcode 11, that is A-Z and a-z by default. TeX knows where the control sequence name start thanks to the backslash, and it knows where it ends when it encounters the first token which is not of catcode 11. This character is then skipped. Since consecutive spaces have been concatenated into one single space, no space is taken into account.
It is possible to define macros that will insert a space dynamically thanks to the xspace package.
- If there is no brace and a space following the command, an extra space will be appended.
- If there is braces, no extra space will be printed.
Example:
|
\usepackage{xspace} |
Forget about bold and underline
It is very bad pratice to use bold or underline in the middle of a paragraph, typographically speaking. Yes, it is very common for traditionnal document processors because these two functions are actually the most accessible ones along italic shape.
The fact is, bold and underline tend to overweight the text, and distract the reader. When you start reading a paragraph having a bold word in the middle, you usually read it first, thus spoiling the content and breaking the order of the ideas.
The point is to emphasize a word or a part of a sentence. Use italic for that. It does not overweight the text nor distract the reader.
The original use of bold and underline is for special parts, such as sectioning, index, glossaries, and so on. Actually underlining is rarely used in prefessional environment.
LaTeX has a macro \emph{...} for emphasizing text. It should be preferred to \textit{...} because it is dynamic. An emphasized text inside another emphasized text will print it in the regular font. You cannot do that with \textit{...}.
Final word: with LaTeX only use \emph{...} for common text.
The proper way to use figures
Users used to WYSIWYG document processors like Word or LibreOffice usually get frustrated with figures. The answer is simple: a figure is not a picture!
If you use \includegraphics without enclosing it in a figure environment, it will behave just as what you were used to, it will place the picture in the source order.
Figures are a kind of floats, which are virtual objects that follow specific rules to be printed in a professional style in the document. This is a convenient way to prevent cluttering your text with pictures and tables.
See Importing Graphics and Floats, Figures and Captions for more details.
Text stops justifying
You used \raggedleft, \raggedright or \centering at some point. These command are switches, they remain active until the end of the scope, or until the end of the document if there is no scope. See Paragraph Alignment.
Rules of punctuation
LaTeX does some work for you, but not everything. Especially regarding punctuation, you are pretty free to do what you want. Punctuation rules are different following the language. In English, there is no space before a punctuation mark, and one space after it.
There is a lot of rules, but you can have a quick look at Wikipedia.
Compilation fails after a Babel language change
This is a limitation of Babel. Delete the .aux file (or clean the project).
Learning LaTeX quickly or correctly
Nowadays it is very common to learn on the web, using a search engine and picking stuff here and there. As with every programming language, we really oppose this method, which will only lead to lack of control, unexpected results and a lot of frustration. Learning LaTeX is not hard at all, and it is not that long. Most chapters in this book are dedicated to a specific usage, so the basics are actually covered very quickly.
If you are getting frustrated with a specific package, make sure you read its official documentation, which is usually the best source of information. Content found on the web, even on this book, is (almost) never as accurate as the official documentation. Inaccurate help might just result in the opposite effect: letting you make mistakes without understanding why.
The time you spend learning is worth it, and quickly makes up for the time you would have lost if you hadn't learned things properly, being stuck all the time.
Non-breaking spaces
This essential feature is a bit unknown to newcomers, although it is available on most WYSIWYG document processors. A non-breaking space between two tokens (e.g. words, punctuation marks) prevents processors from inserting a line break between them. It is very important for consistent reading.
LaTeX uses the '~' symbol as a non-breaking space.
You usually use non-breaking spaces for punctuation marks in some languages, for units and currencies, for initials, etc.
In French typography, you would put a non-breaking space before all two-parts punctuation marks. Example:
|
Il répondit~: «~Ce pain coûte-t-il 2~€~?~» |
Note that writing French like this might get really painful. Thankfully, Babel with the frenchb option will take care of the non-breaking spaces for all puncation marks. In the above example, only the non-breaking space for the euro symbol must remain.
Smart mathematics
All virtual objects designed by letters, variables or others should use a dedicated formatting. For math and a lot of other fields, the LaTeX math formatting is perfect. So to refer to an object A, write
|
Speaking of $A$, let's say... |
If you want to refer to several objects in a sentence, it is the same.
|
Speaking of $A$, $B$ and $C$... |
If you refer to a set of objects, you can still use the math notation.
|
The family $(A, B, C)$ is... |
Note that this is different from usual text parentheses.
|
A sentence. ($A$, $B$, and $C$ are not concerned, but we do not mean the $(A, B, C)$ family.) |
Avoid raster graphics, prefer vector graphics
Raster graphics will highly contrast with the quality of the document if they are in a low resolution. Actually, most graphics are not at a high resolution. The result may be even worse once printed.
Most drawing tools (e.g. for diagrams) can export in vector format. So you should always prefer PDF or EPS to PNG or JPG.
Stretching tables
Trying to stretch tables with the default tabular environment will often lead to unexpected results. The nice tabu package will do what you want and even much more. Alternatively if you cannot use the tabu package you may try tabularx or tabulary packages See Tables.
Tables are really not that hard
Even though the Tables chapter is quite long, it might be worth reading. In the end, you only need to know a few things about the environment of your choice.
Besides, some LaTeX editors feature table assistants. Finally, many spreadsheet applications have a LaTeX export feature (or plugin). Again, see Tables for more details.
Relieving cumbersome code (lists and long command names)
LaTeX is sometimes cumbersome to write, especially if you are not using an adequate editor. See Editors for some interesting choices.
You may define aliases to shorten some commands:
|
\usepackage{xspace} |
Here the xspace package comes in handy to avoid swallowed spaces.
For lists you may want to try the easylist package. Now writing a list is as simple as
|
\usepackage[ampersand]{easylist} |
LaTeX installation is not too big
Refer to Installation, it is exlained in details how to install manually and to have a fully functional TeX distribution (with LaTeX and other features) under 100 MB.