# LaTeX/Print version

Permission is granted to copy, distribute, and/or modify this document under the terms of the Creative Commons Attribution-ShareAlike 3.0 Unported License.

# Contents

If you have saved this file to your computer, click on a link in the contents to go to that section.

Getting Started
Common Elements
Mechanics
Technical Texts
Special Pages
Special Documents
Creating Graphics
Programming
Miscellaneous
Help and Recommendations
Appendices

# Introduction

## What is TeX?

TeX is a low-level markup and programming language created by Donald Knuth to typeset documents attractively and consistently. Knuth started writing the TeX typesetting engine in 1977 to explore the potential of the digital printing equipment that was beginning to infiltrate the publishing industry at that time, especially in the hope that he could reverse the trend of deteriorating typographical quality that he saw affecting his own books and articles. With the release of 8-bit character support in 1989, TeX development has been essentially frozen with only bug fixes released periodically. TeX is a programming language in the sense that it supports the if-else construct: you can make calculations with it (that are performed while compiling the document), etc., but you would find it very hard to do anything else but typesetting with it. The fine control TeX offers over document structure and formatting makes it a powerful—and formidable—tool. TeX is renowned for being extremely stable, for running on many different kinds of computers, and for being virtually bug free. The version numbers of TeX are converging toward $\pi$, with a current version number of 3.1415926.

The name TeX is intended by its developer to be /'tɛx/, with the final consonant of loch or Bach. (Donald E. Knuth, The TeXbook) The letters of the name are meant to represent the capital Greek letters tau, epsilon, and chi, as TeX is an abbreviation of τέχνη (ΤΕΧΝΗ – technē), Greek for both "art" and "craft", which is also the root word of technical. English speakers often pronounce it /'tɛk/, like the first syllable of technical.

Programming in TeX generally progresses along a very gradual learning curve, requiring a significant investment of time to build custom macros for text formatting. Fortunately, document preparation systems based on TeX, consisting of collections of pre-built macros, do exist. These pre-built macros are time saving, and automate certain repetitive tasks and help reduce user introduced errors; however, this convenience comes at the cost of complete design flexibility. One of the most popular macro packages is called LaTeX.

## What is LaTeX?

LaTeX (pronounced either "Lah-tech" or "Lay-tech") is a macro package based on TeX created by Leslie Lamport. Its purpose is to simplify TeX typesetting, especially for documents containing mathematical formulae. Within the typesetting system, its name is formatted as LaTeX.

Many later authors have contributed extensions, called packages or styles, to LaTeX. Some of these are bundled with most TeX/LaTeX software distributions; more can be found in the Comprehensive TeX Archive Network (CTAN).

Since LaTeX comprises a group of TeX commands, LaTeX document processing is essentially programming. You create a text file in LaTeX markup, which LaTeX reads to produce the final document.

This approach has some disadvantages in comparison with a WYSIWYG (What You See Is What You Get) program such as Openoffice.org Writer or Microsoft Word.

In LaTeX:

• You don't (usually) see the final version of the document when editing it.
• You generally need to know the necessary commands for LaTeX markup.
• It can sometimes be difficult to obtain a certain look for the document.

On the other hand, there are certain advantages to the LaTeX approach:

• Document sources can be read with any text editor and understood, unlike the complex binary and XML formats used with WYSIWYG programs.
• You can concentrate purely on the structure and contents of the document, not get caught up with superficial layout issues.
• You don't need to manually adjust fonts, text sizes, line heights, or text flow for readability, as LaTeX takes care of them automatically.
• In LaTeX the document structure is visible to the user, and can be easily copied to another document. In WYSIWYG applications it is often not obvious how a certain formatting was produced, and it might be impossible to copy it directly for use in another document.
• The layout, fonts, tables and so on are consistent throughout the document.
• Mathematical formulae can be easily typeset.
• Indexes, footnotes, citations and references are generated easily.
• Since the document source is plain text, tables, figures, equations, etc. can be generated programmatically with any language.
• You are forced to structure your documents correctly.

The LaTeX-like approach can be called WYSIWYM, i.e. What You See Is What You Mean: you can't see what the final version will look like while typing. Instead you see the logical structure of the document. LaTeX takes care of the formatting for you.

The LaTeX document is a plain text file containing the content of the document, with additional markup. When the source file is processed by the macro package, it can produce documents in several formats. LaTeX natively supports DVI and PDF, but by using other software you can easily create PostScript, PNG, JPEG, etc.

## Philosophy of use

### Flexibility and modularity

One of the most frustrating things beginners and even advanced users might encounter using LaTeX is the lack of flexibility regarding the document design and layout. If you want to design your document in a very specific way, you may have trouble accomplishing this. Keep in mind that LaTeX does the formatting for you, and mostly the right way. If it is not exactly what you desired, then the LaTeX way is at least not worse, if not better. One way to look at it is that LaTeX is a bundle of macros for TeX that aims to carry out everything regarding document formatting, so that the writer only needs to care about content. If you really want flexibility, use plain TeX instead.

One solution to this dilemma is to make use of the modular possibilities of LaTeX. You can build your own macros, or use macros developed by others. You are likely not the first person to face some particular formatting problem, and someone who encountered a similar problem before may have published their solution as a package.

CTAN is a good place to find many resources regarding TeX and derivative packages. It is the first place where you should begin searching.

### Questions and documentation

Besides internet resources being plentiful, the best documentation source remains the official manual for every specific package, and the reference documentation, i.e., the TeXbook by D. Knuth and LaTeX: A document preparation system by L. Lamport.

Therefore before rushing on your favorite web search engine, we really urge you to have a look at the package documentation that causes troubles. This official documentation is most commonly installed along your TeX distribution, or may be found on CTAN.

## Terms regarding TeX

Document preparation systems

LaTeX is a document preparation system based on TeX. So the system is the combination of the language and the macros.

Distributions

TeX distributions are collections of packages and programs (compilers, fonts, and macro packages) that enable you to typeset without having to manually fetch files and configure things.

Engines

An engine is an executable that can turn your source code into a printable output format. The engine by itself only handles the syntax, it also needs to load fonts and macros to fully understand the source code and generate output properly. The engine will determine what kind of source code it can read, and what format it can output (usually DVI or PDF).

All in all, distributions are an easy way to install what you need to use the engines and the systems you want. Distributions usually target specific operating systems. You can use different systems on different engines, but sometimes there are restrictions. Code written for TeX, LaTeX or ConTeXt are (mostly) not compatible. Additionally, engine-specific code (like font for XeTeX) may not be compiled by every engine.

When searching for information on LaTeX, you might also stumble upon XeTeX, ConTeXt, LuaTeX or other names with a -TeX suffix. Let's recap most of the terms in this table.

Systems Descriptions
ConTeXt A TeX-based document preparation system (as LaTeX is) with a very consistent and easy syntax and support for pdfTeX, XeTeX and LuaTeX engines.

It does not have the same objective as LaTeX however.

LaTeX A TeX-based document preparation system designed by Leslie Lamport. It is actually a set of macros for TeX. It aims at taking care of the formatting process.
MetaFont A high-quality font system designed by Donald Knuth along TeX.
MetaPost A descriptive vector graphics language based on MetaFont.
TeX The original language designed by Donald Knuth.
Engines Descriptions
luatex, lualatex A TeX engine with Lua scripting engine embedded aiming at making TeX internals more flexible.
pdftex, pdflatex The engines (PDF compilers).
tex, latex The engines (DVI compilers).
xetex, xelatex a TeX engine which uses Unicode and supports widely popular .ttf and .otf fonts. See Fonts.
TeX Distributions Descriptions
MacTeX A TeX Live based distribution targetting Mac OS X.
MiKTeX A TeX distribution for Windows.
TeX Live A cross-platform TeX distribution.

## What next?

In the next chapter we will proceed to the installation. Then we will compile our first LaTeX file.

Throughout this book you should also utilise other means for learning about LaTeX. Good sources are:

# Installation

If this is the first time you are trying out LaTeX, you don't even need to install anything. For quick testing purpose you may just create a user account with an online LaTeX editor and continue this tutorial in the next chapter. These websites offer collaboration capabilities while allowing you to experiment with LaTeX syntax without having to bother with installing and configuring a distribution and an editor. When you later feel that you would benefit from having a standalone LaTeX installation, you can return to this chapter and follow the instructions below.

LaTeX is not a program by itself; it is a language. Using LaTeX requires a bunch of tools. Acquiring them manually would result in downloading and installing multiple programs in order to have a suitable computer system that can be used to create LaTeX output, such as PDFs. TeX Distributions help the user in this way, in that it is a single step installation process that provides (almost) everything.

At a minimum, you'll need a TeX distribution, a good text editor and a DVI or PDF viewer. More specifically, the basic requirement is to have a TeX compiler (which is used to generate output files from source), fonts, and the LaTeX macro set. Optional, and recommended installations include an attractive editor to write LaTeX source documents (this is probably where you will spend most of your time), and a bibliographic management program to manage references if you use them a lot.

## Distributions

TeX and LaTeX are available for most computer platforms, since they were programmed to be very portable. They are most commonly installed using a distribution, such as teTeX, MiKTeX, or MacTeX. TeX distributions are collections of packages and programs (compilers, fonts, and macro packages) that enable you to typeset without having to manually fetch files and configure things. LaTeX is just a set of macro packages built for TeX.

The recommended distributions for each of the major operating systems are:

• TeX Live is a major TeX distribution for *BSD, GNU/Linux, Mac OS X and Windows.
• MiKTeX is a Windows-specific distribution.
• MacTeX is a Mac OS-specific distribution based on TeX Live.

These, however, do not necessarily include an editor. You might be interested in other programs that are not part of the distribution, which will help you in writing and preparing TeX and LaTeX files.

### *BSD and GNU/Linux

In the past, the most common distribution used to be teTeX. As of May 2006 teTeX is no longer actively maintained and its former maintainer Thomas Esser recommended TeX Live as the replacement.[1]

The easy way to get TeX Live is to use the package manager or portage tree coming with your operating system. Usually it comes as several packages, with some of them being essential, other optional. The core TeX Live packages should be around 200-300 MB.

If your *BSD or GNU/Linux distribution does not have the TeX Live packages, you should report a wish to the bug tracking system. In that case you will need to download TeX Live yourself and run the installer by hand.

You may wish to install the content of TeX Live more selectively. See below.

### Mac OS X

Mac OS X users may use MacTeX, a TeX Live-based distribution supporting TeX, LaTeX, AMSTeX, ConTeXt, XeTeX and many other core packages. Download MacTeX.mpkg.zip on the MacTeX page, unzip it and follow the instructions. Further information for Mac OS X users can be found on the TeX on Mac OS X Wiki.

Since Mac OS X is also a Unix-based system, TeX Live is naturally available through MacPorts and Fink. Further information for Mac OS X users can be found on the TeX on Mac OS X Wiki.

### Microsoft Windows

Microsoft Windows users can install MiKTeX onto their computer. It has an easy installer that takes care of setting up the environment and downloading core packages. This distribution has advanced features, such as automatic installation of packages, and simple interfaces to modify settings, such as default paper sizes.

There is also a port of TeX Live available for Windows.

## Custom installation with TeX Live

This section targets users who want fine-grained control over their TeX distribution, like an installation with a minimum of disk space usage. If it is none of your concern, you may want to jump to the next section.

Picky users may wish to have more control over their installation. Common distributions might be tedious for the user caring about disk space. In fact, MikTeX and MacTeX and packaged TeX Live features hundreds of LaTeX packages, most of them which you will never use. Most Unix with a package manager will offer TeX Live as a set of several big packages, and you often have to install 300–400 MB for a functional system.

TeX Live features a manual installation with a lot of possible customizations. You can get the network installer at tug.org. This installer allows you to select precisely the packages you want to install. As a result, you may have everything you need for less than 100 MB. TeX Live is then managed through its own package manager, tlmgr. It will let you configure the distributions, install or remove extra packages and so on.

You will need a Unix-based operating system for the following. Mac OS X, GNU/Linux or *BSD are fine. It may work for Windows but the process must be quite different.

TeX Live groups features and packages into different concepts:

• Collections are groups of packages that can always be installed individually, except for the Essential programs and files collection. You can install collections at any time.
• Installation Schemes group collections and packages. Schemes can only be used at installation time. You can select only one scheme at a time.

### Minimal installation

We will give you general guidelines to install a minimal TeX distribution (i.e., only for plain TeX).

1. Download the installer at http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz and extract it to a temporary folder.
2. Open a terminal in the extracted folder and log in as root.
3. Change the umask to 022 to make sure other users will have read-only access to the installed distribution.
1. Launch install-tl.
2. Select the minimal scheme (plain only).
3. You may want to change the directory options. For example you may want to hide your personal macro folder which is located at TEXMFHOME. It is ~/texmf by default. Replace it by ~/.texmf to hide it.
4. Now the options:
1. use letter size instead of A4 by default: mostly for users from the USA.
2. execution of restricted list of programs: it is recommended to select it for security reasons. Otherwise it allows the TeX engines to call any external program. You may still configure the list afterwards.
3. create format files: targetting a minimal disk space, the best choice depends on whether there is only one user on the system, then deselecting it is better, otherwise select it. From the help menu: "If this option is set, format files are created for system-wide use by the installer. Otherwise they will be created automatically when needed. In the latter case format files are stored in user's directory trees and in some cases have to be re-created when new packages are installed."
4. install font/macro doc tree: useful if you are a developer, but very space consuming. Turn it off if you want to save space.
5. install font/macro source tree: same as above.
6. Symlinks are fine by default, change it if you know what you are doing.
5. Select portable installation if you install the distribution to an optical disc, or any kind of external media. Leave to default for a traditional installation on the system hard drive.

At this point it should display

1 collections out of 85, disk space required: 40 MB

or a similar space usage.

You can now proceed to installation: start installation to hard disk.

Don't forget to add the binaries to your PATH as it's noticed at the end of the installation procedure.

### First test

In a terminal write

$tex '\empty Hello world!\bye'$ pdftex '\empty Hello world!\bye'

You should get a DVI or a PDF file accordingly.

### Configuration

Formerly, TeX distributions used to be configured with the texconfig tool from the teTeX distribution. TeX Live still features this tool, but recommends using its own tool instead: tlmgr. Note that as of January 2013 not all texconfig features are implemented by tlmgr. Only use texconfig when you cannot do what you want with tlmgr.

List current installation options:

tlmgr option

You can change the install options:

tlmgr option src 1
tlmgr option doc 0
tlmgr option paper letter

See the TLMGR(1) man page for more details on its usage. If you did not install the documents as told previously, you can still access the tlmgr man page with

tlmgr help

### Installing LaTeX

Now we have a running plainTeX environment, let's install the base packages for LaTeX.

# tlmgr install latex latex-bin latexconfig latex-fonts

In this case you can omit latexconfig latex-fonts as they are auto-resolved dependencies to LaTeX. Note that tlmgr resolves some dependencies, but not all. It may happen to install dependencies manually. Thankfully this is rarely too cumbersome.

Other interesting packages:

# tlmgr install amsmath babel carlisle ec geometry graphics hyperref lm  marvosym oberdiek parskip pdftex-def url
 amsmath The essentials for math typesetting. babel Internationalization support. carlisle Bundle package required for some babel features. ec Required for T1 encoding. geometry For page layout. graphics The essentials to import graphics. hyperref PDF bookmarks, PDF followable links, link style, TOC links, etc. lm One of the best Computer Modern style font available for several font encodings (such as T1). marvosym Several symbols, such as the official euro. oberdiek Bundle package required for some geometry features. parskip Let you configure paragraph breaks and indents properly. pdftex-def Required for some graphics features. url Required for some hyperref features.

If you installed a package you do not need anymore, use

# tlmgr remove <package>

### Hyphenation

If you are using Babel for non-English documents, you need to install the hyphenation patterns for every language you are going to use. They are all packaged individually. For instance, use

# tlmgr install hyphen-{finnish,sanskrit}

for finnish and sanskrit hyphenation patterns.

Note that if you have been using another TeX distribution beforehand, you may still have hyphenation cache stored in you home folder. You need to remove it so that the new packages are taken into account. The TeX Live cache is usually stored in the ~/.texliveYYYY folder (YYYY stands for the year). You may safely remove this folder as it contains only generated data. TeX compilers will re-generate the cache accordingly on next compilation.

### Uninstallation

By default TeX Live will install in /usr/local/texlive. The distribution is quite proper as it will not write any file outside its folder, except for the cache (like font cache, hyphenation patters, etc.). By default,

• the system cache goes in /var/lib/texmf;
• the user cache goes in ~/.texliveYYYY.

Therefore TeX Live can be installed and uninstalled safely by removing the aforementioned folders.

Still, TeX Live provides a more convenient way to do this:

# tlmgr uninstall

You may still have to wipe out the folders if you put untracked files in them.

## Editors

TeX and LaTeX source documents (as well as related files) are all text files, and can be opened and modified in almost any text editor. You should use a text editor (e.g. Notepad), not a word processor (Word, OpenOffice). Dedicated LaTeX editors are more useful than generic plain text editors, because they usually have autocompletion of commands, spell and error checking and handy macros.

### Cross-platform

#### BaKoMa TeX

BaKoMa TeX is an editor for Windows and Mac OS with WYSIWYG-like features. It takes care of compiling the LaTeX source and updating it constantly to view changes to document almost in real time.

#### Emacs

Emacs is a general purpose, extensible text processing system. Advanced users can program it (in elisp) to make Emacs the best LaTeX environment that will fit theirs needs. In turn beginners may prefer using it in combination with AUCTeX and Reftex (extensions that may be installed into the Emacs program). Depending on your configuration, Emacs can provide a complete LaTeX editing environment with auto-completion, spell-checking, a complete set of keyboard shortcuts, table of contents view, document preview and many other features.

#### gedit-latex-plugin

Gedit with gedit-latex-plugin is also worth trying out for users of GNOME. GEdit is a cross-platform application for Windows, Mac, and Linux

#### Gummi

Screenshot of Gummi.

Gummi is a LaTeX editor for Linux, which compiles the output of pdflatex in realtime and shows it on the right half of the screen[2].

#### LyX

LyX1.6.3

LyX is a popular LaTeX editor for Windows, Linux and Mac OS. It contains formula and table editors and shows visual clues of the final document on the screen enabling users to write LaTeX documents without worrying about the actual syntax[3].

#### TeXmaker

TeXmaker is a cross-platform editor very similar to Kile in features and user interface. In addition it has its own PDF viewer.

#### TeXstudio

TeXstudio is a cross-platform open source LaTeX editor forked from Texmaker.

#### TeXworks

Screenshot of TeXworks on Ubuntu 12.10.

TeXworks is a dedicated TeX editor that is included in MiKTeX and TeX Live. It was developed with the idea that a simple interface is better than a cluttered one, and thus to make it easier for people in their early days with LaTeX to get to what they want to do: write their documents. TeXworks originally came about precisely because a math professor wanted his students to have a better initial experience with LaTeX.

You can install TeXworks with the package manager of your Linux distribution or choose it as an install option in the Windows or Mac installer.

#### Vim

Vim is another general purpose text editor for a wide variety of platforms including UNIX, Mac OS X and Windows. A variety of extensions exist including LaTeX Box and Vim-LaTeX.

### *BSD and GNU/Linux-only

#### Kile

Screenshot of Kile.

Kile is a LaTeX editor for KDE (cross platform), providing a powerful GUI for editing multiple documents and compiling them with many different TeX compilers. Kile is based on Kate editor, has a quick access toolbar for symbols, document structure viewer, a console and customizable build options. Kile can be run in all operating systems that can run KDE.

#### LaTeXila

LaTeXila is another text editor for Linux (Gnome).

### Mac OS X-only

#### TeXShop

TeXShop is a TeXworks-like editor and previewer for Mac OS that is bundled with the MacTeX distribution. It uses multiple windows, one for editing the source, one for the preview, and one as a console for error messages. It offers one-click updating of the preview and allows easy crossfinding between the code and the preview by using CMD-click.

#### TeXnicle

TeXnicle is a free editor for Mac OS that includes the ability to perform live updates. It includes a code library for the swift insertion of code and the ability to execute detailed word counts on documents. It also performs code highlighting and the editing window is customisable, permitting the user to select the font, colour, background colour of the editing environment. It is in active development.

### Windows-only

LEd

#### TeXnicCenter

TeXnicCenter is a popular free and open source LaTeX editor for Windows. It also has a similar user interface to TeXmaker and Kile.

#### WinEdt

WinEdt is a powerful and versatile text editor with strong predisposition towards creation of LaTeX/TeX documents for Windows. It has been designed and configured to integrate with TeX Systems such as MiTeX or TeX Live. Its in-built macro helps in compiling the LaTeX source to the WYSIWYG-like DVI or PDF or PS and also in exporting the document to other mark-up languages as html or XML.

WinShell

### Web-based

#### Authorea

Authorea [3] is not a LaTeX installation per se, but an integrated online framework for the creation of technical documents in collaboration. Authorea's frontend allows you to enter text in LaTeX or Markdown, as well as figures, and equations (in LaTeX or MathML). Authorea renders and compiles everything to the web (HTML5), in addition to PDF (export to numerous journal formats is provided). Authorea's versioning control system is entirely based on Git (every article is a Git repository).

## Bibliography management

Bibliography files (*.bib) are most easily edited and modified using a management system. These graphical user interfaces all feature a database form, where information is entered for each reference item, and the resulting text file can be used directly by BibTeX.

### Cross-platform

Screenshot of JabRef.

### Mac OS X-only

Screenshot of BibDesk
• BibDesk is a bibliography manager based on a BibTeX file. It imports references from the internet and makes it easy to organize references using tags and categories[4].

## Viewers

Finally, you will need a viewer for the files LaTeX outputs. Normally LaTeX saves the final document as a .dvi (Device independent file format), but you will rarely want it to. DVI files do not contain embedded fonts and many document viewers are unable to open them.

Usually you will use a LaTeX compiler like pdflatex to produce a PDF file directly, or a tool like dvi2pdf to convert the DVI file to PDF format. Then you can view the result with any PDF viewer.

Practically all LaTeX distributions have a DVI viewer for viewing the default output of latex, and also tools such as dvi2pdf for converting the result automatically to PDF and PS formats.

Here follows a list of various PDF viewers.

• epdfview
• Evince
• Foxit
• Okular
• Sumatra
• Zathura

## Tables and graphics tools

LaTeX is a document preparation system, it does not aim at being a spreadsheet tool nor a vector graphics tool.

If LaTeX can render beautiful tables in a dynamic and flexible manner, it will not handle the handy features you could get with a spreadsheet like dynamic cells and calculus. Other tools are better at that. The ideal solution is to combine the strength of both tools: build your dynamic table with a spreadsheet, and export it to LaTeX to get a beautiful table seamlessly integrated to your document. See Tables for more details.

The graphics topic is a bit different since it is possible to write procedural graphics from within your LaTeX document. Procedural graphics produce state-of-the-art results that integrates perfectly to LaTeX (e.g. no font change), but have a steep learning curve and require a lot of time to draw.

For easier and quicker drawings, you may want to use a WYSIWYG tool and export the result to a vector format like PDF. The drawback is that it will contrast in style with the rest of your document (font, size, etc.). Some tools have the capability to export to LaTeX, which will partially solve this issue. See Importing Graphics for more details.

## Online solutions

To get started without needing to install anything, you can use a web-hosted service featuring a full TeX distribution and a web LaTeX editor.

• Google Documents or LaTeX Lab allows real-time simultaneous collaborative editing of text files for anyone with a Google account (and its option to make the document available through a URL makes local download and compilation easily scriptable).
• LIMSUP is an online LaTeX editor allowing real time collaboration of LaTeX documents (announcement)
• ScribTeX.com is one of the most mature systems available, with git push and pull access it allows for powerful version control. The new sign ups are now directed to use ShareLatex.com however accounts are still available upon request.
• ShareLaTeX.com is a secure cloud based LaTeX editor offering unlimited free project. Premium accounts are available for extra features such as version control and Dropbox integration.
• SpanDeX is a cloud-based LaTeX collaboration platform designed to make collaborating with LaTeX seamless and to reduce the learning curve to LaTeX. It offers simultaneous real-time editing and collaboration, live document preview, Dropbox integration, and a built-in LaTeX resource system.
• Verbosus is a professional Online LaTeX Editor that supports collaboration with other users and is free to use. Merge conflicts can easily resolved by using a built-in merge tool that uses an implementation of the diff-algorithm to generate information required for a successful merge.
• writeLaTeX.com is a secure, easy to use online LaTeX editor with integrated rapid preview - like EtherPad for LaTeX. Start writing with one click (no signup required) and share the link. It supports real time preview, figures, bibliographies and custom styles.

## References

1. teTeX Home Page (Retrieved January 31, 2007)
2. Gummi
3. LyX
4. BibDesk

# Installing Extra Packages

Add-on features for LaTeX are known as packages. Dozens of these are pre-installed with LaTeX and can be used in your documents immediately. They should all be stored in subdirectories of texmf/tex/latex named after each package. The directory name "texmf" stands for “TEX and METAFONT”. To find out what other packages are available and what they do, you should use the CTAN search page which includes a link to Graham Williams' comprehensive package catalogue.

A package is a file or collection of files containing extra LaTeX commands and programming which add new styling features or modify those already existing. There are two main file types: class files with .cls extension, and style files with .sty extension. There may be ancillary files as well. When you try to typeset a document which requires a package which is not installed on your system, LaTeX will warn you with an error message that it is missing. You can download updates to packages you already have (both the ones that were installed along with your version of LaTeX as well as ones you added). There is no limit to the number of packages you can have installed on your computer (apart from disk space!), but there is a configurable limit to the number that can be used inside any one LaTeX document at the same time, although it depends on how big each package is. In practice there is no problem in having even a couple of dozen packages active.

Most LaTeX installations come with a large set of pre-installed style packages, so you can use the package manager of the TeX distribution or the one on your system to manage them. See the automatic installation. But many more are available on the net. The main place to look for style packages on the Internet is CTAN. Once you have identified a package you need that is not in your distribution, use the indexes on any CTAN server to find the package you need and the directory where it can be downloaded from. See the manual installation.

## Automatic installation

If on an operating system with a package manager or a portage tree, you can often find packages in repositories.

With MikTeX there is a package manager that allows you to pick the package you want individually. As a convenient feature, upon the compilation of a file requiring non-installed packages, MikTeX will automatically prompt to install the missing ones.

With TeX Live, it is common to have the distribution packed into a few big packages. For example, to install something related to internationalization, you might have to install a package like texlive-lang. With TeX Live manually installed, use tlmgr to manage packages individually.

tlmgr install <package1> <package2> ...
tlmgr remove <package1> <package2> ...

The use of tlmgr is covered in the Installation chapter.

If you cannot find the wanted package with any of the previous methods, see the manual installation.

## Manual installation

What you need to look for is usually two files, one ending in .dtx and the other in .ins. The first is a DOCTeX file, which combines the package program and its documentation in a single file. The second is the installation routine (much smaller). You must always download both files. If the two files are not there, it means one of two things:

• Either the package is part of a much larger bundle which you shouldn't normally update unless you change LaTeXversion of LaTeX;
• or it's an older or relatively simple package written by an author who did not use a .dtx file.

Download the package files to a temporary directory. There will often be a readme.txt with a brief description of the package. You should of course read this file first.

### Installing a package

There are five steps to installing a LaTeX package. (These steps can also be used on the pieces of a complicated package you wrote yourself; in this case, skip straight to Step 3.)

1. Extract the files Run LaTeX on the .ins file. That is, open the file in your editor and process it as if it were a LaTeX document (which it is), or if you prefer, type latex followed by the .ins filename in a command window in your temporary directory. This will extract all the files needed from the .dtx file (which is why you must have both of them present in the temporary directory). Note down or print the names of the files created if there are a lot of them (read the log file if you want to see their names again).

2. Create the documentation Run LaTeX on the .dtx file. You might need to run it twice or more, to get the cross-references right (just like any other LaTeX document). This will create a .dvi file of documentation explaining what the package is for and how to use it. If you prefer to create PDF then run pdfLaTeX instead. If you created a .idx as well, it means that the document contains an index, too. If you want the index to be created properly, follow the steps in the indexing section. Sometimes you will see that a .glo (glossary) file has been produced. Run the following command instead:

makeindex -s gglo.ist -o name.gls name.glo

3. Install the files While the documentation is printing, move or copy the package files from your temporary directory to the right place[s] in your TeX local installation directory tree. Packages installed by hand should always be placed in your "local" directory tree, not in the directory tree containing all the pre-installed packages. This is done to a) prevent your new package accidentally overwriting files in the main TeX directories; and b) avoid your newly-installed files being overwritten when you next update your version of TeX.

For a TDS(TeX Directory Structure)-conformant system, your "local installation directory tree" is a folder and its subfolders. The outermost folder should probably be called texmf-local/ or texmf/. Its location depends on your system:

The "right place" sometimes causes confusion, especially if your TeX installation is old or does not conform to the TeX Directory Structure(TDS). For a TDS-conformant system, the "right place" for a LaTeX .sty file is a suitably-named subdirectory of texmf/tex/latex/. "Suitably-named" means sensible and meaningful (and probably short). For a package like paralist, for example, I'd call the directory texmf/tex/latex/paralist.

Often there is just a .sty file to move, but in the case of complex packages there may be more, and they may belong in different locations. For example, new BibTeX packages or font packages will typically have several files to install. This is why it is a good idea to create a sub-directory for the package rather than dump the files into misc along with other unrelated stuff. If there are configuration or other files, read the documentation to find out if there is a special or preferred location to move them to.

Where to put files from packages
Type Directory (under texmf/ or texmf-local/) Description
.afm fonts/afm/foundry/typeface Adobe Font Metrics for Type 1 fonts
.bst bibtex/bst/packagename BibTeX style
.cls tex/latex/base Document class file
.dvi doc package documentation
.enc fonts/enc Font encoding
.fd tex/latex/mfnfss Font Definition files for METAFONT fonts
.fd tex/latex/psnfss Font Definition files for PostScript Type 1 fonts
.map fonts/map/ Font mapping files
.mf fonts/source/public/typeface METAFONT outline
.pdf doc package documentation
.pfb fonts/type1/foundry/typeface PostScript Type 1 outline
.sty tex/latex/packagename Style file: the normal package content
.tex doc TeX source for package documentation
.tex tex/plain/packagename Plain TeX macro files
.tfm fonts/tfm/foundry/typeface TeX Font Metrics for METAFONT and Type 1 fonts
.ttf fonts/truetype/foundry/typeface TrueType font
.vf fonts/vf/foundry/typeface TeX virtual fonts
others tex/latex/packagename other types of file unless instructed otherwise

For most fonts on CTAN, the foundry is public.

4. Update your index Finally, run your TeX indexer program to update the package database. This program comes with every modern version of TeX and has various names depending on the LaTeX distribution you use. (Read the documentation that came with your installation to find out which it is, or consult http://www.tug.org/fonts/fontinstall.html#fndb):

• teTeX, TeX Live, fpTeX: texhash
• web2c: mktexlsr
• MacTeX: MacTeX appears to do this for you.
• MikTeX: initexmf --update-fndb (or use the GUI)
• MiKTeX 2.7 or later versions, installed on Windows XP through Windows 7: Start -> All Programs -> MikTex -> Settings. In Windows 8 use the keyword Settings and choose the option of Settings with the MiKTex logo. In Settings menu choose the first tab and click on Refresh FNDB-button (MikTex will then check the Program Files directory and update the list of File Name DataBase). After that just verify by clicking 'OK'.

5. Update font maps If your package installed any TrueType or Type 1 fonts, you need to update the font mapping files in addition to updating the index. Your package author should have included a .map file for the fonts. The map updating program is usually some variant on updmap, depending on your distribution:

• TeX Live and MacTeX: updmap --enable Map=mapfile.map (if you installed the files in a personal tree) or updmap-sys --enable Map=mapfile.map (if you installed the files in a system directory).
• MikTeX: Run initexmf --edit-config-file updmap, add the line "Map mapfile.map to the file that opens, then run initexmf --mkmaps.

The reason this process has not been automated widely is that there are still thousands of installations which do not conform to the TDS, such as old shared Unix systems and some Microsoft Windows systems, so there is no way for an installation program to guess where to put the files: you have to know this. There are also systems where the owner, user, or installer has chosen not to follow the recommended TDS directory structure, or is unable to do so for political or security reasons (such as a shared system where she cannot write to a protected directory). The reason for having the texmf-local directory (called texmf.local on some systems) is to provide a place for local modifications or personal updates, especially if you are a user on a shared or managed system (Unix, Linux, VMS, Windows NT/2000/XP, etc.) where you may not have write-access to the main TeX installation directory tree. You can also have a personal texmf subdirectory in your own login directory. Your installation must be configured to look in these directories first, however, so that any updates to standard packages will be found there before the superseded copies in the main texmf tree. All modern TeX installations should do this anyway, but if not, you can edit texmf/web2c/texmf.cnf yourself.

## Checking package status

The universal way to check if a file is available to TeX compilers is the command-line tool kpsewhich.

$kpsewhich tikz /usr/local/texlive/2012/texmf-dist/tex/plain/pgf/frontendlayer/tikz.tex kpsewhich will actually search for files only, not for packages. It returns the path to the file. For more details on a specific package use the command-line tool tlmgr (TeX Live only): tlmgr info <package> The tlmgr tool has lot more options. To consult the documentation: tlmgr help ## Package documentation To find out what commands a package provides (and thus how to use it), you need to read the documentation. In the texmf/doc subdirectory of your installation there should be directories full of .dvi files, one for every package installed. This location is distribution-specific, but is typically found in: Distribution Path MiKTeX %MIKTEX_DIR%\doc\latex TeX Live$TEXMFDIST/doc/latex

Generally, most of the packages are in the latex subdirectory, although other packages (such as BibTeX and font packages) are found in other subdirectories in doc. The documentation directories have the same name of the package (e.g. amsmath), which generally have one or more relevant documents in a variety of formats (dvi, txt, pdf, etc.). The documents generally have the same name as the package, but there are exceptions (for example, the documentation for amsmath is found at latex/amsmath/amsdoc.dvi). If your installation procedure has not installed the documentation, the DVI files can all be downloaded from CTAN. Before using a package, you should read the documentation carefully, especially the subsection usually called "User Interface", which describes the commands the package makes available. You cannot just guess and hope it will work: you have to read it and find out.

You can usually automatically open any installed package documentation with the texdoc command:

texdoc <package-name>

## External resources

The best way to look for LaTeX packages is the already mentioned CTAN: Search. Additional resources form The TeX Catalogue Online:

# Basics

This tutorial is aimed at getting familiar with the bare bones of LaTeX.

Before starting, ensure you have LaTeX installed on your computer (see Installation for instructions of what you will need).

• We will first have a look at the LaTeX syntax.
• We will create our first LaTeX document.
• Then we will take you through how to feed this file through the LaTeX system to produce quality output, such as postscript or PDF.
• Finally we will have a look at the file names and types.

## The LaTeX syntax

LaTeX uses a markup language in order to describe document structure and presentation. LaTeX converts your source text, combined with the markup, into a high quality document. For the purpose of analogy, web pages work in a similar way: the HTML is used to describe the document, but it is your browser that presents it in its full glory - with different colours, fonts, sizes, etc.

The input for LaTeX is a plain text file. You can create it with any text editor. It contains the text of the document, as well as the commands that tell LaTeX how to typeset the text.

For the truly impatient, a minimal example looks something like the following (the commands will be explained later):

 \documentclass{article} \begin{document} Hello world! \end{document}

### Spaces

The LaTeX compiler normalises whitespace so that whitespace characters, such as [space] or [tab], are treated uniformly as "space": several consecutive "spaces" are treated as one, "space" opening a line is generally ignored, and a single line break also yields “space”. A double line break (an empty line), however, defines the end of a paragraph; multiple empty lines are also treated as the end of a paragraph. An example of applying these rules is presented below: the left-hand side shows the user's input (.tex), while the right-hand side depicts the rendered output (.dvi/.pdf/.ps).

 It does not matter whether you enter one or several             spaces after a word. An empty line starts a new paragraph. It does not matter whether you enter one or several spaces after a word. An empty line starts a new paragraph.

### Reserved Characters

The following symbols are reserved characters that either have a special meaning under LaTeX or are unavailable in all the fonts. If you enter them directly in your text, they will normally not print, but rather make LaTeX do things you did not intend.

# $% ^ & _ { } ~ \ As you will see, these characters can be used in your documents all the same by adding a prefix backslash:  \# \$ \% \^{} \& \_ \{ \} \~{} \textbackslash{}

The backslash character \ cannot be entered by adding another backslash in front of it (\\); this sequence is used for line breaking. For introducing a backslash in math mode, you can use \backslash instead.

The commands \~ and \^ produce respectively a tilde and a hat which is placed over the next letter. For example \~n gives ñ. That's why you need braces to specify there is no letter as argument. You can also use \textasciitilde and \textasciicircum to enter these characters; or other commands .

If you want to insert text that might contain several particular symbols (such as URIs), you can consider using the \verb command, which will be discussed later in the section on formatting. For source code, see Source Code Listings

The 'less than' (<) and 'greater than' (>) characters are the only visible ASCII characters (not reserved) that will not print correctly. See Special Characters for an explanation and a workaround.

Non-ASCII characters (e.g. accents, diacritics) can be typed in directly for most cases. However you must configure the document appropriately. The other symbols and many more can be printed with special commands in mathematical formulae or as accents. We will tackle this issue in Special Characters.

### LaTeX groups

A group is basically defined by a pair of braces. The range of commands put between braces is limited to them. The \begingroup and \endgroup commands are equivalent to opening brace and closing brace.

Example:

 { \bf This is bold.} This is no longer bold.

For some commands it is important to restrict their range of action, and that's where groups come to be very useful.

### LaTeX environments

Environments in LaTeX have a role that is quite similar to commands, but they usually have effect on a wider part of the document. Their syntax is:

 \begin{environmentname} text to be influenced \end{environmentname}

Between the \begin and the \end you can put other commands and nested environments. The internal mechanism of environments defines a group, which makes its usage safe (no influence on the other parts of the document). In general, environments can accept arguments as well, but this feature is not commonly used and so it will be discussed in more advanced parts of the document.

Anything in LaTeX can be expressed in terms of commands and environments.

### LaTeX commands

LaTeX commands are case sensitive, and take one of the following two formats:

• They start with a backslash \ and then have a name consisting of letters only. Command names are terminated by a space, a number or any other "non-letter".
• They consist of a backslash \ and exactly one non-letter.

Some commands need an argument, which has to be given between curly braces { } after the command name. Some commands support optional parameters, which are added after the command name in square brackets [ ]. The general syntax is:

 \commandname[option1,option2,...]{argument1}{argument2}...

Most standard LaTeX commands have a switch equivalent. Switches have no arguments but apply on the rest of the scope, i.e. the current group or environment. A switch should (almost) never be called outside of any scope, otherwise it will apply on the rest of the document.

Example:

 % \emph is a command with argument, \em is a switch. \emph{emphasized text}, this part is normal % Correct {\em emphasized text}, this part is normal % Correct \em emphasized text, this part is normal % Incorrect \em{emphasized text}, this part is normal % Incorrect

When LaTeX encounters a % character while processing an input file, it ignores the rest of the current line, the line break, and all whitespace at the beginning of the next line.

This can be used to write notes into the input file, which will not show up in the printed version.

 This is an % stupid % Better: instructive <---- example: Supercal%             ifragilist% icexpialidocious This is an example: Supercalifragilisticexpialidocious

Note that the % character can be used to split long input lines that do not allow whitespace or line breaks, as with Supercalifragilisticexpialidocious above.

The core LaTeX language does not have a predefined syntax for commenting out regions spanning multiple lines. Refer to multi-line comments for simple workarounds.

## Our first document

Now we can create our first document. We will produce the absolute bare minimum that is needed in order to get some output; the well known Hello World! approach will be suitable here.

• Open your favorite text-editor. vim, emacs, Notepad++, and other text editors will have syntax highlighting that will help to write your files.
• Reproduce the following text in your editor. This is the LaTeX source.
 % hello.tex - Our first LaTeX example! \documentclass{article} \begin{document} Hello World! \end{document}
• Save your file as hello.tex.

When picking a name for your file, make sure it bears a .tex extension.

### What does it all mean?

 % hello.tex - Our first LaTeX example! The first line is a comment. This is because it begins with the percent symbol (%); when LaTeX sees this, it simply ignores the rest of the line. Comments are useful for people to annotate parts of the source file. For example, you could put information about the author and the date, or whatever you wish. \documentclass{article} This line is a command and tells LaTeX to use the article document class. A document class file defines the formatting, which in this case is a generic article format. The handy thing is that if you want to change the appearance of your document, substitute article for another class file that exists. \begin{document} This line is the beginning of the environment called document; it alerts LaTeX that content of the document is about to commence. Anything above this command is known generally to belong in the preamble. Hello World! This was the only actual line containing real content - the text that we wanted displayed on the page. \end{document} The document environment ends here. It tells LaTeX that the document source is complete, anything after this line will be ignored.

As we have said before, each of the LaTeX commands begins with a backslash (\). This is LaTeX's way of knowing that whenever it sees a backslash, to expect some commands. Comments are not classed as a command, since all they tell LaTeX is to ignore the line. Comments never affect the output of the document.

## Compilation

### Compilation process

The general concept is to transform a plain text document into a publishable format, mosty a DVI, PS or PDF file. This process is called compilation, which is done by an executable file called a compiler.

There are two main compilers.

• tex compiler reads a TeX .tex file and creates a .dvi.
• pdftex compiler reads a TeX .tex file and creates a .pdf.

These compilers are basically used to compile Plain TeX, not LaTeX. There is no such LaTeX compiler since LaTeX is just a bunch of macros for TeX. However, there are two executables related to the previous compilers:

• latex executable calls tex with LaTeX initialization files, reads a LaTeX .tex file and creates a .dvi
• pdflatex executable calls pdftex with LaTeX initialization files, reads a LaTeX .tex file and creates a .pdf

If you compile a Plain TeX document with a LaTeX compiler (such as pdflatex) it will work while the opposite is not true: if you try to compile a LaTeX source with a TeX compiler you will get many errors.

As a matter of fact, following your operating system latex and pdflatex are simple scripts or symbolic links.

Most of the programs should be already within your LaTeX distribution; the others come with w:Ghostscript, which is a free and multi-platform software as well. Here are common programs you expect to find in any LaTeX distribution:

• dvi2ps converts the .dvi file to .ps (postscript).
• dvi2pdf converts the .dvi file to .pdf (dvi2pdfm is an improved version).

and with Ghostscript:

• ps2pdf and pdf2ps converts the .ps file to .pdf and vice-versa.

When LaTeX was created, the only format it could create was DVI; later PDF support was added by pdflatex. PDF files can be created with both pdflatex and dvipdfm. The output of pdflatex takes direct advantage of modern features of PDF such as hyperlinks and embedded fonts, which are not part of DVI. Passing through DVI imposes limitations of its older format. On the other hand, some packages, such as PSTricks, exploit the process of conversion to DVI, and therefore will not work with pdflatex. Some of those packages embed information in the DVI that doesn't appear when the DVI is viewed, but reemerges when the DVI is converted to another, newer format.

You would write your document slightly differently depending on the compiler you are using (latex or pdflatex). But as we will see later it is possible to add a sort of abstraction layer to hide the details of which compiler you're using, while the compiler can handle the translation itself.

The following diagram shows the relationships between the LaTeX source code and the formats you can create from it:

The boxed red text represents the file formats, the blue text on the arrows represents the commands you have to use, the small dark green text under the boxes represents the image formats that are supported. Any time you pass through an arrow you lose some information, which might decrease the features of your document. Therefore, you should choose the shortest route to reach your target format. This is probably the most convenient way to obtain an output in your desired format anyway. Starting from a LaTeX source, the best way is to use only latex for a DVI output or pdflatex for a PDF output, converting to PostScript only when it is necessary to print the document.

Chapter Export To Other Formats discusses more about exporting LaTeX source to other file formats.

### Generating the document

It is clearly not going to be the most exciting document you have ever seen, but we want to see it nonetheless. I am assuming that you are at a command prompt, already in the directory where hello.tex is stored. LaTeX itself does not have a GUI (graphical user interface), since it is just a program that crunches away at your input files, and produces either a DVI or PDF file. Some LaTeX installations feature a graphical front-end where you can click LaTeX into compiling your input file. On other systems there might be some typing involved, so here is how to coax LaTeX into compiling your input file on a text based system. Please note: this description assumes that you already have a working LaTeX installation on your computer.

1. Type the command: latex hello (the .tex extension is not required, although you can include it if you wish)
2. Various bits of info about LaTeX and its progress will be displayed. If all went well, the last two lines displayed in the console will be:
Output written on hello.dvi (1 page, 232 bytes).
Transcript written on hello.log.

This means that your source file has been processed and the resulting document is called hello.dvi, which takes up 1 page and 232 bytes of space. Now you may view the DVI file. On Unix with X11 you can type xdvi foo.dvi, on Windows you can use a program called yap (yet another previewer). (Now evince and okular, the standard document viewers for many Linux distributions are able to view DVI files.)

This way you created the DVI file, but with the same source file you can create a PDF document. The steps are exactly the same as before, but you have to replace the command latex with pdflatex:

1. Type the command: pdflatex hello (as before, the .tex extension is not required)
2. Various bits of info about LaTeX and its progress will be displayed. If all went well, the last two lines displayed in the console will be:
Output written on hello.pdf (1 page, 5548 bytes).
Transcript written on hello.log.

you can notice that the PDF document is bigger than the DVI, even if it contains exactly the same information. The main differences between the DVI and PDF formats are:

• DVI needs less disk space and it is faster to create. It does not include the fonts within the document, so if you want the document to be viewed properly on another computer, there must be all the necessary fonts installed. It does not support any interactivity such as hyperlinks or animated images. DVI viewers are not very common, so you can consider using it for previewing your document while typesetting.
• PDF needs more disk space and it is slower to create, but it includes all the necessary fonts within the document, so you will not have any problem of portability. It supports internal and external hyperlinks. It also supports advanced typographic features: hanging punctuation, font expansion and margin kerning resulting in more flexibility available to the TeX engine and better looking output. Nowadays it is the de facto standard for sharing and publishing documents, so you can consider using it for the final version of your document.

About now, you saw you can create both DVI and PDF document from the same source. This is true, but it gets a bit more complicated if you want to introduce images or links. This will be explained in detail in the next chapters, but for now assume you can compile in both DVI and PDF without any problem.

Note, in this instance, due to the simplicity of the file, you only need to run the LaTeX command once. However, if you begin to create complex documents, including bibliographies and cross-references, etc, LaTeX needs to be executed multiple times to resolve the references. But this will be discussed in the future when it comes up.

### Autobuild Systems

Compiling using only the latex binary can be quite tricky as soon as you start working on more complex documents as previously stated. A number of programs exist to automatically read in a TeX document and run the appropriate compilers the appropriate number of times. For example, latexmk can generate a PDF from most TeX files simply:

## Files

### Picking suitable filenames

Never, ever use directories (folders) or file names that contain spaces. Although your operating system probably supports them, some don't, and they will only cause grief and tears with TeX. Make filenames as short or as long as you wish, but strictly avoid spaces. Stick to lower-case letters without accents (a-z), the digits 0-9, the hyphen (–), and only one full point or period (.) to separate the file extension (somewhat similar to the conventions for a good Web URL): it will let you refer to TeX files over the Web more easily and make your files more portable. Some operating systems do not distinguish between upper-case and lower-case letters, others do. Therefore it's best not to mix them.

### Ancillary files

The TeX compilers are single-pass processes. It means that there is no way for a compiler to jump around the document, which would be useful for the table of contents and references. Indeed the compiler cannot guess at which page a specific section is going to be printed, so when the table of contents is printed before the upcoming sections, it cannot set the page numbers.

To circumvent this issue, many LaTeX commands which need to jump use ancillary files which usually have the same file name as the current document but a different extension. It stores temporary data into these files and use them for the next compilation. So to have an up-to-date table of contents, you need to compile the document twice. There is no need to re-compile if no section moved.

For example, the temporary file for the table of contents data is filename.toc.

None of these files contains unrecoverable information. It means you can delete them safely, compiling will regenerate them automatically.

When you work with various capabilities of LaTeX (index, glossaries, bibliographies, etc.) you will soon find yourself in a maze of files with various extensions and probably no clue. The following list explains the most common file types you might encounter when working with TeX:

 .aux A file that transports information from one compiler run to the next. Among other things, the .aux file is used to store information associated with cross-references. .bbl Bibliography file output by BiBTeX and used by LaTeX .bib Bibliography database file. (where you can store a list of full bibliographic citations) .blg BiBTeX log file. (errors are logged here) .bst BiBTeX style file. .cls Class files define what your document looks like. They are selected with the \documentclass command. .dtx Documented TeX. This is the main distribution format for LaTeX style files. If you process a .dtx file you get documented macro code of the LaTeX package contained in the .dtx file. .ins The installer for the files contained in the matching .dtx file. If you download a LaTeX package from the net, you will normally get a .dtx and a .ins file. Run LaTeX on the .ins file to unpack the .dtx file. .fd Font description file telling LaTeX about new fonts. .dvi Device Independent File. This is the main result of a LaTeX compile run with latex. You can look at its content with a DVI previewer program or you can send it to a printer with dvips or a similar application. .pdf Portable Document Format. This is the main result of a LaTeX compile run with pdflatex. You can look at its content or print it with any PDF viewer. .log Gives a detailed account of what happened during the last compiler run. .toc Stores all your section headers. It gets read in for the next compiler run and is used to produce the table of contents. .lof This is like .toc but for the list of figures. .lot And again the same for the list of tables. .idx If your document contains an index. LaTeX stores all the words that go into the index in this file. Process this file with makeindex. .ind The processed .idx file, ready for inclusion into your document on the next compile cycle. .ilg Logfile telling what makeindex did. .sty LaTeX Macro package. This is a file you can load into your LaTeX document using the \usepackage command. .tex LaTeX or TeX input file. It can be compiled with latex. .out hyperref package file, just one for the master file.

## And what now?

### Common Elements

See Document Structure and the Common Elements part for all the common features that belong to every type of document.

### Non-English documents and special characters

LaTeX has some nice features for most languages in the world. You can tell LaTeX to follow typography rules of the target language, ease special characters input, and so on. See Special Characters and Internationalization.

### Modular document

See Modular Documents for good recommendations about the way to organize big projects into multiple files.

### Questions and Issues

We highly urge you to read the FAQ if you have issues about basic features, or if you want to read essential recommendations. For the more specific questions and issues, refer to the Tips and Tricks page. If you cannot find what you want here, use the Q&A page.

### Macros for the utmost efficiency

The full power of LaTeX resides in macros. They make your documents very dynamic and flexible. See the dedicated part.

### Working in a team

See chapter Collaborative Writing of LaTeX Documents.

# Document Structure

The main point of writing a text is to convey ideas, information, or knowledge to the reader. The reader will understand the text better if these ideas are well-structured, and will see and feel this structure much better if the typographical form reflects the logical and semantic structure of the content.

LaTeX is different from other typesetting systems in that you just have to tell it the logical and semantical structure of a text. It then derives the typographical form of the text according to the “rules” given in the document class file and in various style files. LaTeX allows users to structure their documents with a variety of hierarchical constructs, including chapters, sections, subsections and paragraphs.

## Global structure

When LaTeX processes an input file, it expects it to follow a certain structure. Thus every input file must contain the commands

 \documentclass{...} \begin{document} ... \end{document}

The area between \documentclass{...} and \begin{document} is called the preamble. It normally contains commands that affect the entire document.

After the preamble, the text of your document is enclosed between two commands which identify the beginning and end of the actual document:

 \begin{document} ... \end{document}

You would put your text where the dots are. The reason for marking off the beginning of your text is that LaTeX allows you to insert extra setup specifications before it (where the blank line is in the example above: we'll be using this soon). The reason for marking off the end of your text is to provide a place for LaTeX to be programmed to do extra stuff automatically at the end of the document, like making an index.

A useful side-effect of marking the end of the document text is that you can store comments or temporary text underneath the \end{document} in the knowledge that LaTeX will never try to typeset them:

 \end{document} ...

## Preamble

### Document classes

When processing an input file, LaTeX needs to know the type of document the author wants to create. This is specified with the \documentclass command. It is recommended to put this declaration at the very beginning.

 \documentclass[options]{class}

Here, class specifies the type of document to be created. The LaTeX distribution provides additional classes for other documents, including letters and slides. It is also possible to create your own, as is often done by journal publishers, who simply provide you with their own class file, which tells LaTeX how to format your content. But we'll be happy with the standard article class for now. The options parameter customizes the behavior of the document class. The options have to be separated by commas.

Example: an input file for a LaTeX document could start with the line

 \documentclass[11pt,twoside,a4paper]{article}

which instructs LaTeX to typeset the document as an article with a base font size of 11 points, and to produce a layout suitable for double sided printing on A4 paper.

Here are some document classes that can be used with LaTeX:

 article For articles in scientific journals, presentations, short reports, program documentation, invitations, ... IEEEtran For articles with the IEEE Transactions format. proc A class for proceedings based on the article class. minimal Is as small as it can get. It only sets a page size and a base font. It is mainly used for debugging purposes. report For longer reports containing several chapters, small books, thesis, ... book For real books. slides For slides. The class uses big sans serif letters. memoir For changing sensibly the output of the document. It is based on the book class, but you can create any kind of document with it [4] letter For writing letters. beamer For writing presentations (see LaTeX/Presentations).

The standard document classes that are a part of LaTeX are built to be fairly generic, which is why they have a lot of options in common. Other classes may have different options (or none at all). Normally, third party classes come with some documentation to let you know. The most common options for the standard document classes are listed in the following table:

 10pt, 11pt, 12pt Sets the size of the main font in the document. If no option is specified, 10pt is assumed. a4paper, letterpaper,... Defines the paper size. The default size is letterpaper; However, many European distributions of TeX now come pre-set for A4, not Letter, and this is also true of all distributions of pdfLaTeX. Besides that, a5paper, b5paper, executivepaper, and legalpaper can be specified. fleqn Typesets displayed formulas left-aligned instead of centered. leqno Places the numbering of formulas on the left hand side instead of the right. titlepage, notitlepage Specifies whether a new page should be started after the document title or not. The article class does not start a new page by default, while report and book do. twocolumn Instructs LaTeX to typeset the document in two columns instead of one. twoside, oneside Specifies whether double or single sided output should be generated. The classes article and report are single sided and the book class is double sided by default. Note that this option concerns the style of the document only. The option twoside does not tell the printer you use that it should actually make a two-sided printout. landscape Changes the layout of the document to print in landscape mode. openright, openany Makes chapters begin either only on right hand pages or on the next page available. This does not work with the article class, as it does not know about chapters. The report class by default starts chapters on the next page available and the book class starts them on right hand pages. draft makes LaTeX indicate hyphenation and justification problems with a small square in the right-hand margin of the problem line so they can be located quickly by a human. It also suppresses the inclusion of images and shows only a frame where they would normally occur.

For example, if you want a report to be in 12pt type on A4, but printed one-sided in draft mode, you would use:

 \documentclass[12pt,a4paper,oneside,draft]{report}

### Packages

While writing your document, you will probably find that there are some areas where basic LaTeX cannot solve your problem. If you want to include graphics, colored text or source code from a file into your document, you need to enhance the capabilities of LaTeX. Such enhancements are called packages. Some packages come with the LaTeX base distribution. Others are provided separately. Modern TeX distributions come with a large number of packages pre-installed. Packages are activated with the

 \usepackage[options]{package}

command, where package is the name of the package and options is a list of keywords that trigger special features in the package. For example, to use the color package, which lets you typeset in colors, you would type:

 \documentclass[11pt,a4paper,oneside]{report} \usepackage{color} \begin{document} ... \end{document}

You can include several package names in one \usepackage command by separating the names with commas, like this:

 \usepackage{package1,package2,package3}

and you can have more than one \usepackage command. Some packages allow optional settings in square brackets. If you use these, you must give the package its own separate \usepackage command, like geometry shown below:

 \documentclass[11pt,a4paper,oneside]{report} \usepackage{pslatex,palatino,avant,graphicx,color} \usepackage[margin=2cm]{geometry} \begin{document} \title{\color{red}Practical Typesetting} \author{\color{blue}Name\\ Work} \date{\color{green}December 2005} \maketitle \end{document}

Many packages can have additional formatting specifications in optional arguments in square brackets, in the same way as geometry does. Read the documentation for the package concerned to find out what can be done. You can pass several options together separated by a comma:

 \usepackage[option1,option2,option3]{''package_name''}

## The document environment

### Top matter

At the beginning of most documents there will be information about the document itself, such as the title and date, and also information about the authors, such as name, address, email etc. All of this type of information within LaTeX is collectively referred to as top matter. Although never explicitly specified (there is no \topmatter command) you are likely to encounter the term within LaTeX documentation.

A simple example:

 \documentclass[11pt,a4paper]{report} \begin{document} \title{How to Structure a LaTeX Document} \author{Andrew Roberts} \date{December 2004} \maketitle \end{document}

The \title, \author, and \date commands are self-explanatory. You put the title, author name, and date in curly braces after the relevant command. The title and author are usually compulsory (at least if you want LaTeX to write the title automatically); if you omit the \date command, LaTeX uses today's date by default. You always finish the top matter with the \maketitle command, which tells LaTeX that it's complete and it can typeset the title according to the information you have provided and the class (style) you are using. If you omit \maketitle, the titling will never be typeset (unless you write your own).

Here is a more complicated example:

 \title{How to Structure a \LaTeX{} Document} \author{Joe Bloggs\\   School of Computing,\\   University of Study,\\   Books,\\   United Readdom,\\   RN 1234\\   \texttt{jbloggs@latex.wizard}} \date{\today} \maketitle

as you can see, you can use commands as arguments of \title and the others. The double backslash (\\) is the LaTeX command for forced linebreak. LaTeX normally decides by itself where to break lines, and it's usually right, but sometimes you need to cut a line short, like here, and start a new one.

If there are two authors separate them with the \and command:

 \title{Our Fun Document} \author{Jane Doe \and John Doe} \date{\today} \maketitle

If you are provided with a class file from a publisher, or if you use the AMS article class (amsart), then you can use several different commands to enter author information. The email address is at the end, and the \texttt commands formats the email address using a mono-spaced font. The built-in command called \today will be replaced with the current date when processed by LaTeX. But you are free to put whatever you want as a date, in no set order. If braces are left empty, then the date is omitted.

Using this approach, you can create only basic output whose layout is very hard to change. If you want to create your title freely, see the Title Creation section.

### Abstract

As most research papers have an abstract, there are predefined commands for telling LaTeX which part of the content makes up the abstract. This should appear in its logical order, therefore, after the top matter, but before the main sections of the body. This command is available for the document classes article and report, but not book.

 \documentclass{article} \begin{document} \begin{abstract} Your abstract goes here... ... \end{abstract} ... \end{document}

By default, LaTeX will use the word "Abstract" as a title for your abstract. If you want to change it into anything else, e.g. "Executive Summary", add the following line before you begin the abstract environment:

 \renewcommand{\abstractname}{Executive Summary}

### Sectioning commands

The commands for inserting sections are fairly intuitive. Of course, certain commands are appropriate to different document classes. For example, a book has chapters but an article doesn't. Here are some of the structure commands found in simple.tex.

 \chapter{Introduction} This chapter's content... \section{Structure} This section's content... \subsection{Top Matter} This subsection's content... \subsubsection{Article Information} This subsubsection's content...

Notice that you do not need to specify section numbers; LaTeX will sort that out for you. Also, for sections, you do not need to use \begin and \end commands to indicate which content belongs to a given block.

LaTeX provides 7 levels of depth for defining sections (see table below). Each section in this table is a subsection of the one above it.

Command Level Comment
\part{''part''} -1 not in letters
\chapter{''chapter''} 0 only books and reports
\section{''section''} 1 not in letters
\subsection{''subsection''} 2 not in letters
\subsubsection{''subsubsection''} 3 not in letters
\paragraph{''paragraph''} 4 not in letters
\subparagraph{''subparagraph''} 5 not in letters

All the titles of the sections are added automatically to the table of contents (if you decide to insert one). But if you make manual styling changes to your heading, for example a very long title, or some special line-breaks or unusual font-play, this would appear in the Table of Contents as well, which you almost certainly don't want. LaTeX allows you to give an optional extra version of the heading text which only gets used in the Table of Contents and any running heads, if they are in effect. This optional alternative heading goes in [square brackets] before the curly braces:

 \section[Effect on staff turnover]{An analysis of the effect of the revised recruitment policies on staff turnover at divisional headquarters}

#### Section numbering

Numbering of the sections is performed automatically by LaTeX, so don't bother adding them explicitly, just insert the heading you want between the curly braces. Parts get roman numerals (Part I, Part II, etc.); chapters and sections get decimal numbering like this document, and appendices (which are just a special case of chapters, and share the same structure) are lettered (A, B, C, etc.).

You can change the depth to which section numbering occurs, so you can turn it off selectively. By default it is set to 2. If you only want parts, chapters, and sections numbered, not subsections or subsubsections etc., you can change the value of the secnumdepth counter using the \setcounter command, giving the depth level you wish. For example, if you want to change it to "1":

 \setcounter{secnumdepth}{1}

A related counter is tocdepth, which specifies what depth to take the Table of Contents to. It can be reset in exactly the same way as secnumdepth. For example:

 \setcounter{tocdepth}{3}

To get an unnumbered section heading which does not go into the Table of Contents, follow the command name with an asterisk before the opening curly brace:

 \subsection*{Introduction}

All the divisional commands from \part* to \subparagraph* have this "starred" version which can be used on special occasions for an unnumbered heading when the setting of secnumdepth would normally mean it would be numbered.

If you want the unnumbered section to be in the table of contents anyway, use the \addcontentsline command like this:

Note that if you use PDF bookmarks you will need to add a phantom section so that bookmark will lead to the correct place in the document. The \phantomsection command is defined in the hyperref package, and is implemented normally as follows:

For chapters you will also need to clear the page (this will also correct page numbering in the ToC):

 \cleardoublepage \phantomsection \addcontentsline{toc}{chapter}{Bibliography} \bibliographystyle{unsrt} \bibliography{my_bib_file}

The value where the section numbering starts from can be set with the following command:

 \setcounter{section}{4}

The next section after this command will now be numbered 5.

For more details on counters, see the dedicated chapter.

See Counters.

### Ordinary paragraphs

Paragraphs of text come after section headings. Simply type the text and leave a blank line between paragraphs. The blank line means "start a new paragraph here": it does not mean you get a blank line in the typeset output. For formatting paragraph indents and spacing between paragraphs, refer to the Paragraph Formatting section.

All auto-numbered headings get entered in the Table of Contents (ToC) automatically. You don't have to print a ToC, but if you want to, just add the command \tableofcontents at the point where you want it printed (usually after the Abstract or Summary).

Entries for the ToC are recorded each time you process your document, and reproduced the next time you process it, so you need to re-run LaTeX one extra time to ensure that all ToC pagenumber references are correctly calculated. We've already seen how to use the optional argument to the sectioning commands to add text to the ToC which is slightly different from the one printed in the body of the document. It is also possible to add extra lines to the ToC, to force extra or unnumbered section headings to be included.

The commands \listoffigures and \listoftables work in exactly the same way as \tableofcontents to automatically list all your tables and figures. If you use them, they normally go after the \tableofcontents command. The \tableofcontents command normally shows only numbered section headings, and only down to the level defined by the tocdepth counter, but you can add extra entries with the \addcontentsline command. For example if you use an unnumbered section heading command to start a preliminary piece of text like a Foreword or Preface, you can write:

This will format an unnumbered ToC entry for "Preface" in the "subsection" style. You can use the same mechanism to add lines to the List of Figures or List of Tables by substituting lof or lot for toc. If the hyperref package is used and the link does not point to the correct chapter, the command \phantomsection in combination with \clearpage or \cleardoublepage can be used (see also Labels and Cross-referencing):

 \cleardoublepage \phantomsection \addcontentsline{toc}{chapter}{List of Figures} \listoffigures

To change the title of the TOC, you have to paste this command \renewcommand{\contentsname}{<New table of contents title>} in your document preamble. The List of Figures (LoF) and List of Tables (LoT) names can be changed by replacing the \contentsname with \listfigurename for LoF and \listtablename for LoT.

#### Depth

The default ToC will list headings of level 3 and above. To change how deep the table of contents displays automatically the following command can be used in the preamble:

 \setcounter{tocdepth}{4}

This will make the table of contents include everything down to paragraphs. The levels are defined above on this page. Note that this solution does not permit changing the depth dynamically.

You can change the depth of specific section type, which could be useful for PDF bookmarks (if you are using the hyperref package) :


In order to further tune the display or the numbering of the table of contents, for instance if the appendix should be less detailed, you can make use of the tocvsec2 package (CTAN, doc).

## Book structure

The standard LaTeX book class follows the same layout described above with some additions. By default a book will be two-sided, i.e. left and right margins will change according to the page number parity. Furthermore current chapter and section will be printed in the header.

If you do not make use of chapters, it is barely useful to use the book class.

Additionally the class provides macros to change the formatting of some places of the document. We will give you some advice on how to use them properly.[1]

 \begin{document} \frontmatter \maketitle % Introductory chapters \chapter{Preface} % ... \mainmatter \chapter{First chapter} % ... \appendix \chapter{First Appendix} \backmatter \chapter{Last note}
• The frontmatter chapters will not be numbered. Page numbers will be printed in roman numerals. Frontmatter is not supposed to have sections, since they will be number 0.n because there is no chapter numbering. Check the Counters chapter for a fix.
• The mainmatter chapters works as usual. The command resets the page numbering. Page numbers will be printed in arabic numerals.
• The \appendix macro can be used to indicate that following sections or chapters are to be numbered as appendices. Appendices can be used for the article class too:
 \appendix \section{First Appendix}

Only use the \appendix macro once for all appendices.

• The backmatter behaves like the frontmatter. It has the same issue with section numbering.

As a general rule you should avoid mixing the command order. Nonetheless all commands are optional, so you might consider using only a few.

Note that the special content like the table of contents is considered as an unnumbered chapter.

### Page order

This is one traditional page order for books.

Frontmatter
1. Half-title
2. Empty
3. Title page
4. Information (copyright notice, ISBN, etc.)
5. Dedication if any, else empty
7. List of figures (can be in the backmatter too)
8. Preface chapter
Mainmatter
1. Main topic
Appendix
1. Some subordinate chapters
Backmatter
1. Bibliography
2. Glossary / Index

### Introductory chapters with main page numbering

You may be tempted to put your introductory chapters in the main matter so that it follows the same numbering as the main chapters. This is not how the class was meant to be used, so you will run into an issue if you don't want the chapter to be numbered.

 \frontmatter \maketitle \tableofcontents \mainmatter %% WRONG! \chapter*{Introduction} Blah \clearpage Blah \chapter{First one} Blah

In the above code sample, the second page of the introduction will have TABLE OF CONTENTS printed in the header. This is because the starred \chapter* command does not set the leftmark -- see Page Layout. And it will not be printed in the table of contents either.

The trick is to set the leftmark and the TOC manually:

 \chapter*{Introduction} \markboth{\MakeUppercase{Introduction}}{} \addcontentsline{toc}{chapter}{Introduction} % ...

TABLE OF CONTENTS is traditionally printed both left and right, but here we print it like other chapters, only right on even pages.

To make it more convenient, you might use a macro:

 \newcommand\intro[1]{   \chapter*{#1}   \markboth{\MakeUppercase{#1}}{}   \addcontentsline{toc}{chapter}{#1}} %% ... \intro{Introduction}

## Special pages

Comprehensive papers often feature special pages at the end, like indices, glossaries and bibliographies. Since this is a quite complex topic, we will give you details in the dedicated part Special Pages.

### Bibliography

Any good research paper will have a complete list of references. LaTeX has two ways of inserting your references into a document:

• you can embed them within the document itself. It's simpler, but it can be time-consuming if you are writing several papers about similar subjects so that you often have to cite the same books.
• you can store them in an external BibTeX file and then link them via a command to your current document and use a Bibtex style to define how they appear. This way you can create a small database of the references you might use and simply link them, letting LaTeX work for you.

To learn how to add a bibliography to your document, see the Bibliography Management section.

# Text Formatting

This section will guide you through the formatting techniques of the text. Formatting tends to refer to most things to do with appearance, so it makes the list of possible topics quite eclectic: text style, spacing, etc. If formatting may also refer to paragraphs and to the page layout, we will focus on the customization of words and sentences for now.

A lot of formatting techniques are required to differentiate certain elements from the rest of the text. It is often necessary to add emphasis to key words or phrases. Footnotes are useful for providing extra information or clarification without interrupting the main flow of text. So, for these reasons, formatting is very important. However, it is also very easy to abuse, and a document that has been over-done can look and read worse than one with none at all.

LaTeX is so flexible that we will actually only skim the surface, as you can have much more control over the presentation of your document if you wish. Having said that, one of the purposes of LaTeX is to take away the stress of having to deal with the physical presentation yourself, so you need not get too carried away!

## Spacing

### Line Spacing

If you want to use larger inter-line spacing in a document, you can change its value by putting the

command into the preamble of your document. Use \linespread{1.3} for "one and a half" line spacing, and \linespread{1.6} for "double" line spacing. Normally the lines are not spread, so the default line spread factor is 1.

The setspace package allows more fine-grained control over line spacing. To set "one and a half" line spacing document-wide, but not where it is usually unnecessary (e.g. footnotes, captions):

 \usepackage{setspace} %\singlespacing \onehalfspacing %\doublespacing %\setstretch{1.1}

To change line spacing within the document, the setspace package provides the environments singlespace, onehalfspace, doublespace and spacing:

 This paragraph has \\ default \\ line spacing.   \begin{doublespace}   This paragraph has \\ double \\ line spacing. \end{doublespace}   \begin{spacing}{2.5}   This paragraph has \\ huge gaps \\ between lines. \end{spacing}

### 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 the processors from inserting a line break between them. Besides a non-breaking space cannot be enlarged. It is very important for a consistent reading.

LaTeX uses the '~' symbol as a non-breaking space. You would 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.

Examples:

 D.~\textsc{Knuth} 50~€

### Space between words and sentences

To get a straight right margin in the output, LaTeX inserts varying amounts of space between the words. By default, it also inserts slightly more space at the end of a sentence. However, the extra space added at the end of sentences is generally considered typographically old-fashioned in English language printing. (The practice is found in nineteenth century design and in twentieth century typewriter styles.) Most modern typesetters treat the end of sentence space the same as the interword space. (See for example, Bringhurst's Elements of Typographic Style.) The additional space after periods can be disabled with the command

 \frenchspacing

which tells LaTeX not to insert more space after a period than after ordinary character. Frenchspacing can be turned off later in your document via the \nonfrenchspacing command.

If an author wishes to use the wider end-of-sentence spacing, care must be exercised so that punctuation marks are not misinterpreted as ends of sentences. TeX assumes that sentences end with periods, question marks or exclamation marks. Although if a period follows an uppercase letter, this is not taken as a sentence ending, since periods after uppercase letters normally occur in abbreviations. Any exception from these assumptions has to be specified by the author. A backslash in front of a space generates a space that will not be enlarged. A tilde ‘~’ character generates a non-breaking space. The command \@ in front of a period specifies that this period terminates a sentence even when it follows an uppercase letter. (If you are using \frenchspacing, then none of these exceptions need be specified.)

### Stretched spaces

You can insert a horizontal stretched space with \hfill in a line so that the rest gets "pushed" toward the right margin. For instance this may be useful in the header.

 Author Name \hfill \today

Similarly you can insert vertical stretched space with \vfill. It may be useful for special pages.

 \maketitle \vfill \tableofcontents \clearpage \section{My first section} % ...

See Lengths for more details.

### Manual spacing

The spaces between words and sentences, between paragraphs, sections, subsections, etc. is determined automatically by LaTeX. It is against LaTeX philosophy to insert spaces manually and will usually lead to bad formatting. Manual spacing is a matter of macro writing and package creation.

See Lengths for more details.

## Hyphenation

LaTeX hyphenates words whenever necessary. Hyphenation rules will vary for different languages. LaTeX only supports english by default, so if you want to have correct hyphenation rules for your desired language, see Internationalization.

If the hyphenation algorithm does not find the correct hyphenation points, you can remedy the situation by using the following commands to tell TeX about the exception. The command

 \hyphenation{word list}

causes the words listed in the argument to be hyphenated only at the points marked by “-”. The argument of the command should only contain words built from normal letters, or rather characters that are considered to be normal letters by LaTeX. It is known that the hyphenation algorithm does not find all correct American English hyphenation points for several words. A log of known exceptions is published periodically in the TUGboat journal. (See a 2008 list: http://www.tug.org/TUGboat/Articles/tb29-2/tb92hyf.pdf)

The hyphenation hints are stored for the language that is active when the hyphenation command occurs. This means that if you place a hyphenation command into the preamble of your document it will influence the English language hyphenation. If you place the command after the \begin{document} and you are using some package for national language support like babel, then the hyphenation hints will be active in the language activated through babel. The example below will allow “hyphenation” to be hyphenated as well as “Hyphenation”, and it prevents “FORTRAN”, “Fortran” and “fortran” from being hyphenated at all. No special characters or symbols are allowed in the argument. Example:

 \hyphenation{FORTRAN Hy-phen-a-tion}

The command \- inserts a discretionary hyphen into a word. This also becomes the only point where hyphenation is allowed in this word. This command is especially useful for words containing special characters (e.g., accented characters), because LaTeX does not automatically hyphenate words containing special characters.

 \begin{minipage}{2in} I think this is: su\-per\-cal\-% i\-frag\-i\-lis\-tic\-ex\-pi\-% al\-i\-do\-cious \end{minipage} $\begin{array}{l}\mbox{I think this is: supercalifragi-}\\ \mbox{listicexpialidocious}\end{array}$

LaTeX does not hyphenate compound words that contain a dash[1]. There are two packages that can add back flexibility. The hyphenat package supplies the \hyp command. This command typesets the dash and then subjects the constituent words to automatic hyphenation. After loading the package:

 \usepackage{hyphenat}

one should write, instead of electromagnetic-endioscopy:

 electromagnetic\hyp{}endioscopy

The extdash package also offers features for controlling the hyphenation of compound words containing dashes — as opposed to the words themselves which it leaves to LaTeX. The shortcuts option enables a more compressed syntax:

 \usepackage[shortcuts]{extdash}

Typical usage is as follows, assuming the compressed syntax. In both cases, LaTeX can break and hyphenate the constituent words, but in the latter case, it will not break after the L:

 electromagnetic\-/endioscopy L\=/approximation

One or more words can be kept together on the one line with the standard LaTeX command:

 \mbox{text}

This prevents hyphenation and causes its argument to be kept together under all circumstances. For example:

 My phone number will change soon. It will be \mbox{0116 291 2319}.

\fbox is similar to \mbox, but in addition there will be a visible box drawn around the content.

To avoid hyphenation altogether, the penalty for hyphenation can be set to an extreme value:

 \hyphenpenalty=100000

You can change the degree to which LaTeX will hyphenate by changing the value of \tolerance=1000 and \hyphenpenalty=1000. You'll have to experiment with the values to achieve the desired effect. A document which has a low tolerance value will cause LaTeX not to tolerate uneven spacing between words, hyphenating words more frequently than in documents with higher tolerances. Also note that using a higher text width will decrease the probability of encountering badly hyphenated word. For example adding

 \usepackage{geometry}

will widen the text width and reduce the amount of margin overruns.

## Quote-marks

LaTeX treats left and right quotes as different entities. For single quotes,  (on American keyboards, this symbol is found on the tilde key (adjacent to the number 1 key on most keyboards) gives a left quote mark, and ' is the right. For double quotes, simply double the symbols, and LaTeX will interpret them accordingly. (Don't use the " for right double quotes: when the babel package is used for some languages (e.g. German), the " is redefined to produce an umlaut accent; using " for right double quotes will either lead to bad spacing or it being used to produce an umlaut). On British keyboards, '  ' is left of the ' 1 ' key and shares the key with ' ¬ ', and sometimes ' ¦ ' or ' | '. The apostrophe (') key is to the right of the colon/semicolon key and shares it with the ' @ ' symbol.

 To quote' in LaTeX To quote'' in LaTeX To quote" in LaTeX To ,,quote'' in LaTeX ,,German quotation marks <> Please press the x' key.'' ,,Proszę, naciśnij klawisz <>''.

The right quote is also used for apostrophe in LaTeX without trouble.

For left bottom quote and European quoting style you need to use T1 font encoding enabled by:

 \usepackage[T1]{fontenc}

See Fonts for more details on font encoding.

The package csquotes offers a multi-lingual solution to quotations, with integration to citation mechanisms offered by BibTeX. This package allows one for example to switch languages and quotation styles according to babel language selections.

## Diacritics and accents

Most accents and diacritics may be inserted with direct keyboard input by configuring the preamble properly. For symbols unavailable on your keyboard, diacritics may be added to letters by placing special escaped metacharacters before the letter that requires the diacritic.

## Margin misalignment and interword spacing

Some very long words, numbers or URLs may not be hyphenated properly and move far beyond the side margin. One solution for this problem is to use sloppypar environment, which tells LaTeX to adjust word spacing less strictly. As a result, some spaces between words may be a bit too large, but long words will be placed properly.

 This is a paragraph with a very long word ABCDEFGHIJKLMNOPRST; then we have another bad thing --- a long number 1234567890123456789. \begin{sloppypar} This is a paragraph with a very long word ABCDEFGHIJKLMNOPRST; then we have an another bad thing --- a long number 1234567890123456789. \end{sloppypar}

Another solution is to edit the text to avoid long words, numbers or urls approaching the side margin.

## Ligatures

Some letter combinations are typeset not just by setting the different letters one after the other, but by actually using special symbols (like "ﬀ"), called ligatures. Ligatures can be prohibited by inserting {} or, if this does not work, {\kern0pt} between the two letters in question. This might be necessary with words built from two words. Here is an example:

 \Large Not shelfful\\ but shelf{}ful

Some tools are unable to perform search in documents that contain ligatures (a search for "finally" wouldn't find the string "nally"). If one desires, for greater accessibility, to disable ligatures altogether in the whole document, the \DisableLigatures from the microtype package can be used:

 \usepackage{microtype} \DisableLigatures{encoding = *, family = *}

Note that this will also disable ligatures such as "--" to "–", "---" to "—", etc.

If you are using XeLaTeX and OpenType fonts, the fontspec package allows for standard ligatures to be turned off as well as fancy swash ligatures to be turned on.

Another solution is to use the cmap package, which will help the reader to interpret the ligatures:

 \usepackage[resetfonts]{cmap}

## Slash marks

The normal typesetting of the / character in LaTeX does not allow following characters to be "broken" onto new lines, which often create "overfull" errors in output (where letters push off the margin). Words that use slash marks, such as "input/output" should be typeset as "input\slash output", which allow the line to "break" after the slash mark (if needed). The use of the / character in LaTeX should be restricted to units, such as "mm/year", which should not be broken over multiple lines.

## Fonts

To change the font family, emphasize text, and other font-related issues, see Fonts.

## Formatting macros

Even if you can easily change the output of your fonts using those commands, you're better off not using explicit commands like this, because they work in opposition to the basic idea of LaTeX, which is to separate the logical and visual markup of your document. This means that if you use the same font changing command in several places in order to typeset a special kind of information, you should use \newcommand to define a "logical wrapper command" for the font changing command.

 \newcommand{\oops}[1]{\textit{#1}} Do not \oops{enter} this room, it’s occupied by \oops{machines} of unknown origin and purpose. Do not enter this room, it’s occupied by machines of unknown origin and purpose.

This approach has the advantage that you can decide at some later stage that you want to use some visual representation of danger other than \textit, without having to wade through your document, identifying all the occurrences of \textit and then figuring out for each one whether it was used for pointing out danger or for some other reason.

See Macros for more details.

## Text mode superscript and subscript

To superscript text in text-mode, you can use the \textsuperscript{} command. This allows you to, for instance, typeset 6th as 6th:

 Michelangelo was born on March 6\textsuperscript{th}, 1475.

Subscripting in text-mode is not supported by LaTeX alone; however, several packages allow the use of the \textsubscript{} command. For instance, bpchem, KOMA-Script2, and fixltx2e all support this command. Of these, fixltx2e is perhaps the most universal option since it is distributed with LaTeX and requires no additional packages to be implemented.

 % In your preamble, add: \usepackage{fixltx2e} ... % In your document: It is found that height\textsubscript{apple tree} is different than height\textsubscript{orange tree}. $\text{It is found that height}_\text{apple tree}\text{ is different than height}_\text{orange tree}\text{.}\,$


When using \textbf{} inside the alltt enviroment, note that the standard font has no bold TT font. Txtfonts has bold fonts: just add \renewcommand{\ttdefault}{txtt} after \usepackage{alltt}.

If you just want to introduce a short verbatim phrase, you don't need to use the whole environment, but you have the \verb command:

 \verb+my text+

The first character following \verb is the delimiter: here we have used "+", but you can use any character you like except *; \verb will print verbatim all the text after it until it finds the next delimiter. For example, the code:

 \verb;\textbf{Hi mate!};

will print \textbf{Hi mate!}, ignoring the effect \textbf should have on text.

For more control over formatting, however, you can try the fancyvrb package, which provides a Verbatim environment (note the capital letter) which lets you draw a rule round the verbatim text, change the font size, and even have typographic effects inside the Verbatim environment. It can also be used in conjunction with the fancybox package and it can add reference line numbers (useful for chunks of data or programming), and it can even include entire external files.

#### Typesetting URLs

One of either the hyperref or url packages provides the \url command, which properly typesets URLs, for example:

 Go to \url{http://www.uni.edu/~myname/best-website-ever.html} for my website.

will show this URL exactly as typed (similar to the \verb command), but the \url command also performs a hyphenless break at punctuation characters (only in PDFLaTeX, not in plain LaTeX+ dvips). It was designed for Web URLs, so it understands their syntax and will never break mid-way through an unpunctuated word, only at slashes and full stops. Bear in mind, however, that spaces are forbidden in URLs, so using spaces in \url arguments will fail, as will using other non-URL-valid characters.

When using this command through the hyperref package, the URL is "clickable" in the PDF document, whereas it is not linked to the web when using only the url package. Also when using the hyperref package, to remove the border placed around a URL, insert pdfborder = {0 0 0 0} inside the \hypersetup{}. (Alternately pdfborder = {0 0 0} might work if the four zeroes do not.)

You can put the following code into your preamble to change the style, how URLs are displayed to the normal font:

 \urlstyle{same}

#### Listing environment

This is also an extension of the verbatim environment provided by the moreverb package. The extra functionality it provides is that it can add line numbers along side the text. The command: \begin{listing}[step]{first line}. The mandatory first line argument is for specifying which line the numbering shall commence. The optional step is the step between numbered lines (the default is 1, which means every line will be numbered).

To use this environment, remember to add \usepackage{moreverb} to the document preamble.

As we have seen, the only way LaTeX allows you to add comments is by using the special character %, that will comment out all the rest of the line after itself. This approach is really time-consuming if you want to insert long comments or just comment out a part of your document that you want to improve later, unless you're using an editor that automates this process. Alternatively, you can use the verbatim package, to be loaded in the preamble as usual:

 \usepackage{verbatim}

(you can also use the comment package instead) you can use an environment called comment that will comment out everything within itself. Here is an example:

 This is another \begin{comment} rather stupid, but helpful \end{comment} example for embedding comments in your document. This is another example for embedding comments in your document.

Note that this won’t work inside complex environments, like math for example. You may be wondering, why should I load a package called verbatim to have the possibility to add comments? The answer is straightforward: commented text is interpreted by the compiler just like verbatim text, the only difference is that verbatim text is introduced within the document, while the comment is just dropped.

Alternatively, you can define a \comment{} command, by adding the following to the document's preamble:

 \newcommand{\comment}[1]{}

Then, to comment out text, simply do something like this:

 \comment{This is a long comment and can extend over multiple lines, etc.} But it won't show. But it won't show.

This approach can, however, produce unwanted spaces in the document, so it may work better to use

 \newcommand{\comment}[2]{#2}

Then if you supply only one argument to \comment{}, this has the desired effect without producing extra spaces.

Another drawback is that content is still parsed and possibly expanded, so you cannot put anything you want in it (such as LaTeX commands).

### Quoting text

LaTeX provides several environments for quoting text; they have small differences and they are aimed for different types of quotations. All of them are indented on either margin, and you will need to add your own quotation marks if you want them. The provided environments are:

quote
for a short quotation, or a series of small quotes, separated by blank lines.
quotation
for use with longer quotations, of more than one paragraph, because it indents the first line of each paragraph.
verse
is for quotations where line breaks are important, such as poetry. Once in, new stanzas are created with a blank line, and new lines within a stanza are indicated using the newline command, \\. If a line takes up more than one line on the page, then all subsequent lines are indented until explicitly separated with \\.

### Abstracts

In scientific publications it is customary to start with an abstract which gives the reader a quick overview of what to expect. See Document Structure.

## Notes and References

This page uses material from Andy Roberts' Getting to grips with LaTeX with permission from the author.

# Colors

Adding colors to your text is supported by the color package. Using this package, you can set the color of the font of the text, and set the background color of the page. You can use one of the predefined colors such as white, red, or yellow, or you can define your own named colors. It's also possible to color formulas in math-environments.

## Adding the color package

To make use of these color features the color package must be inserted into the preamble.

 \usepackage{color}

Alternatively, one can write:

 \usepackage[usenames,dvipsnames,svgnames,table]{xcolor}

The \usepackage is obvious, but the initialization of additional commands like usenames allows you to use names of the default colors, the same 16 base colors as used in HTML. The dvipsnames allows you access to more colors, another 64, and svgnames allows access to about 150 colors. The initialization of "table" allows colors to be added to tables by placing the color command just before the table. The package loaded here is the xcolor package.

If you need more colors, then you may also want to look at adding the x11names to the initialization section as well, this offers more than 300 colors, but you need to make sure your xcolor package is the most recent you can download.

## Entering colored text

The simplest way to type colored text is by:

 \textcolor{declared-color}{text}

where declared-color is a color that was defined before by \definecolor.

Another possible way by

 {\color{declared-color} some text}

that will switch the standard text color to the color you want. It will work until the end of the current TeX group. For example:

 \emph{some black text, \color{red} followed by a red fragment}, going black again.

The difference between \textcolor and \color is the same as that between \texttt and \ttfamily, you can use the one you prefer. The \color environment allows the text to run over multiple lines and other text environments whereas the text in \textcolor must all be one paragraph and not contain other environments.

You can change the background color of the whole page by:

 \pagecolor{declared-color}

## Entering colored background for the text

 \colorbox{declared-color}{text}

If the background color and the text color is changed, then:

 \colorbox{declared-color1}{\color{declared-color2}text}

There is also \fcolorbox to make framed background color in yet another color:

 \fcolorbox{declared-color-frame}{declared-color-background}{text}

## Predefined colors

The predefined color names are

white, black, red, green, blue, cyan, magenta, yellow.

There may be other pre-defined colors on your system, but these should be available on all systems.

If you would like a color not pre-defined, you can use one of the 68 dvips colors, or define your own. These options are discussed in the following sections

### The 68 standard colors known to dvips

Invoke the package with the usenames and dvipsnames option. If you are using tikz or pstricks package you must declare the color package before that, otherwise it will not work.

 \usepackage[usenames,dvipsnames]{color}
Name Color   Name Color
Apricot     Aquamarine
Bittersweet     Black
Blue     BlueGreen
BlueViolet     BrickRed
Brown     BurntOrange
Cerulean     CornflowerBlue
Cyan     Dandelion
DarkOrchid     Emerald
ForestGreen     Fuchsia
Goldenrod     Gray
Green     GreenYellow
JungleGreen     Lavender
LimeGreen     Magenta
Mahogany     Maroon
Melon     MidnightBlue
Mulberry     NavyBlue
OliveGreen     Orange
OrangeRed     Orchid
Peach     Periwinkle
PineGreen     Plum
ProcessBlue     Purple
RawSienna     Red
RedOrange     RedViolet
Rhodamine     RoyalBlue
RoyalPurple     RubineRed
Salmon     SeaGreen
Sepia     SkyBlue
SpringGreen     Tan
TealBlue     Thistle
Turquoise     Violet
VioletRed     White
WildStrawberry     Yellow
YellowGreen     YellowOrange

## Defining new colors

If the predefined colors are not adequate, you may wish to define your own.

### Place

Define the colors in the preamble of your document. (Reason: do so in the preamble, so that you can already refer to them in the preamble, which is useful, for instance, in an argument of another package that supports colors as arguments, such as the listings package.)

### Method

In the abstract, the colors are defined following this scheme:

 \definecolor{''name''}{''model''}{''color-spec''}

where:

• name is the name of the color; you can call it as you like
• model is the way you describe the color, and is one of gray, rgb, RGB, HTML, and cmyk.
• color-spec is the description of the color

### Color Models

Among the models you can use to describe the color are the following (several more are described in the xcolor manual):

Color Models
Model Description Color Specification Example
gray Shades of gray
(0-1)
Just one number between 0 (black) and 1 (white), so 0.95 will be very light gray, 0.30 will be dark gray. \definecolor{light-gray}{gray}{0.95}
rgb Red, Green, Blue
(0-1)
Three numbers given in the form red,green,blue; the quantity of each color is represented with a number between 0 and 1. \definecolor{orange}{rgb}{1,0.5,0}
RGB Red, Green, Blue
(0-255)
Three numbers given in the form red,green,blue; the quantity of each color is represented with a number between 0 and 255. \definecolor{orange}{RGB}{255,127,0}
HTML Red, Green, Blue
(00-FF)
Six hexadecimal numbers given in the form RRGGBB; similar to what is used in HTML. \definecolor{orange}{HTML}{FF7F00}
cmyk Cyan, Magenta, Yellow, Black
(0-1)
Four numbers given in the form cyan,magenta,yellow,black; the quantity of each color is represented with a number between 0 and 1. \definecolor{orange}{cmyk}{0,0.5,1,0}

### Examples

To define a new color, follow the following example, which defines orange for you, by setting the red to the maximum, the green to one half (0.5), and the blue to the minimum:

 \definecolor{orange}{rgb}{1,0.5,0}

The following code should give a similar results to the last code chunk.

 \definecolor{orange}{RGB}{255,127,0}

If you loaded the xcolor package, you can define colors upon previously defined ones.

The first specifies 20 percent blue and 80 percent white; the second is a mixture of 20 percent blue and 80 percent black; and the last one is a mixture of (20*0.3) percent blue, ((100-20)*0.3) percent black and (100-30) percent green.

 \color{blue!20} \color{blue!20!black} \color{blue!20!black!30!green}

xcolor also feature a handy command to define colors from color mixes:

 \colorlet{notgreen}{blue!50!yellow}

### Using colour specifications directly

Normally one would predeclare all the colours as above, but sometimes it is convenient to directly use a colour without naming it first. To achieve this, \color and \textcolor have an alternative syntax specifying the model in square brackets, and the color specification in curly braces. For example:

 {\color[rgb]{1,0,0} This text will appear red-colored} \textcolor[rgb]{0,1,0}{This text will appear green-colored}

### Creating / Capturing colors

You may want to use colors that appear on another document, web pages, pictures, etc. Alternatively, you may want to play around with rgb values to create your own custom colors.

Image processing suites like the free GIMP suite for Linux/Windows/Mac offer colour picker facilities to capture any color on your screen or synthesize colors directly from their respective rgb / hsv / hexadecimal values.

Smaller, free utilities also exist:

# Fonts

Fonts are a complex topic. For common documents, only Font families, Emphasizing text, and Font encoding are really needed. The other sections are more useful to macro writers or for very specific needs.

## Introduction

The digital fonts have a long and intricate history. See Adobe Font Metrics for some more details.

Originally TeX was conceived to use its own font system, MetaFont, designed by D. Knuth. The default font family for TeX and friends is called Computer Modern. These high quality fonts are scalable, and have a wide range of typographical fine tuning capabilities.

Standard tex compilers will let you use other fonts. There are many different font types, such as PostScript Type1/Type3 fonts and bitmap fonts. Type1 are outline fonts (vector graphics) which are commonly used by pdftex. Bitmap fonts are raster graphics, and usually have very poor quality, which can easily be seen when zooming or printing a document. Type3 is a superset of Type1 and has more functionalities from Postscript, such as embedding raster graphics. In the TeX world, Type3 fonts are often used to embed bitmap fonts.

It should be noticed that fonts get generated the first time they are required, hence the long compilation time.

However, MetaFont is internally a quite complex font system, and the most popular font systems as of this day are Truetype font (ttf) and OpenType font (otf). With modern TeX compilers such as xetex and luatex it is possible to make use of such fonts in LaTeX documents. If you want/have to stick with the standard compilers, the aforementioned font types must first be converted and made available to LaTeX (e.g. converted to Type1 fonts). The external links section below has some useful resources.

In LaTeX, there are many ways to specify and control fonts. It is a very complex matter in typography.

## Font families

There are many font families e.g. Computer Modern, Times, Arial and Courier. Those families can be grouped into three main categories: roman (rm) or serif, sans serif (sf) and monospace (tt) (see Typeface for more details). Each font family comes with the default design which falls into one of those categories; however, it is interchangeable among them. Computer Modern Roman is the default font family for LaTeX. Fonts in each family also have different properties (size, shape, weight, etc.). Families are meant to be consistent, so it is highly discouraged to change fonts individually rather than the whole family.

The three families are defined by their respective variables:

• \rmdefault
• \sfdefault
• \ttdefault

The default family is contained in the \familydefault variable, and it is meant to have one of the three aforementioned variables as value. The default is defined like the following assignment:

 \renewcommand*{\familydefault}{\sfdefault}

This will turn all the part of the document using the default font to the default sans serif, which is Computer Modern Sans Serif if you did not change the default font.

Changing font families usually works in two steps:

1. First specify which family you want to change (rm, sf or tt).
2. Second specify the new default family if it is not rm.

Mathematical fonts is a more complex matter. Fonts may come with a package that will take care of defining all three families plus the math fonts. You can do it by yourself, in which case you do not have to load any package.

Below is an example[1] that demonstrates how to change a specific family.


The three default family font variables and the \familydefault variable should not be confused with their respective switch:

• \normalfont
• \rmfamily
• \sffamily
• \ttfamily

## Emphasizing text

In order to add some emphasis to a word or a phrase, the simplest way is to use the \emph{text} command, which usually italicizes the text. Italics may be specified explicitly with \textit{text}.

 I want to \emph{emphasize} a word.

Note that the \emph command is dynamic: if you emphasize a word which is already in an emphasized sentence, it will be reverted to the upright font.

 \emph{In this emphasized sentence, there is an emphasized \emph{word} which looks upright.} In this emphasized sentence, there is an emphasized word which looks upright.

Text may be emphasized more heavily through the use of boldface, particularly for keywords the reader may be trying to find when reading the text. As bold text is generally read before any other text in a paragraph or even on a page, it should be used sparingly. It may also be used in place of italics when using sans-serif typefaces to provide a greater contrast with unemphasized text. Bold text can be generated with the \textbf{text} command.

 \textbf{Bold text} may be used to heavily emphasize very important words or phrases. Bold text may be used to heavily emphasize very important words or phrases.

## Font encoding

A character is a sequence of bytes, and should not be confused with its representation, the glyph, which is what the reader sees. So the character 'a' has different representations following the used font, for example the upright version, the italic version, various weights and heights, and so on.

Upon compilation, tex will have to choose the right font glyph for every character. This is what is called font encoding. The default LaTeX font encoding is OT1, the encoding of the original Computer Modern TeX text fonts. It contains only 128 characters, many from ASCII, but leaving out some others and including a number that are not in ASCII. When accented characters are required, TeX creates them by combining a normal character with an accent. While the resulting output looks perfect, this approach has some caveats.

• It stops the automatic hyphenation from working inside words containing accented characters.
• Searches for words with accents in PDFs will fail.
• Extracting ('e.g.' copy paste) the umlaut 'Ä' via a PDF viewer actually extracts the two characters '"A'.
• Besides, some of Latin letters could not be created by combining a normal character with an accent, to say nothing about letters of non-Latin alphabets, such as Greek or Cyrillic.

To overcome these shortcomings, several 8-bit CM-like font sets were created. Extended Cork (EC) fonts in T1 encoding contains letters and punctuation characters for most of the European languages based on Latin script. The LH font set contains letters necessary to typeset documents in languages using Cyrillic script. Because of the large number of Cyrillic glyphs, they are arranged into four font encodings—T2A, T2B, T2C, and X2. The CB bundle contains fonts in LGR encoding for the composition of Greek text. By using these fonts you can improve/enable hyphenation in non-English documents. Another advantage of using new CM-like fonts is that they provide fonts of CM families in all weights, shapes, and optically scaled font sizes.

All this is not possible with OT1; that's why you may want to change the font encoding of your document.

Note that changing the font encoding will have some requirements over the fonts being used. The default Computer Modern font does not support T1. You will need Computer Modern Super (cm-super) or Latin Modern (lmodern), which are Computer Modern-like fonts with T1 support. If you have none of these, it is quite frequent (depends on your TeX installation) that tex chooses a Type3 font such as the Type3 EC, which is a bitmap font. Bitmap fonts look rather ugly when zoomed or printed.

The fontenc package tells LaTeX what font encoding to use. Font encoding is set with:

 \usepackage['encoding']{fontenc}

where encoding is the font encoding. It is possible to load several encodings simultaneously.

There is nothing to change in your document to use CM Super fonts (assuming they are installed), they will get loaded automatically if you use T1 encoding. For lmodern, you will need to load the package after the T1 encoding has been set:

 \usepackage[T1]{fontenc} \usepackage{lmodern}

The package ae (almost European) is obsolete. It provided some workarounds for hyphenation of words with special characters. These are not necessary any more with fonts like lmodern. Using the ae package leads to text encoding problems in PDF files generated via pdflatex (e.g. text extraction and searching), besides typographic issues.

## Font styles

Each family has its own font characteristics (such as italic and bold), also known as font styles, or font properties.

Font styles are usually implemented with different font files. So it is possible to build a new font family by specifying the font styles of different font families.

### Shapes

The following table lists the commands you will need to access the typical font shapes:

LaTeX command Equivalent to Output style Remarks
\textnormal{...} {\normalfont ...} document font family This is the default or normal font.
\emph{...} {\em ...} emphasis Typically italics. Using emph{} inside of italic text removes the italics on the emphasized text.
\textrm{...} {\rmfamily ...} roman font family
\textsf{...} {\sffamily ...} sans serif font family
\texttt{...} {\ttfamily ...} teletypefont family This is a fixed-width or monospace font.
\textup{...} {\upshape ...} upright shape The same as the normal typeface.
\textit{...} {\itshape ...} italic shape
\textsl{...} {\slshape ...} slanted shape A skewed version of the normal typeface (similar to, but slightly different from, italics).
\textsc{...} {\scshape ...} Small Capitals
\uppercase{...} uppercase (all caps) Also \lowercase. There are some caveats, though; see here.
\textbf{...} {\bfseries ...} bold
\textmd{...} {\mdseries ...} medium weight A font weight in between normal and bold.
\textlf{...} {\lfseries ...} light A font weight lighter than normal. Not supported by all typefaces.

The commands in column two are not entirely equivalent to the commands in column one: They do not correct spacing after the selected font style has ended. The commands in column one are therefore in general recommended.

You may have noticed the absence of underline. This is because underlining is not recommended for typographic reasons (it weighs the text down). You should use emph instead. However underlining text provides a useful extra form of emphasis during the editing process, for example to draw attention to changes. Although underlining is available via the \underline{...} command, text underlined in this way will not break properly. This functionality has to be added with the ulem (underline emphasis) package. Stick \usepackage{ulem} in your preamble. By default, this overrides the \emph command with the underline rather than the italic style. It is unlikely that you wish this to be the desired effect, so it is better to stop ulem taking over \emph and simply call the underline command as and when it is needed.

• To restore the usual \emph formatting, add \normalem straight after the document environment begins. Alternatively, use \usepackage[normalem]{ulem}.
• To underline, use \uline{...}.
• To add a wavy underline, use \uwave{...}.
• For a strike-out (strikethrough), use \sout{...}.
• For a slash through each individual character \xout{...}.

Some font styles are not compatible one with the other. But some extra packages will fill this hole. For bold small capitals, you might want to use:

 \usepackage{bold-extra} % ... \textsc{ \textbf{This is bold small capitals} }

### Sizing text

To apply different font sizes, simply follow the commands on this table:

These commands change the size within a given scope, so for instance {\Large some words} will change the size of only some words, and does not affect the font in the rest of the document. It will work for most parts of the text.

 {\Large\tableofcontents}

These commands cannot be used in math mode. However, part of a formula may be set in a different size by using an \mbox command containing the size command. The new size takes effect immediately after the size command; if an entire paragraph or unit is set in a certain size, the size command should include the blank line or the \end{...} which delimits the unit.

The default for \normalsize is 10 point (option 10pt), but it may differ for some Document Styles or their options. The actual size produced by these commands also depends on the Document Style and, in some styles, more than one of these size commands may produce the same actual size.

Note that the font size definitions are set by the document class. Depending on the document style the actual font size may differ from that listed above. And not every document class has unique sizes for all 10 size commands.

Absolute Point Sizes, [10pt] being default
size standard classes, proc AMS classes, memoir slides beamer
[10pt] [11pt] [12pt] [10pt] [11pt] [12pt] [10pt] [11pt] [12pt]
\tiny 6.80565 7.33325 7.33325 7.33325 7.97224 8.50012 17.27505 5.31258 6.37509 6.37509
\scriptsize 7.97224 8.50012 8.50012 7.97224 8.50012 9.24994 20.73755 7.43760 8.50012 8.50012
\footnotesize 8.50012 9.24994 10.00002 8.50012 9.24994 10.00002 20.73755 8.50012 9.24994 10.00002
\small 9.24994 10.00002 10.95003 9.24994 10.00002 10.95003 20.73755 9.24994 10.00002 10.95003
\normalsize 10.00002 10.95003 11.74988 10.00002 10.95003 11.74988 24.88382 10.00002 10.95003 11.74988
\large 11.74988 11.74988 14.09984 10.95003 11.74988 14.09984 29.86258 11.74988 11.74988 14.09984
\Large 14.09984 14.09984 15.84985 11.74988 14.09984 15.84985 35.82510 14.09984 14.09984 16.24988
\LARGE 15.84985 15.84985 19.02350 14.09984 15.84985 19.02350 43.00012 16.24988 16.24988 19.50362
\huge 19.02350 19.02350 22.82086 15.84985 19.02350 22.82086 51.60014 19.50362 19.50362 23.39682
\Huge 22.82086 22.82086 22.82086 19.02350 22.82086 22.82086 51.60014 23.39682 23.39682 23.39682

As a technical note, points in TeX follow the standard American point size in which 1 pt is approximately 0.35136 mm. The standard point size used in most modern computer programs (known as the desktop publishing point or PostScript point) has 1 pt equal to approximately 0.3527 mm while the standard European point size (known as the Didot point) had 1 pt equal to approximately 0.37597151 mm (see: point (typography)).

## Local font selection

You can change font for a specific part of the text. There are four font properties you can change.

\fontencoding
The font encoding, such as OT1 (TeX default) or T1 (extended characters support, better PDF support, widely used).
\fontfamily
The font family.
\fontseries
The series: l=light, m=medium, b=bold, bx=very bold.
\fontshape
The shape: it=italic, n=normal, sl=slanted, sc=small capitals.
 { \fontfamily{anttlc}\selectfont Some text in anttlc...}

The \selectfont command is mandatory, otherwise the font will not be changed. It is highly recommended to enclose the command in a group to cleanly return to the previous font selection when desired.

You can use all these commands in a row:

 { \fontencoding{T1}\fontfamily{anttlc}\fontseries{m}\fontshape{n}\selectfont Some text in anttlc...}

The default values are stored in \encodingdefault, \familydefault, \seriesdefault and \shapedefault. Setting back the default font properties can be done with

 \fontencoding{\encodingdefault} \fontfamily{\familydefault} \fontseries{\seriesdefault} \fontshape{\shapedefault} \selectfont

For short, you can use the \usefont{<encoding>}{<family>}{<series>}{<shape>} command.

 \usefont{T1}{cmr}{m}{n} % Computer Modern Roman (TeX default) in T1 encoding. May lead to bad text quality if you do not have cm-super installed. \usefont{T1}{phv}{m}{sc} % phv family (sans serif) medium small capitals. \usefont{T1}{ptm}{b}{it} % ptm family bold italic \usefont{U}{pzd}{m}{n}   % ...

## Arbitrary font size

The \tiny...\Huge commands are often enough for most contents. These are fixed sizes however. In most document processors, you can usually choose any size for any font. This is because the characters actually get magnified. If it usually looks correct for medium sizes, it will look odd at extreme sizes because of an unbalanced thickness. In TeX it is possible to change the magnification of anything, but highly discouraged for the aforementioned reason. Changing the font size is made by changing the font file. Yes, there is a file for every size: cmr10 for Computer Modern Roman 10pt, cmr12 for Computer Modern Roman 12pt, etc. This ensure the characters are correctly balanced and remain readable at all defined sizes.

You may choose a particular font size with the \fontsize{<size>}{<line space>} command. Example:

 {\fontsize{5cm}{1em}\selectfont This is big!}

If you are using the default Computer Modern font with OT1 encoding, you may get the following message:

LaTeX Font Warning: Font shape OT1/cmr/m/n' in size <142.26378> not available
(Font)              size <24.88> substituted on input line 103.

In that case you will notice that the font size cannot be changed beyond \tiny and \Huge. You must switch to a more sizable font, e.g.

 \usepackage[T1]{fontenc} \usepackage{lmodern}

## Finding fonts

You will find a huge font directory along examples and configurations at TUG Font Catalogue.

## Using arbitrary system fonts

If you use the XeTeX or LuaTeX engine and the fontspec package, you'll be able to use any font installed in the system effortlessly. XeTeX also allows using OpenType technology of modern fonts like specifying alternate glyphs and optical size variants. XeTeX also uses Unicode by default, which might be helpful for font issues.

To use the fonts, simply load the fontspec package and set the font:

 \documentclass{article} \usepackage{fontspec} \setmainfont{Arial} \begin{document} Lorem ipsum... \end{document}

Then compile the document with xelatex or lualatex. Note that you can only generate .pdf files, and that you need a sufficiently new TeX distribution (TeX Live 2009 should work for XeTeX and Tex Live 2010 for LuaTeX). Also you should not load the inputenc or fontenc package. Instead make sure that your document is encoded as UTF-8 and load fontspec, which will take care of the font encoding. To make your document support both pdflatex and xelatex/lualatex you can use the \ifxetex/ \ifluatex macro from the ifxetex/ ifluatex package. For example for xelatex

 \documentclass{article} \usepackage{ifxetex} \ifxetex   \usepackage{fontspec}   \defaultfontfeatures{Ligatures=TeX} % To support LaTeX quoting style   \setromanfont{Hoefler Text} \else   \usepackage[T1]{fontenc}   \usepackage[utf8]{inputenc} \fi \begin{document} Lorem ipsum... \end{document}

## PDF fonts and properties

PDF documents have the capability to embed font files. It makes them portable, hence the name Portable Document Format.

Many PDF viewers have a Properties feature to list embedded fonts and document metadata.

Many Unix systems make use of the poppler tool set which features pdfinfo to list PDF metadata, and pdffonts to list embedded fonts.

## References

1. found at the Google discussion group latexlovers

# List Structures

Convenient and predictable list formatting is one of the many advantages of using LaTeX. Users of WYSIWYG word processors can sometimes be frustrated by the software's attempts to determine when they intend lists to begin and end. As a mark-up language, LaTeX gives more control over the structure and content of lists.

## List structures

Lists often appear in documents, especially academic, as their purpose is often to present information in a clear and concise fashion. List structures in LaTeX are simply environments which essentially come in three flavors: itemize, enumerate and description.

All lists follow the basic format:

 \begin{list_type}   \item The first item   \item The second item   \item The third etc \ldots \end{list_type}

All three of these types of lists can have multiple paragraphs per item: just type the additional paragraphs in the normal way, with a blank line between each. So long as they are still contained within the enclosing environment, they will automatically be indented to follow underneath their item.

### Itemize

This environment is for your standard bulleted list of items.

 \begin{itemize}   \item The first item   \item The second item   \item The third etc \ldots \end{itemize}

### Enumerate

The enumerate environment is for ordered lists, where by default, each item is numbered sequentially.

 \begin{enumerate}   \item The first item   \item The second item   \item The third etc \ldots \end{enumerate}

### Description

The description environment is slightly different. You can specify the item label by passing it as an optional argument (although optional, it would look odd if you didn't include it!). Ideal for a series of definitions, such as a glossary.

 \begin{description}   \item[First] The first item   \item[Second] The second item   \item[Third] The third etc \ldots \end{description}

Sometimes you want a description where the text begins on a new line. This cannot easily be done with \\. The trick is to use \hfill[1].

 \begin{description}   \item[First] \hfill \\   The first item   \item[Second] \hfill \\   The second item   \item[Third] \hfill \\   The third etc \ldots \end{description}

## Nested lists

LaTeX will happily allow you to insert a list environment into an existing one (up to a depth of four—if you need more than four, use the easylist package). Simply begin the appropriate environment at the desired point within the current list. Latex will sort out the layout and any numbering for you.

 \begin{enumerate}   \item The first item   \begin{enumerate}     \item Nested item 1     \item Nested item 2   \end{enumerate}   \item The second item   \item The third etc \ldots \end{enumerate}

## Customizing lists

Customizing LaTeX is outside the beginners' domain. While not necessarily difficult in itself, because beginners are already overwhelmed with the array of commands and environments, moving on to more advanced topics runs the risk of confusion.

However, since the tutorial aims at being complete, we shall still include a brief guide on customizing lists. Feel free to skip!

Note that in the following when \renewcommand is used it must appear after the \begin{document} instruction so the changes made are taken into account. This is needed for both enumerated and itemized lists.

Also beware of the spaces in the label definitions. It is a common error!

### Line spacing

As you may have noticed, in standard LaTeX document classes, the vertical spacing between items, and above and below the lists as a whole, is more than between paragraphs: it may look odd if the descriptions are too short.

#### Using packages

If you want tightly-packed lists, use the mdwlist package (included in the mdwtools bundle), which provides compact, "starred" versions of the previous environments, i.e. itemize*, enumerate* and description*. They work exactly in the same way, but the output is more compact. Other packages providing compacted lists are paralist and enumitem.

Alternatively, use the memoir class and with \tightlists.

#### Customizing manually

Inside lists you can redefine some length/dimension variables of LaTeX, for example using:

 \begin{itemize} \itemsep1pt \parskip0pt \parsep0pt   \item first item   \item second item \end{itemize}

Alternatively, to create a unified look in your document you can redefine the enumerate environment:

 \let\oldenumerate\enumerate \renewcommand{\enumerate}{   \oldenumerate   \setlength{\itemsep}{1pt}   \setlength{\parskip}{0pt}   \setlength{\parsep}{0pt}}

Another approach is to redefine the \item command globally.

 \newlength{\wideitemsep} \setlength{\wideitemsep}{.5\itemsep} \addtolength{\wideitemsep}{-7pt} \let\olditem\item \renewcommand{\item}{\setlength{\itemsep}{\wideitemsep}\olditem}

### Customizing enumerated lists

#### Using packages

The thing people want to change most often with Enumerated lists are the counters. A quick solution to this problem is provided by the enumerate package of David Carlisle[2], or the more sophisticated package enumitem by Javier Bezos[3]. When using enumerate, it is possible to specify the style of the numbering: \begin{enumerate}[style].

The options A, a, I, i and 1 define the style and are self-explanatory, anything else is treated as text. To use any of the style tokens as text they can be enclosed in braces, e.g. {A} will give a literal A. [4]

Sometimes you may want to place some short text in front of the enumeration for example: "Exercise 1, Exercise 2, Execise 3, ...". This is possible with the enumitem package:

 \begin{enumerate}[label=\bfseries Exercise \arabic*:]   \item 5 + 7 = 12   \item 9 + 1 = 10   \item 2 * 2 = 4 \end{enumerate} Enumeration with text

\bfseries makes it bold, Exercise is the text and \arabic* inserts the counter followed by a colon (:) which is treated as text again.

#### Manually

To go any further and do it yourself instead, a brief introduction to LaTeX counters is required. You should check the dedicated chapter as we will not delve into the details for now.

There are four individual counters that are associated with itemized lists, each one represents the four possible levels of nesting, which are called:

 enumi enumii enumiii enumiv

The counter is incremented by \item before it is printed. For example to reset enumi use:

 \begin{enumerate}   \setcounter{enumi}{4}   \item fifth element \end{enumerate} 5. fifth element

The command responsible for formatting the various levels of nesting are

 \labelenumi \labelenumii \labelenumiii \labelenumiv

Example:


This simply redefines the appearance of the label, which is fine, providing that you do not intend to cross-reference to a specific item within the list, in which case the reference will be printed in the original format. This issue does not arise if you redefine the counter printer:


### Customizing itemized lists

Itemized lists are not as complex as they do not need to count. Therefore, to customize, you simply change the labels. It can be done manually for each entry with \item[new symbol], eg \item[$\star$].

The itemize labels are accessed via \labelitemi, \labelitemii, \labelitemiii, \labelitemiv, for the four respective levels.

 \renewcommand{\labelitemi}{\textgreater}

The above example would set the labels for the first level to a greater than (>) symbol. Of course, the text symbols available in Latex are not very exciting. Why not use one of the ZapfDingbat symbols, as described in the Symbols section. Or use a mathematical symbol:

 \renewcommand{\labelitemi}{$\star$}

Itemized list with tightly set items, that is with no vertical space between two consecutive items, can be created as follows.

 \begin{itemize}   \setlength{\itemsep}{0cm}%   \setlength{\parskip}{0cm}%   \item Item opening the list   \item Item tightly following \end{itemize}

## Inline lists

Inline lists can be achieved as follows.

### With package paralist

The paralist package provides the inparaenum environment (with an optional formatting specification in square brackets):

 \usepackage{paralist} % ... \begin{document} Inline lists, which are sequential in nature, just like enumerated lists, but are \begin{inparaenum}[\itshape a\upshape)] \item formatted within their paragraph; \item usually labelled with letters; and \item usually have the final item prefixed with and' or or', \end{inparaenum} like this example. ...

To change the styles of the counter, tokens A, a, I, i, and 1 can be used in the optional argument to produce the counter with one of the styles \Alph, \alph, \Roman, \roman and \arabic. For example: \begin{inparaenum}[(i)] produces the labels (i), (ii), (iii) ...

### With package enumitem

 \usepackage[inline]{enumitem} % ... \begin{document} Inline lists, which are sequential in nature, just like enumerated lists, but are \begin{enumerate*}[label=\itshape\alph*\upshape)] \item formatted within their paragraph; \item usually labelled with letters; and \item usually have the final item prefixed with and' or or', \end{enumerate*} like this example. ...

Package shortlst also provides inline lists.

## Easylist package

The easylist package [5] allows you to create list using a more convenient syntax and with infinite nested levels. It is also very customizable.

Load the package with the control character as optional argument:

 \usepackage[ampersand]{easylist}

The easylist environment will default to enumerations.

 \begin{easylist} & Main item~: && Sub item. && Another sub item. \end{easylist}

It features predefined styles which you can set as optional argument.

 \begin{easylist}[itemize] % ... \end{easylist}

Available styles:

• tractatus
• checklist - All items have empty check boxes next to them
• booktoc - Approximately the format used by the table of contents of the book class
• articletoc - Approximately the format used by the table of contents of the article class
• enumerate - The default
• itemize

You can customize lists with the \ListProperties(...) command and revert back the customization with \newlist{}. Yes, that's parentheses for \ListProperties parameters.

The Style parameter sets the style of counters and text, the Style* parameter sets the sytle of counters, and the Style** parameter sets the style of text. The parameter Numbers determines the way that the numbers are displayed and the possible values are r or R (for lower and upper case Roman numerals), l or L (for lower and upper case letters), a (for Arabic numbers, the default), and z (for Zapf's Dingbats).

The FinalMark parameter sets the punctuation of the final counter (Ex: FinalMark3={)}) while FinalSpace sets the amount of space between the item and the item's text. The Margin parameter sets the distance from the left margin (Ex: FinalSpace2=1cm). The Progressive parameter sets the distance from the left margin of all items in proportion to their level.

The {{{1}}} parameter prevents the first n counters from appearing in all levels. If there is a number after a parameter (Ex: Style3*) then this numbers indicates the level that it will affect (Ex: Style3=\color{red}).

Example of custom enumerate:

 \begin{easylist}[enumerate] \ListProperties(Style2*=,Numbers=a,Numbers1=R,FinalMark={)}) & Main item~: && Sub item. && Another sub item. \end{easylist}

Note that we put the FinalMark argument between {} to avoid LaTeX understanding it as the end of the properties list. Now we change the default properties to print a custom itemize:

 \usepackage{amssymb} \ListProperties(Hide=100, Hang=true, Progressive=3ex, Style*=-- , Style2*=$\bullet$ ,Style3*=$\circ$ ,Style4*=\tiny$\blacksquare$ ) % ... \begin{easylist} & Blah & Blah && Blah &&& Blah &&&& Blah &&&&& Blah \end{easylist} – Blah   $\bullet$ Blah    $\circ$ Blah     $\blacksquare$ Blah      – Blah

Spaces in Style parameters are important. The Style* parameter acts as a default value and easylist will use a medium dash for level 1, 5 and onward.

You can also define custom styles using LaTeX macros:


Important note: easylist has some drawbacks. First if you need to put an easylist inside an environment using the same control character as the one specified for easylist, you may get an error. To circumvent it, use the following commands provided by easylist:

 \Activate \begin{easylist} & ... \end{easylist} \Deactivate

Besides using easylist along with figures may cause some trouble to the layout and the indentation. LaTeX lists do not have this problem.

To use easylist with Beamer, each frame that uses easylist must be marked as fragile:

 \begin{frame}[fragile]     ...     \begin{easylist}[itemize]         ...     \end{easylist}     ... \end{frame}

## Notes and references

1. http://www.tex.ac.uk/cgi-bin/texfaq2html?label=noline
2. [1]The enumerate package, David Carlisle 1999
3. [2]The enumitem package, Javier Bezos 2011
4. CTAN documentation for enumerate
5. easylist documentation

# Special Characters

In this chapter we will tackle matters related to input encoding, typesetting diacritics and special characters.

In the following document, we will refer to special characters for all symbols other than A-Za-z0-9 and English punctuation marks.

This chapter is tightly linked with the font encoding issue. You should have a look at Fonts on the topic.

Some languages usually need a dedicated input system to ease document writing. This is the case for Arabic, Chinese, Japanese, Korean and others. This specific matter will be tackled in Internationalization.

The rules for producing characters with diacritical marks, such as accents, differ somewhat depending whether you are in text mode, math mode, or the tabbing environment.

## Input encoding

### A technical matter

Most of the modern computer systems allow you to input letters of national alphabets directly from the keyboard. If you tried to input these special characters in your LaTeX source file and compiled it, you may have noticed that they do not get printed at all.

A LaTeX source document is a plain text file. A computer stores data in a binary format, that is a sequence of bits (0 and 1). To display a plain text file, we need a code which tells which sequence of bits corresponds to which sequence of characters. This association is called input encoding, character encoding, or more informally charset.

For historical reasons, there are many different input encodings. There is an attempt to unify all the encoding with a specification that contains all existent symbols that are known from human history. This specification is Unicode. It only defines code points, which is a number for a symbol, but not the way symbols are reprensented in binary value. For that, unicode encodings are in charge. There are also several unicode encodings available, UTF-8 being one of them.

The ASCII encoding is an encoding which defines 128 characters on 7 bits. Its widespread use has led the vast majority of encodings to have backward compatibility with ASCII, by defining the first 128 characters the same way. The other characters are added using more bits (8 or more).

This is actually a big issue, since if you do not use the right encoding to display a file, it will show weird characters. What most programs try to do is guess statistically the encoding by analyzing the frequent sequences of bits. Sadly, it is not 100% safe. Some text editors may not bother guessing the encoding and will just use the OS default encoding. You should consider that other people might not be able to display directly your input files on their computer, because the default encoding for text file is different. It does not mean that the user cannot use another encoding, besides the default one, only that it has to be configured. For example, the German umlaut ä on OS/2 is encoded as 132, with Latin1 it is encoded as 228, while in Cyrillic encoding cp1251 this letter does not exist at all. Therefore you should consider encoding with care.

The following table shows the default encodings for some operating systems.

Operating system Default Encodings
Western Latin Cyrillic
Modern Unices (*BSD, Mac OS X, GNU/Linux) utf-8 utf-8
Mac (before OS X) applemac maccyr
Unix (Old) latin1 koi8-ru
Windows ansinew, cp1252 cp1251
DOS, OS/2 cp850 cp866nav

UTF-8 and Latin1 are not compatible. It means that if you try to open a Latin1-encoded file using a UTF-8 decoding, it will display odd symbols only if you used accents in it, since both encoding are ASCII superset they encode the classic letters the same way. There aren't many advantages in using Latin1 over UTF-8, which is technically superior. UTF-8 is also becoming the most widely used encoding (on the Web, in modern Unices, etc.).

### Dealing with LaTeX

TeX uses ASCII by default. But 128 characters is not enough to support non-english languages. TeX has its own way to do that with commands for every diacritical marking (see Escaped codes). But if we want accents and other special characters to appear directly in the source file, we have to tell TeX that we want to use a different encoding.

There are several encodings available to LaTeX:

• ASCII: the default. Only bare english characters are supported in the source file.
• ISO-8859-1 (a.k.a. Latin 1): 8-bits encoding. It supports most characters for latin languages, but that's it.
• UTF-8: a Unicode multi-byte encoding. Supports the complete Unicode specification.
• Others...

In the following we will assume you want to use UTF-8.

There are some important steps to specify encoding.

• Make sure your text editor decodes the file in UTF-8.
• Make sure it saves your file in UTF-8. Most text editors do not make the distinction, but some do, such as Notepad++.
• If you are working in a terminal, make sure it is set to support UTF-8 input and output. Some old Unix terminals may not support UTF-8. PuTTY is not set to use UTF-8 by default, you have to configure it.
• Tell LaTeX that the source file is UTF-8 encoded.
 \usepackage[utf8]{inputenc}

inputenc [2] package tells LaTeX what the text encoding format of your .tex files is.

The inputenc package allows as well the user to change the encoding within the document by means of the command \inputencoding{'encoding name'}.

 \usepackage[utf8]{inputenc} % ... % In this area % The UTF-8 encoding is specified. % ... \inputencoding{latin1} % ... % Here the text encoding is specified as ISO Latin-1. % ... \inputencoding{utf8} % Back to the UTF-8 encoding. % ...

### Extending the support

The LaTeX support of UTF-8 is fairly specific: it includes only a limited range of unicode input characters. It only defines those symbols that are known to be available with the current font encoding. You might encounter a situation where using UTF-8 might result in error:

! Package inputenc Error: Unicode char \u8:ũ not set up for use with LaTeX.

This is due to the utf8 definition not necessarily having a mapping of all the character glyphs you are able to enter on your keyboard. Such characters are for example

ŷ Ŷ ũ Ũ ẽ Ẽ ĩ Ĩ

In such case, you may try need to use the utf8x option to define more character combinations. utf8x is not officially supported, but can be viable in some cases. However it might break up compatibility with some packages like csquotes.

Another possiblity is to stick with utf8 and to define the characters yourself. This is easy:

 \DeclareUnicodeCharacter{'codepoint'}{'TeX sequence'}

where codepoint is the unicode codepoint of the desired character. TeX sequence is what to print when the character matching the codepoint is met. You may find codepoints on this site. Codepoints are easy to find on the web. Example:

 \DeclareUnicodeCharacter{0177}{\^y}

Now inputting 'ŷ' will effectively print 'ŷ'.

With XeTeX and LuaTeX the inputenc package is no longer needed. Both engines support UTF-8 directly and allow the use of TTF and OpenType fonts to support Unicode characters. See the Fonts section for more information.

## Escaped codes

In addition to direct UTF-8 input, LaTeX supports the composition of special characters. This is convenient if your keyboard lacks some desired accents and other diacritics.

The following accents may be placed on letters. Although 'o' letter is used in most of the examples, the accents may be placed on any letter. Accents may even be placed above a "missing" letter; for example, \~{} produces a tilde over a blank space.

The following commands may be used only in paragraph (default) or LR (left-right) mode.

LaTeX command Sample Description
\{o} ò grave accent
\'{o} ó acute accent
\^{o} ô circumflex
\"{o} ö umlaut, trema or dieresis
\H{o} ő long Hungarian umlaut (double acute)
\~{o} õ tilde
\c{c} ç cedilla
\k{a} ą ogonek
\l ł barred l (l with stroke)
\={o} ō macron accent (a bar over the letter)
\b{o} o bar under the letter
\.{o} ȯ dot over the letter
\d{u} dot under the letter
\r{a} å ring over the letter (for å there is also the special command \aa)
\u{o} ŏ breve over the letter
\v{s} š caron/háček ("v") over the letter
\t{oo} o͡o "tie" (inverted u) over the two letters
\o ø slashed o (o with stroke)

To place a diacritic on top of an i or a j, its dot has to be removed. The dotless version of these letters is accomplished by typing \i and \j. For example:

• \^\i should be used for i circumflex 'î';
• \"\i should be used for i umlaut 'ï'.

If a document is to be written completely in a language that requires particular diacritics several times, then using the right configuration allows those characters to be written directly in the document. For example, to achieve easier coding of umlauts, the babel package can be configured as \usepackage[german]{babel}. This provides the short hand "o for \"o. This is very useful if one needs to use some text accents in a label, since no backslash will be accepted otherwise.

More information regarding language configuration can be found in the Internationalization section.

## Less than < and greater than >

The two symbols '<' and '>' are actually ASCII characters, but you may have noticed that they will print '¡' and '¿' respectively. This is a font encoding issue. If you want them to print their real symbol, you will have to use another font encoding such as T1, loaded with the fontenc package. See Fonts for more details on font encoding.

Alternatively, they can be printed with dedicated commands:

 \textless \textgreater

## Euro € currency symbol

When writing about money these days, you need the euro sign. The textcomp package features a \texteuro command which gives you the euro symbol as supplied by your current text font. Depending on your chosen font this may be quite far from the official symbol.

An official version of the euro symbol is provided by eurosym. Load it in the preamble (optionally with the official option):

 \usepackage[official]{eurosym}

then you can insert it with the \euro{} command. Finally, if you want a euro symbol that matches with the current font style (e.g., bold, italics, etc.) you can use a different option:

 \usepackage[gen]{eurosym}

again you can insert the euro symbol with \euro{}.

Alternatively you can use the marvosym package which also provides the official euro symbol.

 \usepackage{marvosym} % ... \EUR{}

Now that you have succeeded in printing a euro sign, you may want the '€' on your keyboard to actually print the euro sign as above. There is a simple method to do that. You must make sure you are using UTF-8 encoding along with a working \euro{} or \EUR{}command.

 \DeclareUnicodeCharacter{20AC}{\euro{}} % or \DeclareUnicodeCharacter{20AC}{\EUR{}}

Complete example:

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

## Degree symbol for temperature and math

A common mistake is to use the \circ command. It will not print the correct character. Use the textcomp package instead, which provides a \textdegree command.

 \usepackage{textcomp} %... A $45\textdegree$ angle.

For temperature, you can use the same command or opt for the gensymb package and write

 \usepackage{gensymb} %... 17\degree~C or 17\celsius

Some keyboard layouts feature the degree symbol, you can use it directly if you are using UTF-8 and textcomp. For better results (font quality) we recommend the use of an appropriate font, like lmodern:

 \usepackage[utf8]{inputenc} \usepackage{lmodern} \usepackage{textcomp} % ... 17°~C

## Other symbols

LaTeX has lots of symbols at its disposal. The majority of them are within the mathematical domain, and later chapters will cover how to get access to them. For the more common text symbols, use the following commands:

Not mentioned in above table, tilde (~) is used in LaTeX code to produce non-breakable space. To get printed tilde sign, either write \~{} or \textasciitilde{}. And a visible space can be created with \textvisiblespace.

For some more interesting symbols, the Postscript ZipfDingbats font is available thanks to the pifont package. Add the declaration to your preamble: \usepackage{pifont}. Next, the command \ding{number}, will print the specified symbol. Here is a table of the available symbols:

.

## In special environments

### Math mode

Several of the above and some similar accents can also be produced in math mode. The following commands may be used only in math mode.

LaTeX command Sample Description Text-mode equivalence
\hat{o} $\hat{o}$ circumflex \^
\widehat{oo} $\widehat{oo}$ wide version of \hat over several letters
\check{o} $\check{o}$ vee or check \v
\tilde{o} $\tilde{o}$ tilde \~
\widetilde{oo} $\widetilde{oo}$ wide version of \tilde over several letters
\acute{o} $\acute{o}$ acute accent \'
\grave{o} $\grave{o}$ grave accent \
\dot{o} $\dot{o}$ dot over the letter \.
\ddot{o} $\ddot{o}$ two dots over the letter (umlaut in text-mode) \"
\breve{o} $\breve{o}$ breve \u
\bar{o} $\bar{o}$ macron \=
\vec{o} $\vec{o}$ vector (arrow) over the letter

When applying accents to letters i and j, you can use \imath and \jmath to keep the dots from interfering with the accents:

LaTeX command Sample Description Sample with upper dot
\hat{\imath} $\hat{\imath}$ circumflex on letter i without upper dot $\hat{i}$
\vec{\jmath} $\vec{\jmath}$ vector (arrow) on letter j without upper dot $\vec{j}$

### Tabbing environment

Some of the accent marks used in running text have other uses in the tabbing environment. In that case they can be created with the following command:

• \a' for an acute accent
• \a for a grave accent
• \a= for a macron accent

## Unicode keyboard input

Some operating systems provide a keyboard combination to input any Unicode code point, the so-called unicode compose key.

Many X applications (*BSD and GNU/Linux) support the Ctrl+Shift+u combination. A 'u' symbol should appear. Type the code point and press enter or space to actually print the character. Example:

<Ctrl+Shift+u> 20AC <space>

will print the euro character.

Desktop environments like GNOME and KDE may feature a customizable compose key for more memorizable sequences.

Xorg features advanced keyboard layouts with variants that let you enter a lot of characters easily with combination using the aprioriate modifier, like Alt Gr. It highly depends on the selected layout+variant, so we suggest you to play a bit with your keyboard, preceeding every key and dead key with the Alt Gr modifier.