text:
LaTeX/Paragraph Formatting

Altering the paragraph formatting is rarely necessary in academic writing. It is primarily used for formatting text in floats or for more exotic documents.

Paragraph alignment
Paragraphs in LaTeX are usually fully justified, i.e. flush with both the left and right margins. For whatever reason, should you wish to alter the justification of a paragraph, there are three environments at hand, and also LaTeX command equivalents.

All text between the and  of the specified environment will be justified appropriately. The commands listed are for use within other environments. For example, (paragraph) columns in.

However, if you really need to disable one of the above commands locally (for example because you have to use some broken package), you can use the command from package.

Paragraph indent
By default, the first paragraph after a heading follows the standard Anglo-American publishers' practice of no indentation. The size of subsequent paragraph indents is determined by a parameter called. The default length that this constant holds is set by the document class that you use. It is possible to override it by using the command. This will set paragraph indents to 1cm:

Whitespace in LaTeX can also be made flexible (what Lamport calls "rubber" lengths). This means that values such as extra vertical space inserted before a paragraph can have a default dimension plus an amount of expansion minus an amount of contraction. This is useful on pages in complex documents where not every page may be an exact number of fixed-height lines long, so some give-and-take in vertical space is useful. You specify this in a command like this:

If you want to indent a paragraph that is not indented, you can use

at the beginning of the paragraph. Obviously, this will only have an effect when is not set to zero. If you want to indent the beginning of every section, you can use the package: once loaded, the beginning of any chapter/section is indented by the usual paragraph indentation.

To create a non-indented paragraph, you can use

as the first command of the paragraph. This might come in handy when you start a document with body text and not with a sectioning command.

Be careful, however, if you decide to set the indent to zero, then it means you will need a vertical space between paragraphs in order to make them clear. The space between paragraphs is held in, which could be altered in a similar fashion as above. However, this parameter is used elsewhere too, such as in lists, which means you run the risk of making various parts of your document look very untidy by changing this setting. If you want to use the style of having no indentation with a space between paragraphs, use the package, which does this for you, while making adjustments to the spacing of lists and other structures which use paragraph spacing, so they don't get too far apart. If you want both indent and break, use

To indent subsequent lines of a paragraph, use the TeX command. (While the default behaviour is to apply the hanging indent after the first line, this may be changed with the command.)  An example follows.

The TeX commands and  add additional space to the left and right sides of each line, allowing the formatting for subsequent paragraphs to differ from the overall document margins. This space is in addition to the indentation added by and.

To change the indentation of the last line in a paragraph, use the TeX command.

Paragraph line break
Default style for may seem odd in the first place, as it writes the following text next to the title. If you do not like it, use a class other than the traditional article/book, or use ConTeXt or PlainTeX. Hacking of the class in use is really not the way LaTeX is intended to be used, and you may encounter a lot of frustrating issues.

Anyway, let's analyse the problem. If you add a manual line break with, LaTeX will complain that

There's no line here to end.

Simply adding an empty space will do it:

Alternatively, you can use the shorter, yet not completely equivalent syntax:

You can also change (an empty inline mathematical expression) for   or  in the above makeshift.

Line spacing
To change line spacing in the whole document use the command covered in Text Formatting.

Alternatively, you can use the package, which is also covered in Text Formatting. This package provides the commands, , and , which will specify the line spacing for all sections and paragraphs until another command is used. Furthermore, the package provides the following environments in order to change line spacing within the document but not document-wide:
 * : lines are double spaced;
 * : line spacing set to one-and-half spacing;
 * : normal line spacing;
 * : customizable line spacing, e.g..

See the section on customizing lists for information on how to change the line spacing in lists.

Manual breaks
LaTeX takes care of formatting, breaks included. You should avoid manual breaking as much as possible, for it could lead to very bad formatting.

Controlling the breaks should be reserved to macro and package writers. Here follows a quick reference.

 * If you use these comments to put a break in a section heading, the line will also be broken in the table of contents. To avoid such a division, you can use the command, which is described in sectioning commands.

The page breaks are covered in Page Layout. More details on manual spaces between paragraphs (such as ) can be found in Lengths.

Verbatim text
There are several ways to introduce text that won't be interpreted by the compiler. If you use the environment, everything input between the begin and end commands are processed as if by a typewriter. All spaces and new lines are reproduced as given, and the text is displayed in an appropriate fixed-width font. Any LaTeX command will be ignored and handled as plain text. This is ideal for typesetting program source code. Here is an example:

Note: once in the environment, the only command that will be recognized is. Any others will be output. The font size in the verbatim environment can be adjusted by placing a font size command before. If this is a problem, you can use the package instead, providing an environment with the same name:

Remember to add to your preamble to use it though! Within the environment, you can use the command  to get back the normal font. To write equations within the enviroment, you can use  and  to enclose them, instead of the usual.

When using inside the  enviroment, note that the standard font has no bold TT font. Txtfonts has bold fonts: just add after.

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

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

will print, ignoring the effect should have on text.

For more control over formatting, however, you can try the package, which provides a  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   environment. It can also be used in conjunction with the package and it can add reference line numbers (useful for chunks of data or programming), and it can even include entire external files.

To use verbatim in beamer, the frame needs to be made fragile:.

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

will show this URL exactly as typed (similar to the command), but the  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 midway through an unpunctuated word, only at slashes and full stops. Bear in mind, however, that spaces are forbidden in URLs, so using spaces in arguments will fail, as will using other non-URL-valid characters.

When using this command through the package, the URL is "clickable" in the PDF document, whereas it is not linked to the web when using only the  package. Also when using the package, to remove the border placed around a URL, insert  inside the. (Alternately 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:

See also Hyperlinks

Listing environment
This is also an extension of the verbatim environment provided by the package. The extra functionality it provides is that it can add line numbers alongside the text. The command is. The mandatory first line argument is for specifying which line the numbering should start at. 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 to the document preamble.

Multiline comments
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 package, to be loaded in the preamble as usual:

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

Note that this won’t work inside complex environments, like math for example. You may be wondering, why should I load a package called 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 command, by adding the following to the document's preamble:

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

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

Then if you supply only one argument to, 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).

Skipping parts of the source
A more robust way of making the TeX engine skip some part of the source is to use the TeX -conditional. The typical use is

The -conditional is always false.

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:
 * for a short quotation, or a series of small quotes, separated by blank lines.
 * for a short quotation, or a series of small quotes, separated by blank lines.

 * for use with longer quotations, of more than one paragraph, because it indents the first line of each paragraph.
 * for use with longer quotations, of more than one paragraph, because it indents the first line of each paragraph.

 * 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.
 * 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.

title: LaTeX/Paragraph Formatting


text:
LaTeX/Page Layout

LaTeX and the document class will normally take care of page layout issues for you. For submission to an academic publication, this entire topic will be out of your hands, as the publishers want to control the presentation. However, for your own documents, there are some obvious settings that you may wish to change: margins, page orientation and columns, to name but three. The purpose of this tutorial is to show you how to configure your pages.

We will often have to deal with TeX lengths in this chapter. You should have a look at Lengths for comprehensive details on the topic.

Two-sided documents
Documents can be either one- or two-sided. Articles are by default one-sided, books are two-sided. Two-sided documents differentiate the left (even) and right (odd) pages, whereas one-sided do not. The most notable effect can be seen in page margins. If you want to make the article class two-sided, use.

Many commands and variables in LaTeX take this concept into account. They are referred to as even and odd. For one-sided document, only the odd commands and variables will be in effect.

Page dimensions
A page in LaTeX is defined by many internal parameters. Each parameter corresponds to the length of an element of the page, for example, is the physical height of the page. Here you can see a diagram showing all the variables defining the page. All sizes are given in TeX points (pt), there are 72.27pt in an inch or 1pt ≈ 0.3515mm.

 * 1) one inch +
 * 2) one inch +
 * 3)  = 31pt
 * 4)  = 20pt
 * 5)  = 12pt
 * 6)  = 25pt
 * 7)  = 592pt
 * 8)  = 390pt
 * 9)  = 10pt
 * 10)  = 35pt
 * 11)  = 30pt
 * = 7pt (not shown)
 * = 0pt
 * = 0pt
 * = 597pt
 * = 845pt

The current details plus the layout shape can be printed from a LaTeX document itself. Use the layout package and the command of the same name: To render a frame marking the margins of a document you are currently working on, add  to the document.

Page size
It will not have been immediately obvious - because it doesn't really cause any serious problems - that the default page size for all standard document classes is US letter. This is shorter by 18 mm (about 3/4 inch), and slightly wider by 8 mm (about 1/4 inch), compared to A4 (which is the standard in almost all the rest of the world). While this is not a serious issue (most printers will print the document without any problems), it is possible to specify alternative sizes as class option. For A4 format:

More size options with geometry
One of the most versatile packages for page layout is the package. The immediate advantage of this package is that it lets you customize the page size even with classes that do not support the options. For instance, to set the page size, add the following to your preamble:

The package has many pre-defined page sizes, like, built in. Others include:

To explicitly change the paper dimensions using the package, the  and  options can be used. For example:

Package provides many flexibility on setting the page layout, including specifying specific layout of each page using the: While very flexible, this package also comes with limitations. For instance, page size cannot be provided to individual pages, which requires different approaches for the workaround.

Page size issues
If you intend to get a PDF in the end, there are basically three ways: pdflatex myfile              # TeX → PDF latex myfile                 # TeX → DVI dvipdf myfile                # DVI → PDF latex myfile                 # TeX → DVI dvips myfile -o myfile.ps    # DVI → PS ps2pdf myfile.ps myfile.pdf   # PS  → PDF
 * TeX → PDF
 * TeX → DVI → PDF
 * TeX → DVI → PS → PDF

Sadly the PDF output page size may not be completely respectful of your settings. Some of these tools do not have the same interpretation of the DVI, PS and PDF specifications, and you may end up with a PDF which has not exactly the right size. Thankfully there is a solution to that: the command lets the user pass PostScript or PDF parameters, which can be used here to set the page size appropriately.

 * For pdflatex to work fine, using the package usually works.
 * For the DVI and PS ways, the safest way to always get the right paper size in the end is to add

to the tex file, and to append the appropriate parameters to the processors used during output generation: dvips -t a4 ... ps2pdf -sPAPERSIZE=a4 ... # On Windows: ps2pdf -sPAPERSIZE#a4 ...

If you want US Letter instead, replace by  and  by. Also replace a4 by letter in command-line parameters.

Page size for tablets
Those who want to read on tablets or other handheld digital devices need to create documents without the extra whitespace. In order to create PDF documents with optimal handheld viewing, not only must the text field and margins be adjusted, so must the page size. If you are looking for a sensible dimension, consider following the paper size used by the Supreme Court of the United States, 441pt by 666pt (or 6.125 inches by 9.25 inches), which looks great on tablets. You could also use the Supreme Court's text field size of 297 pt by 513 pt, but this is too wide for fonts other than Century Schoolbook, the font required by the Supreme Court.

Margins
Readers used to perusing typical physical literature are probably wondering why there is so much white space surrounding the text. For example, on A4 paper a document will typically have 44 mm margin widths on the left and right of the page, leaving about 60% of the page width for text. The reason is improved readability. Studies have shown that it's easier to read text when there are 60–70 characters per line—and it would seem that 66 is the optimal number. Therefore, the page margins are set to ensure optimal readability, and excessive margin white space is tolerated as a consequence. Sometimes, this white space is left in the inner margin with the assumption that the document will be bound.

If you wish to avoid excessive white space, rather than changing the margins, consider instead using a two-column (or more) layout. This approach is the one usually taken by print magazines because it provides both readable line lengths and good use of the page. Another option for reducing the amount of whitespace on the page without changing the margins is to increase the font size using the option to the document class.

If you wish to change the margins of your document, there are many ways to do so:

 * One older approach is to use the package for somewhat standardized smaller margins (around an inch), but it creates lines of more than 100 characters per line with the 10pt default font size (and about 90 if the  documentclass option is used):

For even narrower margins, the package has a  option (around 1.5cm), which results in about 120 characters per line at the 10pt default font size, about double what is considered readable:

 * A more modern and flexible approach is to use the package.  This package allows you to specify the 4 margins without needing to remember the particular page dimensions commands.  You can enter the measures in centimeters and inches as well. Use  for centimeters and  for inches after each value (e.g. 1.0in or 2.54cm). Note that by default (i.e. without any options) this package already reduces the margins, so for a 'standard layout' you may not need to specify anything. These values are relative to the edge of paper (0in) and go inward. For example, this command provides more conventional margins, better using the vertical space of the page, without creating the dramatically long lines of the  package (if the  documentclass option is used, the line lengths are about 88 characters for letter-sized paper and slightly less when using ).

It can also recreate the behavior of the package using

You can combine the margin options with the page size options seen in this paragraph.

 * If the page size is A4, you can use the package. The  option further narrows the margins.

 * You should not use the package for a page with A4 document size with smaller margins. It is obsolete and buggy. Use geometry package instead like this:

 * Edit individual page dimension variables described above, using the and  commands. See the Lengths chapter. For instance,

Odd and even margins
Using the geometry package, the options left and right are used for the inside and outside margins respectively. They also have aliases inner and outer. Thus, the easiest way to handle different margins for odd and even pages is to give the twoside option in the document class command and specify the margins as usually.

This will result in a value of 4cm on all inner margins (left margin for odd number pages and right margin for even pages) and 2cm margin on outer margins.

Setting the same value for the inner and outer for geometry will remove the difference between the margins. Another quick way to eliminate the difference in position between even and odd numbered pages would be setting the values to evensidemargin and oddsidemargin to the half of odd's default:

By default, the value of evensidemargin is larger than oddsidemargin in the two-sided layout, as one could wish to write notes on the side of the page. The side for the large margin is chosen opposite to the side where pages are joined together.

See the Lengths.

Top margin above Chapter
The top margin above a chapter can be changed using the package. Example:

The command must be used when the spacing of a chapter is changed. In case of a section this command can be omitted.

Page orientation
When you talk about changing page orientation, it usually means changing to landscape mode, since portrait is the default. We shall introduce two slightly different styles of changing orientation.

Change orientation of the whole document
The first is for when you want all of your document to be in landscape from the very beginning. There are various packages available to achieve this, but the one we prefer is the package. All you need to do is call the package, with landscape as an option:

Although, if you intend to use to set your paper size, don't add the  commands twice, simply string all the options together, separating with a comma:

Using standard LaTeX classes, you can use the same class options:

Change orientation of specific part
The second method is for when you are writing a document in portrait, but you have some contents, like a large diagram or table that would be displayed better on a landscape page. However, you still want the consistency of your headers and footers appearing the same place as the other pages.

The package is for this very purpose. It supplies a environment, and anything inside is basically rotated. No actual page dimensions are changed. This approach is more applicable to books or reports than to typical academic publications. Using instead of  when generating a PDF document will make the page appear right side up when viewed: the single page that is in landscape format will be rotated, while the rest will be left in portrait orientation.

Also, to get a table to appear correctly centered on a landscaped page, one must place the environment inside a  environment, which is itself inside the  environment. For instance it should look like this:

For books (and in general documents using the twoside option), the landscape-environment unfortunately does not pay attention to the different layout of even and odd pages. The macro can be fixed using a few lines of extra code in the preamble.

Change orientation of floating environment
If you use the above code, you will see that the table is inserted where it is in the code. It will not be floated! To fix this you need the package. See the Rotations chapter.

Margins, page size and rotation of a specific page
If you need to rotate the page so that the figure fits, the chances are good that you need to scale the margins and the font size too. Again, the package comes in handy for specifying new margins for a single page only.

Note that order matters!

Page background
There are many ways on implementing background for a page. Below is most common packages used:
 * package will let you print content in the background of every page or individual pages.

The starred-version of the command applies to the current page only.

 * package let users include watermarks and pictures in the background.

{{LaTeX/Usage|code= \usepackage{background}

\backgroundsetup{ opacity = 0.5, angle = 0, contents = {\includegraphics{example.pdf} }

}}

Using the twocolumn optional class argument
Using a standard Latex document class, like article, you can simply pass the optional argument twocolumn to the document class: which will give the desired effect.

While this approach is useful, it has limitations. The package provides the following advantages:

 * Can support up to ten columns.
 * Implements a multicols environment, therefore, it is possible to mix the number of columns within a document.
 * Additionally, the environment can be nested inside other environments, such as.
 * outputs balanced columns, whereby the columns on the final page will be of roughly equal length.
 * Use multicols* environment for unbalanced columns, whereby each column is completely filled before starting with the next column.
 * Vertical rules between columns can be customised.
 * Column environments can be easily customised locally or globally.

Using package
The package overcomes some of the shortcomings of twocolumn and provides the  environment. To create a typical two-column layout:

Floats are not fully supported by this environment. It can only cope if you use the starred forms of the float commands (e.g., ) which makes the float span all columns. This is not hugely problematic, since floats of the same width as a column may be too small, and you would probably want to span them anyway. See this section for a more detailed discussion.

The package has two important parameters which can be set using :

 * , sets the width of the vertical rule between columns and defaults to 0pt
 * , sets the horizontal space between columns and the defaults to 10pt, which is quite narrow

To force a break in a column, the command is used.

Manual page formatting
There may be instances, especially in very long documents, such as books, that LaTeX will not get all page breaks looking as good as it could. It may, therefore, be necessary to manually tweak the page formatting. Of course, you should only do this at the very final stage of producing your document, once all the content is complete. LaTeX offers the following:

Widows and orphans
In professional books, it's not desirable to have single lines at the beginning or end of a page. In typesetting such situations are called 'widows' and 'orphans'. Normally it is possible that widows and orphans appear in LaTeX documents. You can try to deal with them using manual page formatting, but there's also an automatic solution.

LaTeX has a parameter for 'penalty' for widows and orphans ('club lines' in LaTeX terminology). With the greater penalty LaTeX will try more to avoid widows and orphans. You can try to increase these penalties by putting following commands in your document preamble:

If this does not help, you can try increasing these values even more, to a maximum of 10000. However, it is not recommended to set this value too high, as setting it to 10000 forbids LaTeX from doing this altogether, which might result in strange behavior.

It also helps to have rubber band values for the space between paragraphs:

Alternatively, you can use the needspace package to reserve some lines and thus to prevent page breaking for those lines.

Troubleshooting / Debugging
A very useful troubleshooting and designing technique is to turn on the showframe option in the geometry package (which has the same effect as the showframe package described above). It draws bounding boxes around the major page elements, which can be helpful because the boundaries of various regions are usually invisible, and complicated by padding whitespace.

Examining log of the tex could be helpful as well - it should provide many useful information. In addition, following packages can help on visual debugging layout:

Which will print layout and frames. The statements could be on top of the source file and uncommented when required.

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

title: LaTeX/Page Layout


text:
Cookbook:Baked Custard

Ingredients

 * 4 eggs
 * ½ cup (120 g) white granulated sugar
 * ¼ teaspoon salt
 * 1 teaspoon vanilla extract
 * 1 quart (946 ml) milk
 * butter or shortening

Procedure

 * 1) Beat the eggs, the sugar, the salt, and the vanilla together.
 * 2) Scald the milk and add it very slowly, stirring constantly (see tempering).
 * 3) Pour the mixture into a greased or buttered baking dish or several small greased heat-proof molds.
 * 4) Place the baking dish or the molds in a pan of water in a slow oven (300–325°F / 150–160°C) and bake for between 30 and 40 minutes.
 * 5) Test if the custard is cooked with a knife, which will come out clean when the custard is thoroughly baked.

Notes, tips, and variations

 * For caramel custard, add 4 tablespoons of caramel sauce to the eggs.

 * A meringue, or frosting for the top, requires about a tablespoonful of fine sugar to the beaten white of one egg; to be placed on the top after the custard or pudding is baked, smoothed over with a broad-bladed knife dipped in cold water, and replaced in the oven to brown slightly.

 * Applesauce or quince preserves can be placed in the bottom of the dish before baking. When set, add some more quince or apple sauce (heated) on the top with some chopped almonds and serve hot. When starting with fresh fruit, stew it (optionally, with sugar to taste), flavoring with the rind of a half lemon, and pass it through a sieve, or use a food processor. The resulting puree can be decorated with some thin lemon peel cut into stars.

title: Cookbook:Baked Custard


text:
LaTeX/Mathematics

One of the greatest motivating forces for Donald Knuth when he began developing the original TeX system was to create something that allowed simple construction of mathematical formulae, while looking professional when printed. The fact that he succeeded was most probably why TeX (and later on, LaTeX) became so popular within the scientific community. Typesetting mathematics is one of LaTeX's greatest strengths. It is also a large topic due to the existence of so much mathematical notation.

If your document requires only a few simple mathematical formulas, plain LaTeX has most of the tools that you will ever need. If you are writing a scientific document that contains numerous complex formulas, the package introduces several new commands that are more powerful and flexible than the ones provided by basic LaTeX. The package fixes some  quirks and adds some useful settings, symbols, and environments to amsmath. To use either package, include: or in the preamble of the document. The package loads the  package and hence there is no need to   in the preamble if  is used.

Mathematics environments
LaTeX needs to know when the text is mathematical. This is because LaTeX typesets math notation differently from normal text. Therefore, special environments have been declared for this purpose. They can be distinguished into two categories depending on how they are presented:

 * text — text formulas are displayed inline, that is, within the body of text where it is declared, for example, I can say that $$a+a=2a$$ within this sentence.
 * displayed — displayed formulas are on a line by themselves.

As math requires special environments, there are naturally the appropriate environment names you can use in the standard way. Unlike most other environments, however, there are some handy shorthands for declaring your formulas. The following table summarizes them:

Suggestion: Using the should be avoided, as it may cause problems, particularly with the AMS-LaTeX macros. Furthermore, should a problem occur, the error messages may not be helpful.

The and  environments are functionally equivalent.

If you are typing text normally, you are said to be in text mode, but while you are typing within one of those mathematical environments, you are said to be in math mode, that has some differences compared to the text mode:
 * 1) Most spaces and line breaks do not have any significance, as all spaces are either derived logically from the mathematical expressions or have to be specified with special commands such as
 * 2) Empty lines are not allowed. Only one paragraph per formula.
 * 3) Each letter is considered to be the name of a variable and will be typeset as such. If you want to typeset normal text within a formula (normal upright font with normal spacing), then you have to enter the text using dedicated commands.

Inserting "Displayed" maths inside blocks of text
In order for some operators, such as or, to be displayed correctly inside some math environments (read ), it might be convenient to write the  class inside the environment. Doing so might cause the line to be taller, but will cause exponents and indices to be displayed correctly for some math operators. For example, the will print a smaller Σ and  will print a bigger one $$\displaystyle \sum$$, like in equations. It is possible to force this behaviour for all math environments by declaring in the preamble (i.e. before ).

Symbols
Mathematics has many symbols! The following is a set of symbols that can be accessed directly from the keyboard: + - = ! / [ ] < > | ' : *

Beyond those listed above, distinct commands must be issued in order to display the desired symbols. There are many examples such as Greek letters, set and relations symbols, arrows, binary operators, etc.

For example:

Fortunately, there's a tool that can greatly simplify the search for the command for a specific symbol. Look for "Detexify" in the external links section below. Another option would be to look in "The Comprehensive LaTeX Symbol List" in the external links section below.

Greek letters
Greek letters are commonly used in mathematics, and they are very easy to type in math mode. You just have to type the name of the letter after a backslash: if the first letter is lowercase, you will get a lowercase Greek letter, if the first letter is uppercase (and only the first letter), then you will get an uppercase letter. Note that some uppercase Greek letters look like Latin ones, so they are not provided by LaTeX (e.g. uppercase Alpha and Beta are just "A" and "B", respectively). Lowercase epsilon, theta, kappa, phi, pi, rho, and sigma are provided in two different versions. The alternate, or variant, version is created by adding "var" before the name of the letter:

Scroll down to for a complete list of Greek symbols.

Operators
An operator is a function that is written as a word: e.g. trigonometric functions (sin, cos, tan), logarithms and exponentials (log, exp), limits (lim), as well as trace and determinant (tr, det). LaTeX has many of these defined as commands:

For certain operators such as limits, the subscript is placed underneath the operator:

For the modular operator there are two commands: and :

To use operators that are not pre-defined, such as argmax, see custom operators

Powers and indices
Powers and indices are equivalent to superscripts and subscripts in normal text mode. The caret (also known as the circumflex accent) character is used to raise something, and the underscore is for lowering. If an expression containing more than one character is raised or lowered, it should be grouped using curly braces ( and  ).

For powers with more than one digit, surround the power with {}.

An underscore can be used with a vertical bar ($$ | $$) to denote evaluation using subscript notation in mathematics:

Fractions and Binomials
A fraction is created using the command (for those who need their memories refreshed, that's the top and bottom respectively!). Likewise, the binomial coefficient (a.k.a, the Choose function) may be written using the command:

You can embed fractions within fractions:

Note that when appearing inside another fraction, or in inline text $$\tfrac{a}{b}$$, a fraction is noticeably smaller than in displayed mathematics. The and  commands force the use of the respective styles,  and. Similarly, the and  commands typeset the binomial coefficient.

For relatively simple fractions, especially within the text, it may be more aesthetically pleasing to use powers and indices instead:

If this looks a little "loose" (i.e., overspaced), a tightened version can be defined by inserting some negative space

If you use them throughout the document, usage of package is recommended. This package provides command to create slanted fractions. Usage:

If fractions are used as an exponent, curly braces have to be used around the command:

$x^\frac{1}{2}$ % no error $x^\sfrac{1}{2}$ % error $x^{\sfrac{1}{2}}$ % no error

In some cases, using the package alone will result in errors about certain font shapes not being available. In that case, the and  packages need to be added as well.

Alternatively, the package provides the  command, whose usage is similar to.

Continued fractions
Continued fractions should be written using command:

Multiplication of two numbers
To make multiplication visually similar to a fraction, a nested array can be used. For example, multiplication of numbers written one below the other can be typeset as follows:

Roots
The command creates a square root surrounding an expression. It accepts an optional argument specified in square brackets ( and  ) to change magnitude:

Some people prefer writing the square root "closing" it over its content. This method arguably makes it more clear what is in the scope of the root sign. This habit is not normally used while writing with the computer, but if you still want to change the output of the square root, LaTeX gives you this possibility. Just add the following code in the preamble of your document:

This TeX code first renames the command as, then redefines  in terms of the old one, adding something more. The new square root can be seen in the picture on the left, compared to the old one on the right. Unfortunately this code won't work if you want to use multiple roots: if you try to write $$\sqrt[b]{a}$$ as after you used the code above, you'll just get a wrong output. In other words, you can redefine the square root this way only if you are not going to use multiple roots in the whole document.

An alternative piece of TeX code that does allow multiple roots is

However, this requires the package.

Sums and integrals
The and  commands insert the sum and integral symbols respectively, with limits specified using the caret  and underscore. The typical notation for sums is:

or

The limits for the integrals follow the same notation. It's also important to represent the integration variables with an upright d, which in math mode is obtained through the \mathrm{} command, and with a small space separating it from the integrand, which is attained with the \, command.

There are many other "big" commands which operate in a similar manner:

For more integral symbols, including those not included by default in the Computer Modern font, try the package.

The command allows the use of  to write the limits over multiple lines:

If you want the limits of an integral to be specified above and below the symbol (like the sum), use the command:

However, if you want this to apply to all integrals, it is preferable to specify the option when loading the  package:

Subscripts and superscripts in other contexts, as well as other parameters to package related to them, are described in Advanced Mathematics chapter.

For bigger integrals, you may use personal declarations, or the package.

Brackets, braces and delimiters
How to use braces in multi line equations is described in the Advanced Mathematics chapter.

The use of delimiters such as brackets soon becomes important when dealing with anything but the most trivial equations. Without them, formulas can become ambiguous. Also, special types of mathematical structures, such as matrices, typically rely on delimiters to enclose them.

There are a variety of delimiters available for use in LaTeX:

where and  may be used in place of [ and ].

Automatic sizing
Very often, mathematical features will differ in size, in which case the delimiters surrounding the expression should vary accordingly. This can be done automatically using the, , and commands. Any of the previous delimiters may be used in combination with these:

Curly braces are defined differently by using {{LaTeX/LaTeX|code=\left\{}} and {{LaTeX/LaTeX|code=\right\} }},

If a delimiter on only one side of an expression is required, then an invisible delimiter on the other side may be denoted using a period.

Manual sizing
In certain cases, the sizing produced by the and  commands may not be desirable, or you may simply want finer control over the delimiter sizes. In this case, the, , and  modifier commands may be used:

These commands are primarily useful when dealing with nested delimiters. For example, when typesetting

we notice that the and  commands produce the same size delimiters as those nested within it. This can be difficult to read. To fix this, we write

Manual sizing can also be useful when an equation is too large, trails off the end of the page, and must be separated into two lines using an align command. Although the commands and  can be used to balance the delimiters on each line, this may lead to wrong delimiter sizes. Furthermore, manual sizing can be used to avoid overly large delimiters — if an or a similar command appears between the delimiters.

Matrices and arrays
A basic matrix may be created using the environment: in common with other table-like structures, entries are specified by row, with columns separated using an ampersand  and new rows separated with a double backslash

To specify alignment of columns in the table, use starred version:

The alignment by default is, but it can be any column type valid in environment.

However matrices are usually enclosed in delimiters of some kind, and while it is possible to use the  and   commands, there are various other predefined environments which automatically include delimiters:

When writing down arbitrary sized matrices, it is common to use horizontal, vertical and diagonal triplets of dots (known as ellipses) to fill in certain columns and rows. These can be specified using the, and  respectively:

In some cases, you may want to have finer control of the alignment within each column, or to insert lines between columns or rows. This can be achieved using the environment, which is essentially a math-mode version of the   environment, which requires that the columns be pre-specified:

You may see that the AMS matrix class of environments doesn't leave enough space when used together with fractions resulting in output similar to this:

$$ M = \begin{bmatrix} \frac{5}{6} & \frac{1}{6} & 0\\ \frac{5}{6} & 0          & \frac{1}{6}\\ 0          & \frac{5}{6} & \frac{1}{6} \end{bmatrix} $$

To counteract this problem, add additional leading space with the optional parameter to the command:

If you need "border" or "indexes" on your matrix, plain TeX provides the macro

Matrices in running text
To insert a small matrix without increasing leading in the line containing it, use environment:

Adding text to equations
The math environment differs from the text environment in the representation of text. Here is an example of trying to represent text within the math environment:

There are two noticeable problems: there are no spaces between words or numbers, and the letters are italicized and more spaced out than normal. Both issues are simply artifacts of the maths mode, in that it treats it as a mathematical expression: spaces are ignored (LaTeX spaces mathematics according to its own rules), and each character is a separate element (so are not positioned as closely as normal text).

There are a number of ways that text can be added properly. The typical way is to wrap the text with the command (a similar command is, though this causes problems with subscripts, and has a less descriptive name). Let's see what happens when the above equation code is adapted:

The text looks better. However, there are no gaps between the numbers and the words. Unfortunately, you are required to explicitly add these. There are many ways to add spaces between math elements, but for the sake of simplicity we may simply insert space characters into the commands.

Formatted text
Using the is fine and gets the basic result. Yet, there is an alternative that offers a little more flexibility. You may recall the introduction of font formatting commands, such as, , , etc. These commands format the argument accordingly, e.g., gives bold text. These commands are equally valid within a maths environment to include text. The added benefit here is that you can have better control over the font formatting, rather than the standard text achieved with.

Formatting mathematics symbols

 * See also: Mathematical Alphanumeric Symbols, w:Help:Displaying a formula and w:Wikipedia:LaTeX symbols

We can now format text; what about formatting mathematical expressions? There are a set of formatting commands very similar to the font formatting ones just used, except that they are specifically aimed at text in math mode (requires )

These formatting commands can be wrapped around the entire equation, and not just on the textual elements: they only format letters, numbers, and uppercase Greek, and other math commands are unaffected.

To bold lowercase Greek or other symbols use the command; this will only work if there exists a bold version of the symbol in the current font. As a last resort there is the command (poor man's bold): this prints multiple versions of the character slightly offset against each other.

To change the size of the fonts in math mode, see Changing font size.

Accents
So what to do when you run out of symbols and fonts? Well, the next step is to use accents:

Color
The package, described in Colors, allows us to add color to our equations. For example,

The only problem is that this disrupts the default formatting around the  operator. To fix this, we enclose it in a environment, since  is a binary operator. This process is described here.

Plus and minus signs
LaTeX deals with the + and − signs in two possible ways. The most common is as a binary operator. When two maths elements appear on either side of the sign, it is assumed to be a binary operator, and as such, allocates some space to either side of the sign. The alternative way is a sign designation. This is when you state whether a mathematical quantity is either positive or negative. This is common for the latter, as in math, such elements are assumed to be positive unless a − is prefixed to it. In this instance, you want the sign to appear close to the appropriate element to show their association. If you put a + or a − with nothing before it but you want it to be handled like a binary operator you can add an invisible character before the operator using. This can be useful if you are writing multiple-line formulas, and a new line could start with a − or +, for example, then you can fix some strange alignments adding the invisible character where necessary.

A plus-minus sign is written as:

Similarly, there exists also a minus-plus sign:

Controlling horizontal spacing
LaTeX is obviously pretty good at typesetting maths—it was one of the chief aims of the core TeX system that LaTeX extends. However, it can't always be relied upon to accurately interpret formulas in the way you did. It has to make certain assumptions when there are ambiguous expressions. The result tends to be slightly incorrect horizontal spacing. In these events, the output is still satisfactory, yet any perfectionists will no doubt wish to fine-tune their formulas to ensure spacing is correct. These are generally very subtle adjustments.

There are other occasions where LaTeX has done its job correctly, but you just want to add some space, maybe to add a comment of some kind. For example, in the following equation, it is preferable to ensure there is a decent amount of space between the maths and the text.

This code produces errors with Miktex 2.9 and does not yield the results seen on the right. Use \mathrm instead of just \text.

(Note that this particular example can be expressed in more elegant code by the construct provided by the  package described in Advanced Mathematics chapter.)

LaTeX has defined two commands that can be used anywhere in documents (not just maths) to insert some horizontal space. They are and

A is a space equal to the current font size. So, if you are using an 11pt font, then the space provided by will also be 11pt (horizontally, of course.) The  gives twice that amount. As you can see from the code from the above example, s were used to add some separation between the maths and the text.

OK, so back to the fine tuning as mentioned at the beginning of the document. A good example would be displaying the simple equation for the indefinite integral of y with respect to x:

$$\int y\, \mathrm{d}x$$

If you were to try this, you may write:

However, this doesn't give the correct result. LaTeX doesn't respect the white-space left in the code to signify that the y and the dx are independent entities. Instead, it lumps them altogether. A would clearly be overkill in this situation—what is needed are some small spaces to be utilized in this type of instance, and that's what LaTeX provides:

NB you can use more than one command in a sequence to achieve a greater space if necessary.

So, to rectify the current problem:

The negative space may seem like an odd thing to use, however, it wouldn't be there if it didn't have some use! Take the following example:

The matrix-like expression for representing binomial coefficients is too padded. There is too much space between the brackets and the actual contents within. This can easily be corrected by adding a few negative spaces after the left bracket and before the right bracket.

In any case, adding some spaces manually should be avoided whenever possible: it makes the source code more complex and it's against the basic principles of a What You See is What You Mean approach. The best thing to do is to define some commands using all the spaces you want and then, when you use your command, you don't have to add any other space. Later, if you change your mind about the length of the horizontal space, you can easily change it modifying only the command you defined before. Let us use an example: you want the d of a dx in an integral to be in roman font and a small space away from the rest. If you want to type an integral like, you can define a command like this:

in the preamble of your document. We have chosen just because it reminds the "d" it replaces and it is fast to type. Doing so, the code for your integral becomes. Now, whenever you write an integral, you just have to use the instead of the "d", and all your integrals will have the same style. If you change your mind, you just have to change the definition in the preamble, and all your integrals will be changed accordingly.

Manually Specifying Formula Style
To manually display a fragment of a formula using text style, surround the fragment with curly braces and prefix the fragment with. The braces are required because the macro changes the state of the renderer, rendering all subsequent mathematics in text style. The braces limit this change of state to just the fragment enclosed within. For example, to use text style for just the summation symbol in a sum, one would enter

The same thing as a command would look like this:

Note the extra braces. Just one set around the expression won't be enough. That would cause all math after to be displayed using text style.

To display part of a formula using display style, do the same thing, but use instead.

Advanced Mathematics: AMS Math package
The AMS (American Mathematical Society) mathematics package is a powerful package that creates a higher layer of abstraction over mathematical LaTeX language; if you use it it will make your life easier. Some commands introduces will make other plain LaTeX commands obsolete: in order to keep consistency in the final output you'd better use  commands whenever possible. If you do so, you will get an elegant output without worrying about alignment and other details, keeping your source code readable. If you want to use it, you have to add this in the preamble:

Introducing dots in formulas
defines also the command, that is a generalization of the existing. You can use in both text and math mode and LaTeX will replace it with three dots "…" but it will decide according to the context whether to put it on the bottom (like ) or centered (like ).

Dots
LaTeX gives you several commands to insert dots (ellipses) in your formulae. This can be particularly useful if you have to type big matrices omitting elements. First of all, here are the main dots-related commands LaTeX provides:

Instead of using and, you should use the semantically oriented commands. It makes it possible to adapt your document to different conventions on the fly, in case (for example) you have to submit it to a publisher who insists on following house tradition in this respect. The default treatment for the various kinds follows American Mathematical Society conventions.

Write an equation with the align environment
How to write an equation with the align environment with the package is described in Advanced Mathematics.

List of mathematical symbols
All the pre-defined mathematical symbols from the \TeX\ package are listed below. More symbols are available from extra packages.

Note: To use the Greek Letters in LaTeX that have the same appearance in the Latin alphabet, just use Latin: e.g., A instead of Alpha, B instead of Beta, etc.

Not predefined in LATEX 2. Use one of the packages latexsym, amsfonts, amssymb, txfonts, pxfonts, or wasysym

If LaTeX does not include a command for the mathematical operator you want to use, for example  ( c osine plus i times s ine), add to your preamble: \DeclareMathOperator\cis{cis}

You can then use  in the document just like   or any other mathematical operator.

Summary
As you begin to see, typesetting math can be tricky at times. However, because LaTeX provides so much control, you can get professional quality mathematics typesetting with relatively little effort (once you've had a bit of practice, of course!). It is possible to elaborate further on the nitty-gritty of mathematics because the possibilities seem endless. However, with this tutorial, you should be able to get along with it sufficiently.

title: LaTeX/Mathematics


text:
Cookbook talk:Baked Custard

Parts of this module were adapted from The Whitehouse Cookbook, by Mrs. F.L. Gillette; The New Dr. Price Cookbook, written anonymously; and The Belgian Cookbook, by various authors.

Is this recipe incomplete?
68.81.195.10 (talk) 11:16, 25 December 2010 (UTC) To what temperature should the oven being used be adjusted, to guarantee the doneness of the baked custard after the thirty to forty minutes allotted for its baking?

title: Cookbook talk:Baked Custard


text:
LaTeX/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
When using LaTeX, you write a plain text file which describes the document's structure and presentation. LaTeX converts this source text, combined with markup, into a typeset document. For the purpose of analogy, web pages work in a similar way: HTML is used to describe the document, which is then rendered into on-screen output - with different colours, fonts, sizes, etc. - by your browser.

You can create an input file for LaTeX with any text editor. A minimal example looks something like the following (the commands will be explained later):

Spaces
LaTeX normalises spaces in its input files so that whitespace characters, such as a space or a 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. More line breaks (empty lines) define 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).

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.

 * 1) $ % ^ & _ { } ~ \

As you will see, these characters can be used in your documents all the same by adding a prefix backslash:

In some circumstances, the square bracket characters can also be considered as reserved characters, as they are used to give optional parameters to some commands. If you want to print these directly after some command, like in this situation:

it will fail, as [text] will be considered as an option given to. You can achieve the correct output this way: .

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

The commands and  produce respectively a tilde and  a hat which is placed over the next letter. For example gives ñ. That's why you need braces to specify there is no letter as argument. You can also use and  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 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 as in mathematical formulae or as accents. We will tackle this issue in Special Characters.

LaTeX groups
Sometimes a certain state should be kept local, in other words its scope should be limited. This can be done by enclosing the part to be changed locally in curly braces. In certain occasions, using braces won't be possible. LaTeX provides and  to begin and end a group, respectively.

Environments form an implicit group.

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:

Between the and the  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:
 * 1) They start with a backslash  and then have a name consisting of letters only.
 * 2) * Command names are terminated by a space, a number or any other non-letter.
 * 3) They consist of a backslash  and exactly one non-letter.
 * 4) * Command names are terminated after that 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:

Many LaTeX formatting commands come in pairs.

 * 1) An argument form command, where one of the arguments is the text to be formatted.
 * 2) A scope form command, where the formatting will be applied to all text after the command until the end of the current scope. That is, until the end of the current group or environment. This form may also be called a switch command. A scope form command might still have arguments, but the text to be formatted is not an argument. This form should almost never be called outside of any scope, otherwise it will apply on the rest of the document.

An argument form command will have one argument more than its corresponding scope form command, the extra argument being the text the command affects.

Examples:

Emphasing text: is an argument form command with one argument, the text to be emphasised. is the corresponding scope form command with no arguments.

Coloring text: This example requires you to. is an argument form command with two arguments, the color and the text to be colored. is the corresponding scope form command with only one argument, the color.

Comments
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.

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 multiline 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.

When picking a name for your file, make sure it bears a .tex extension.
 * Save your file as hello.tex.

What does it all mean?
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, provided there is no white space before the percent sign.

Building a document
We then feed our input file into a LaTeX engine, a program which generates our final document.

There are several LaTeX engines in modern use: lualatex, xelatex, and <tt>pdflatex</tt>. There are important differences between the three, but we'll discuss those elsewhere - any of them will work for building our first document.

Generating the document
LaTeX itself does not have a GUI, though some LaTeX installations feature a graphical front-end where you can click LaTeX into compiling your input file. Assuming you're not using one of those:

 * 1) Open a terminal and navigate to the directory containing your <tt>.tex</tt> file.
 * 2) Type the command:   (The <tt>.tex</tt> extension is not required, although you can include it if you wish.)
 * 3) 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). Transcript written on hello.log.

This means that your source file has been processed and the resulting document is called <tt>hello.pdf</tt>. You can view it with any PDF viewer installed on your system.

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. This will be discussed in the future when it comes up.

Autobuild Systems
Compiling can be quite tricky as soon as you start working on more complex documents. A number of programs exist to automatically read in a LaTeX document and run the appropriate compilers the appropriate number of times. For example, <tt>latexmk</tt> can generate a PDF from most LaTeX files simply: $ latexmk -pdf file.tex Note that most editors will take care of it for you.

Historical versions of LaTeX
Both LaTeX and TeX were created many years before the Portable Document Format (PDF) existed, so the plain LaTeX engine, <tt>latex</tt>, emits DVI, a format designed by Donald Knuth for device-independent TeX output. This format has fallen out of general use, but can be converted into more common output formats using programs from your LaTeX distribution:
 * <tt>dvips</tt> converts <tt>.dvi</tt> files to <tt>.ps</tt> (PostScript).
 * <tt>dvipdf</tt> converts <tt>.dvi</tt> files to <tt>.pdf</tt> (<tt>dvipdfm</tt> is an improved version).

You might also find Ghostscript, a set of free and open-source tools for working with PostScript, useful. Its <tt>ps2pdf</tt> converts <tt>.ps</tt> files to <tt>.pdf</tt>, and <tt>pdf2ps</tt> does the reverse.

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 <tt>latex</tt> for a DVI output, or only <tt>pdflatex</tt> for a PDF output, converting to PostScript only when it is necessary to print the document.

Note that using <tt>latex</tt> to generate DVI output keeps you from using PDF-only features, such as hyperlinks and embedded fonts.

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

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 <tt>a-z</tt>, the digits <tt>0-9</tt>, the hyphen (<tt>-</tt>), and only one full point or period (<tt>.</tt>) 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 <tt>filename.toc</tt>.

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:

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.

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/.

LaTeX/Основе

title: LaTeX/Basics