LaTeX/FAQ

From Wikibooks, open books for an open world
Jump to navigation Jump to search

LaTeX

Getting Started
  1. Introduction
  2. Installation
  3. Installing Extra Packages
  4. Basics
  5. How to get help

Common Elements

  1. Document Structure
  2. Text Formatting
  3. Paragraph Formatting
  4. Colors
  5. Fonts
  6. List Structures
  7. Special Characters
  8. Internationalization
  9. Rotations
  10. Tables
  11. Title creation
  12. Page Layout
  13. Customizing Page Headers and Footers‎
  14. Importing Graphics
  15. Floats, Figures and Captions
  16. Footnotes and Margin Notes
  17. Hyperlinks
  18. Labels and Cross-referencing
  19. Initials

Mechanics

  1. Errors and Warnings
  2. Lengths
  3. Counters
  4. Boxes
  5. Rules and Struts

Technical Text

  1. Mathematics
  2. Advanced Mathematics
  3. Theorems
  4. Chemical Graphics
  5. Algorithms
  6. Source Code Listings
  7. Linguistics

Special Pages

  1. Indexing
  2. Glossary
  3. Bibliography Management
  4. More Bibliographies

Special Documents

  1. Scientific Reports (Bachelor Report, Master Thesis, Dissertation)
  2. Letters
  3. Presentations
  4. Teacher's Corner
  5. Curriculum Vitae
  6. Academic Journals (MLA, APA, etc.)

Creating Graphics

  1. Introducing Procedural Graphics
  2. MetaPost
  3. Picture
  4. PGF/TikZ
  5. PSTricks
  6. Xy-pic
  7. Creating 3D graphics

Programming

  1. Macros
  2. Plain TeX
  3. Creating Packages
  4. Creating Package Documentation
  5. Themes

Miscellaneous

  1. Modular Documents
  2. Collaborative Writing of LaTeX Documents
  3. Export To Other Formats

Help and Recommendations

  1. FAQ
  2. Tips and Tricks

Appendices

  1. Authors
  2. Links
  3. Package Reference
  4. Sample LaTeX documents
  5. Index
  6. Command Glossary

edit this boxedit the TOC

Margins are too wide[edit | edit source]

LaTeX's default margins may seem too large. In most cases, this is a preferred default and improves readability.

If you still disagree, you can easily change them with

\usepackage{geometry}
% or
\usepackage[margin=1.5in]{geometry}

See Page Layout.

Avoid excessive double line breaks in source code[edit | edit source]

Too many paragraphs of one line or two do not look very good.

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 improve the readability of your source code, but this will have an impact on formatting. The solution is simple: put a comment at the very beginning of the blank lines. This will prevent TeX from seeing another line break—all characters up to and including the next line break after a comment are ignored.

Example:

We are in the first paragraph here.
%
We are still in the first paragraph.

This time, this is another paragraph.

Simplified special character input[edit | edit source]

So long as your computing environment supports UTF-8, you can enter special characters directly rather than entering the TeX commands for diacritics and other extended characters. E.g.,

R\'esum\'e can also be written résumé.

This requires that:

  • your text editor supports and is set to save your file in UTF-8;
  • you add the \usepackage[utf8]{inputenc} line in the preamble.

Avoid using latin1. See Special Characters.

Writing the euro symbol directly[edit | edit source]

Add the following lines in your preamble:

\usepackage[utf8]{inputenc}
\usepackage{marvosym}
\DeclareUnicodeCharacter{20AC}{\EUR{}}

LaTeX paragraph headings have title and content on the same line[edit | edit source]

Some people do not like the way \paragraph{...} writes the title on the same line as the content. This is actually fairly common in a lot of documents and not as weird as it may seem at first.

There are ways to get around the default behavior, however; see \paragraph line break for more information.

Fonts are ugly/jagged/bitmaps or PDF search fails or Copy/paste from PDF is messy[edit | edit source]

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[edit | edit source]

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. Even if it looks right the first time, 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 (although when you start a new part or chapter, LaTeX will ordinarily do this for you). When you do manually insert a page break, you should use \clearpage or \cleardoublepage which print currently floating figures before starting a new page.

If you absolutely have to insert line or page breaks manually, you should do it after you are sure you have completed your document otherwise, so that you don't later have to come back and update it.

Always finish commands with {}[edit | edit source]

TeX has an unintuitive rule that if a control sequence (a command) is not followed by a pair of braces (with a parameter in between or not), then the following space character(s) are ignored. LaTeX will not print any space, and the command (say, the TeX or LaTeX logos) are run together with the following word.

To fix this, use a pair of braces after the command, even if there are no parameters. Example:

\LaTeX is great. % BAD !
\LaTeX{} is great. % GOOD !

(Technical 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 by using the xspace package.

  • If there is no brace and a space following the command, an extra space will be appended.
  • If there are braces, no extra space will be printed.

Example:

\usepackage{xspace}
\let\latexold\LaTeX
\renewcommand{\LaTeX}{\textrm{\latexold}\xspace}
...
\LaTeX is followed by a space.
\LaTeX{} is followed by a space.
\LaTeX{}is not followed by a space.

Avoid bold and underline[edit | edit source]

Typographically speaking, it is usually poor practice to use bold or underline formats in the middle of a paragraph. This has become a common habit for users of traditional word processors because these two functions are very easily accessible (along with italics).

However, bold and underline tend to overweight the text and distract the reader. When you start reading a paragraph with a bold word in the middle, you often read the emphasized part first, thus spoiling the content and breaking the order of the ideas. Italics are less obvious and do not have more weight than normal characters, so they are usually a better choice for emphasizing small amounts of text.

The original and more appropriate use of bold and underline is for special parts, such as headers, the index, glossaries, and so on. (Actually, underlining is rarely used in professional environments.)

LaTeX has a macro \emph{...} for emphasizing text using italics. It should be preferred to \textit{...} because \emph{...} will correctly print emphasized text inside other italic text in the regular font.

The proper way to use figures[edit | edit source]

Users used to WYSIWYG document processors like Microsoft Word or LibreOffice often 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 in a word processor, placing the picture right at the spot where it was placed in the source.

Figures are a type of float, which is a virtual object that LaTeX can put in places other than the exact location it was created, which helps to prevent cluttering your text with pictures and tables.

See Importing Graphics and Floats, Figures and Captions for more details.

Text stops justifying[edit | edit source]

Most likely you have used \raggedleft, \raggedright or \centering at some point and forgotten to switch it off. These commands 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 for more information.

Rules of punctuation and spacing[edit | edit source]

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 for each language. In English there is no space before a punctuation mark and one space after it.

There are a lot of rules, but you can have a quick look at Wikipedia.

Compilation fails after a Babel language change[edit | edit source]

This is a limitation of Babel. Delete the .aux file (or clean the project), then try compiling again.

Learning LaTeX quickly or correctly[edit | edit source]

Nowadays it is very common to “learn” on the web by using a search engine and copying and pasting things here and there. As with every programming language, this is generally a poor method which will lead to lack of control, unexpected results, and a lot of frustration. Really learning LaTeX is not that difficult and does not take 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 in this book, is rarely as accurate as the official documentation. Inaccurate information might result in causing mistakes without you understanding why.

The time you spend learning is worth it, and it quickly makes up for the time you would lose if you don't learn things properly and end up stuck all the time.

Non-breaking spaces[edit | edit source]

This useful feature is unknown to most 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.

For example, in French typography, you 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 punctuation marks. In the above example, only the non-breaking space for the euro symbol must remain.

Smart mathematics[edit | edit source]

All virtual objects designated by letters, variables or others should use a dedicated formatting. For math and a lot of other fields, the LaTeX math formatting is perfect. For instance, if you want 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.)

Use vector graphics rather than raster images[edit | edit source]

Raster (bitmap) graphics scale poorly and often create jagged or low-quality results which clash with the document quality, particularly when printed.

Using vector (line-oriented) graphics instead, either through LaTeX's native diagramming tools or by exporting vector formats from your drawing or diagramming tools, will produce much higher quality results. When possible, you should prefer PDF, EPS, or SVG graphics over PNG or JPG.

Stretching tables[edit | edit source]

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 easier than you think[edit | edit source]

Even though the Tables chapter is quite long, it is worth reading. In the end, you only need to know a few things about the environment of your choice.

Some LaTeX editors feature table assistants. Also, many spreadsheet applications have a LaTeX export feature (or plugin). Again, see Tables for more details.

Relieving cumbersome code (lists and long command names)[edit | edit source]

LaTeX is sometimes cumbersome to write, especially if you are not using an adequate editor. See Editors for some interesting choices.

You can define aliases to shorten some commands:

\usepackage{xspace}
\newcommand{\tss}[1]{\textsuperscript{#1}}
\newcommand{\tbs}[1]{\textbackslash\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}
% ...

\begin{easylist}
& Item 1
& Item 2
&& Subitem 1
&&& Subsubitem 1
& Item 3
&& Subitem 1
\end{easylist}

Reducing the size of your LaTeX installation[edit | edit source]

The Installation article explains in detail how to manually install a fully functional TeX environment, including LaTeX and other features, in under 100 MB.


Previous: Export To Other Formats Index Next: Tips and Tricks