LaTeX/Basics

De LaTeX
Aller à : navigation, rechercher

Un exemple de base

\documentclass{article}

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

avec des mathématiques

\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)

LaTeX online pour une copie dans PowerPoint

Il est possible d'envoyer une expression mathématique à un serveur LaTeX et de recopier l'image produite dans un autre logiciel :

http://www.forkosh.dreamhost.com/mimetex.cgi?x=\frac{1-t^2}{1+t^2}

ou encore

http://math.spip.org/tex.php?x=\frac{1-t^2}{1+t^2} }

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.


Previous: Basics Index Next: Structured document and document structure