LaTeX/Basics : Différence entre versions

De LaTeX
Aller à : navigation, rechercher
Ligne 38 : Ligne 38 :
 
An empty line starts a new paragraph.
 
An empty line starts a new paragraph.
 
}}
 
}}
 +
===Special 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:
 +
{{LaTeX/Usage|code=
 +
\# \$ \% \textasciicircum{} \& \_ \{ \} \~{} \textbackslash{}
 +
}}
 +
 +
The other symbols and many more can be printed with special commands in mathematical formulae or as accents.
 +
 +
The backslash character {{LaTeX/LaTeX|code=\}} can ''not'' be entered by adding another backslash in front of it ({{LaTeX/LaTeX|code=\\}}); this sequence is used for line breaking. For introducing a backslash in math mode, you can use {{LaTeX/LaTeX|code=\backslash}} instead.
 +
 +
The command {{LaTeX/LaTeX|code=\~}} produces a tilde which is placed over the next letter. For example {{LaTeX/LaTeX|code=\~n}} gives ñ. To produce just the character ~, use {{LaTeX/LaTeX|code=\~{}<!---->}}  which places a ~ over an empty box. 
 +
 +
Similarly, the command {{LaTeX/LaTeX|code=\^}} produces a hat over the next character, for example {{LaTeX/LaTeX|code=\^{o}<!---->}} produces ô. If you need in text to display the ^ symbol you have to use {{LaTeX/LaTeX|code=\textasciicircum}}.
 +
 +
If you want to insert text that might contain several particular symbols (such as URIs), you can consider using the {{LaTeX/LaTeX|code=\verb}} command, that will be discussed later in the section on [[LaTeX/Formatting|formatting]].
 +
 +
===LaTeX Commands===
 +
LaTeX commands are case sensitive, and take one of the following two formats:
 +
* They start with a backslash {{LaTeX/LaTeX|code=\}} 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 {{LaTeX/LaTeX|code=\}} and exactly one non-letter.
 +
 +
Some commands need an argument, which has to be given between curly braces {{LaTeX/LaTeX|code={ }<!---->}} after the command name. Some commands support optional parameters, which are added after the command name in square brackets {{LaTeX/LaTeX|code=[ ]}}. The general syntax is:
 +
{{LaTeX/Usage|code=
 +
\commandname[option1,option2,...]{argument1}{argument2}...
 +
}}
 +
 +
===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:
 +
{{LaTeX/Usage|code=
 +
\begin{environmentname}
 +
text to be influenced
 +
\end{environmentname}
 +
}}
 +
 +
Between the {{LaTeX/LaTeX|code=\begin}} and the {{LaTeX/LaTeX|code=\end}} you can put other commands and nested environments. 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.
 +
 +
===Comments===
 +
When LaTeX encounters a {{LaTeX/LaTeX|code=%}} 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.
 +
{{LaTeX/Example|code=This is an % stupid
 +
% Better: instructive <----
 +
example: Supercal%
 +
            ifragilist%
 +
icexpialidocious
 +
|render= This is an example: Supercalifragilisticexpialidocious
 +
}}
 +
 +
Note that the {{LaTeX/LaTeX|code=%}} character can be used to split long input lines that do not allow whitespace or line breaks, as with Supercali...cious above.
 +
 +
The core LaTeX language does not have a predefined syntax for commenting out regions spanning multiple lines. Refer to [[LaTeX/Formatting#Multi-line_comments|multi-line comments]] for simple workarounds.
 +
 +
===Input File Structure===
 +
When LaTeX processes an input file, it expects it to follow a certain structure. Thus every input file must start with the command
 +
{{LaTeX/Usage|code=
 +
\documentclass{...}
 +
}}
 +
 +
This specifies what sort of document you intend to write. After that, you can include commands that influence the style of the whole document, or
 +
you can load packages that add new features to the LaTeX system. To load such a package you use the command
 +
{{LaTeX/Usage|code=
 +
\usepackage{...}
 +
}}
 +
 +
When all the setup work is done, you start the body of the text with the command
 +
{{LaTeX/Usage|code=
 +
\begin{document}
 +
}}
 +
 +
Now you enter the text mixed with some useful LaTeX commands. At the end of the document you add the
 +
{{LaTeX/Usage|code=
 +
\end{document}
 +
}}
 +
 +
command, which tells LaTeX to call it a day. Anything that follows this command will be ignored by LaTeX. The area between {{LaTeX/LaTeX|code=\documentclass}} and {{LaTeX/LaTeX|code=\begin{document}<!---->}} is called the ''preamble''.

Version du 14 avril 2011 à 12:29

\documentclass{article}

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

\begin{document}
  Voici la fonction $\sin x$,
  la fonction \[\cos x=\sum_{k=0}^{\infty}\frac{(-1)^k}{(2k)!}x^{2k}\]
  et la fonction $\tan (x)$\ldots
\end{document}

va donner le résultat suivant :

Voici la fonction \sin, la fonction

\cos x=\sum_{k=0}^{\infty}\frac{(-1)^k}{(2k)!}x^{2k}

et la fonction tangente \tan (x)


Spaces

"Whitespace" characters, such as blank or tab, are treated uniformly as "space" by LaTeX. Several consecutive whitespace characters are treated as one "space". Whitespace at the start of a line is generally ignored, and a single line break is treated as “whitespace.” An empty line between two lines of text defines the end of a paragraph. Several empty lines are treated the same as one empty line. The text below is an example. On the left hand side is the text from the input file, and on the right hand side is the formatted output.

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.

Special 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:

\# \$ \% \textasciicircum{} \& \_ \{ \} \~{} \textbackslash{}

The other symbols and many more can be printed with special commands in mathematical formulae or as accents.

The backslash character \ can not 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 command \~ produces a tilde which is placed over the next letter. For example \~n gives ñ. To produce just the character ~, use \~{} which places a ~ over an empty box.

Similarly, the command \^ produces a hat over the next character, for example \^{o} produces ô. If you need in text to display the ^ symbol you have to use \textasciicircum.

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

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

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

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.

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 Supercali...cious 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.

Input File Structure

When LaTeX processes an input file, it expects it to follow a certain structure. Thus every input file must start with the command

\documentclass{...}

This specifies what sort of document you intend to write. After that, you can include commands that influence the style of the whole document, or you can load packages that add new features to the LaTeX system. To load such a package you use the command

\usepackage{...}

When all the setup work is done, you start the body of the text with the command

\begin{document}

Now you enter the text mixed with some useful LaTeX commands. At the end of the document you add the

\end{document}

command, which tells LaTeX to call it a day. Anything that follows this command will be ignored by LaTeX. The area between \documentclass and \begin{document} is called the preamble.