LaTeX/Basics : Différence entre versions
(Math Online) |
m (→Example with mathematics) |
||
| (16 révisions intermédiaires par le même utilisateur non affichées) | |||
| Ligne 1 : | Ligne 1 : | ||
| − | === | + | <noinclude>{{LaTeX/Top}}</noinclude> |
| + | === Hello World basic example === | ||
{{LaTeX/Usage|code= | {{LaTeX/Usage|code= | ||
| Ligne 9 : | Ligne 10 : | ||
}} | }} | ||
| − | === | + | === Example with mathematics === |
<source lang="latex"> | <source lang="latex"> | ||
\begin{document} | \begin{document} | ||
| − | + | The cosinus function, $\cos x$, can be defined by the power series | |
| − | + | \[\cos x=\sum_{k=0}^{\infty}\frac{(-1)^k}{(2k)!}x^{2k}\] | |
| − | + | as well as $\sin x$, $\tan x$ etc. | |
\end{document} | \end{document} | ||
</source> | </source> | ||
| − | + | will be displayed: | |
{{début cadre|bleu}} | {{début cadre|bleu}} | ||
| − | + | The cosinus function, <math>\cos x</math>, can be defined by the power series<BR> | |
<CENTER><math>\cos x=\sum_{k=0}^{\infty}\frac{(-1)^k}{(2k)!}x^{2k}</math></CENTER><BR> | <CENTER><math>\cos x=\sum_{k=0}^{\infty}\frac{(-1)^k}{(2k)!}x^{2k}</math></CENTER><BR> | ||
| − | + | as well as <math>\sin x</math>, <math>\tan x</math> etc. | |
{{fin cadre}} | {{fin cadre}} | ||
| + | |||
| + | Another example, using the <tt>amsmath</tt> package from the American mathematical association: | ||
| + | <source lang="latex"> | ||
| + | \documentclass{article} | ||
| + | \usepackage{amsmath} | ||
| + | \begin{document} | ||
| + | The cosinus function, $\cos x$, can be defined by the power series | ||
| + | \begin{align} | ||
| + | 1 &=\int_\alpha^\beta e^{-\rho x} \phi(x) dx\\ | ||
| + | &= \int_\alpha^\beta e^{-\rho x}f(x)l(x) dx \\ | ||
| + | l(x)&= \exp(-\int_0^x \mu(u)) du \\ | ||
| + | l(x)&= e^{-\int_0^x \mu(u)} du | ||
| + | \end{align} | ||
| + | |||
| + | \[ | ||
| + | \cos x=\sum_{k=0}^{\infty}\frac{(-1)^k}{(2k)!}x^{2k} | ||
| + | \] | ||
| + | as well as $\sin x$, $\tan x$ etc. | ||
| + | \end{document} | ||
| + | \end{document} | ||
| + | </source> | ||
===LaTeX online pour une copie dans PowerPoint=== | ===LaTeX online pour une copie dans PowerPoint=== | ||
| Ligne 33 : | Ligne 55 : | ||
ou encore | ou encore | ||
<source lang="latex"> | <source lang="latex"> | ||
| − | http://math.spip.org/tex.php?x=\frac{1-t^2}{1+t^2 | + | http://math.spip.org/tex.php?x=\frac{1-t^2}{1+t^2} |
</source> | </source> | ||
| + | L'image de la formule apparaît alors dans votre navigateur et il suffit d'un clic droit pour enregistrer l'image qui est sous un format <tt>.png</tt> ou de le copier en mémoire puis de le coller dans une application. | ||
===Spaces=== | ===Spaces=== | ||
| Ligne 110 : | Ligne 133 : | ||
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. | 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. | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | = Multilingual LaTeX with XeTeX= | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | TeX and LaTeX did not evolve as quick as other softwares regarding multilingualism. Only XeTeX and LuaTeX are able to typeset various languages such as: | |
| − | {{ | + | |
| + | <source lang="latex"> | ||
| + | % | ||
| + | % These lines tells gnu-emacs to typeset with the xetex engine | ||
| + | % which requires Unicode encoding only (utf-8) | ||
| + | %%% Local Variables: | ||
| + | %%% TeX-engine: xetex | ||
| + | %%% coding: utf-8 | ||
| + | %%% End: | ||
| + | |||
| + | % These lines tell TeXworks to typeset with xelatex, and to open and | ||
| + | % save the source with Unicode encoding. | ||
| + | % !TEX program = xelatex | ||
| + | % !TEX encoding = UTF-8 Unicode | ||
| + | %\documentclass{memoir} | ||
| + | %\documentclass[AER,reviewmode]{AEA} % Production modes are draftmode, reviewmode and finalmode | ||
| + | %\documentclass[11pt,a4paper]{amsart} | ||
| + | \documentclass[11pt,a4paper]{article} | ||
| + | \usepackage{mathptmx} % This if you want Times Roman fonts. | ||
| + | \usepackage{xltxtra} % for xetex engine (includes fonstpec) | ||
| + | |||
| + | %\setmainfont[Mapping=tex-text]{Linux Libertine O} % Only if you them on your system | ||
\begin{document} | \begin{document} | ||
| − | + | \section{Unicode support} | |
| − | + | \subsection{English} | |
| − | {{ | + | All human beings are born free and equal in dignity and rights. |
| + | |||
| + | \subsection{Íslenska} | ||
| + | Hver maður er borinn frjáls og jafn öðrum að virðingu og réttindum. | ||
| + | |||
| + | \subsection{Русский} | ||
| + | Все люди рождаются свободными и равными в своем достоинстве и | ||
| + | правах. | ||
| + | |||
| + | \subsection{Tiếng Việt} | ||
| + | Tất cả mọi người sinh ra đều được tự do và bình đẳng về nhân phẩm và | ||
| + | quyền lợi. | ||
| + | |||
| + | \subsection{Ελληνικά} | ||
| + | Ὅλοι οἱ ἄνθρωποι γεννιοῦνται ἐλεύθεροι καὶ ἴσοι στὴν ἀξιοπρέπεια | ||
| + | καὶ τὰ δικαιώματα. | ||
| + | |||
| + | \section{Legacy syntax} | ||
| + | When he goes---``Hello World!''\\ | ||
| + | She replies—“Hello dear!” | ||
| + | |||
| + | \section{Ligatures} | ||
| + | %\fontspec[Ligatures={Common, Historical}]{Linux Libertine O Italic} | ||
| + | \fontsize{12pt}{18pt}\selectfont Questo è strano assai! | ||
| + | |||
| + | \section{Numerals} | ||
| + | %\fontspec[Numbers={OldStyle}]{Linux Libertine O}Old style: 1234567\\ | ||
| + | %\fontspec[Numbers={Lining}]{Linux Libertine O}Lining: 1234567 | ||
| + | |||
\end{document} | \end{document} | ||
| − | + | </source> | |
| + | |||
| + | * If some fonts do not come out, see http://mirror.ibcp.fr/pub/CTAN/macros/latex/contrib/fontspec/fontspec.pdf | ||
| + | as well as the package polyglossia http://www.tex.ac.uk/ctan/macros/xetex/latex/polyglossia/polyglossia.pdf which is a replacement of the Babel package for XeTeX. | ||
| + | |||
| + | * Libertine Linux fonts. In order to verify that the OpenType font is on your disk, you can use the <tt>otfinfo</tt> program. Here is an example with the command line (first locating any file having a 'libertine' name on your disk and using the --info option for a specific file : | ||
| + | <source lang=bash> | ||
| + | $ locate .otf | grep libertine | ||
| + | /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbb.otf | ||
| + | /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbbo.otf | ||
| + | /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbk.otf | ||
| + | /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbo.otf | ||
| + | /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbob.otf | ||
| + | /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxboi.otf | ||
| + | /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbr.otf | ||
| + | /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbri.otf | ||
| + | /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbro.otf | ||
| + | /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbs.otf | ||
| + | /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbsb.otf | ||
| + | /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbsi.otf | ||
| + | /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxlb.otf | ||
| + | /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxlbi.otf | ||
| + | /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxlbo.otf | ||
| + | /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxlr.otf | ||
| + | /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxlri.otf | ||
| + | /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxlro.otf | ||
| + | |||
| + | $ otfinfo --info /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbbo.otf | ||
| + | Family: Linux Biolinum Slanted O | ||
| + | Subfamily: Bold Slanted | ||
| + | Full name: Linux Biolinum Slanted O Bold | ||
| + | PostScript name: LinBiolinumSlantedOB | ||
| + | Version: Version 0.7.1 | ||
| + | Unique ID: FontForge 2.0 : Linux Biolinum Slanted O Bold : 30-8-2010 | ||
| + | Designer: Philipp H. Poll | ||
| + | Designer URL: http://www.linuxlibertine.org | ||
| + | Manufacturer: Philipp H. Poll | ||
| + | Vendor URL: http://www.linuxlibertine.org | ||
| + | Copyright: Linux Libertine by Philipp H. Poll, | ||
| + | Open Font under Terms of following Free Software Licenses: | ||
| + | GPL (General Public License) with font-exception and OFL (Open Font License). | ||
| + | Created with FontForge (http://fontforge.sf.net) | ||
| + | Sept 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 | ||
| + | License URL: http://www.fsf.org/licenses/gpl.html AND http://scripts.sil.org/OFL | ||
| + | License Description: GPL- General Public License AND OFL-Open Font License | ||
| + | </source> | ||
| − | + | <noinclude> | |
| + | {{LaTeX/Bottom|Introduction|Structured document and document structure}} | ||
| + | </noinclude> | ||
Version actuelle en date du 1 juin 2011 à 08:39
Sommaire
Hello World basic example
|
\documentclass{article} |
Example with mathematics
\begin{document} The cosinus function, $\cos x$, can be defined by the power series \[\cos x=\sum_{k=0}^{\infty}\frac{(-1)^k}{(2k)!}x^{2k}\] as well as $\sin x$, $\tan x$ etc. \end{document}
will be displayed:
The cosinus function,
, can be defined by the power series

as well as
,
etc.
Another example, using the amsmath package from the American mathematical association:
\documentclass{article} \usepackage{amsmath} \begin{document} The cosinus function, $\cos x$, can be defined by the power series \begin{align} 1 &=\int_\alpha^\beta e^{-\rho x} \phi(x) dx\\ &= \int_\alpha^\beta e^{-\rho x}f(x)l(x) dx \\ l(x)&= \exp(-\int_0^x \mu(u)) du \\ l(x)&= e^{-\int_0^x \mu(u)} du \end{align} \[ \cos x=\sum_{k=0}^{\infty}\frac{(-1)^k}{(2k)!}x^{2k} \] as well as $\sin x$, $\tan x$ etc. \end{document} \end{document}
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}
L'image de la formule apparaît alors dans votre navigateur et il suffit d'un clic droit pour enregistrer l'image qui est sous un format .png ou de le copier en mémoire puis de le coller dans une application.
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 |
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} |
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 |
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.
Multilingual LaTeX with XeTeX
TeX and LaTeX did not evolve as quick as other softwares regarding multilingualism. Only XeTeX and LuaTeX are able to typeset various languages such as:
% % These lines tells gnu-emacs to typeset with the xetex engine % which requires Unicode encoding only (utf-8) %%% Local Variables: %%% TeX-engine: xetex %%% coding: utf-8 %%% End: % These lines tell TeXworks to typeset with xelatex, and to open and % save the source with Unicode encoding. % !TEX program = xelatex % !TEX encoding = UTF-8 Unicode %\documentclass{memoir} %\documentclass[AER,reviewmode]{AEA} % Production modes are draftmode, reviewmode and finalmode %\documentclass[11pt,a4paper]{amsart} \documentclass[11pt,a4paper]{article} \usepackage{mathptmx} % This if you want Times Roman fonts. \usepackage{xltxtra} % for xetex engine (includes fonstpec) %\setmainfont[Mapping=tex-text]{Linux Libertine O} % Only if you them on your system \begin{document} \section{Unicode support} \subsection{English} All human beings are born free and equal in dignity and rights. \subsection{Íslenska} Hver maður er borinn frjáls og jafn öðrum að virðingu og réttindum. \subsection{Русский} Все люди рождаются свободными и равными в своем достоинстве и правах. \subsection{Tiếng Việt} Tất cả mọi người sinh ra đều được tự do và bình đẳng về nhân phẩm và quyền lợi. \subsection{Ελληνικά} Ὅλοι οἱ ἄνθρωποι γεννιοῦνται ἐλεύθεροι καὶ ἴσοι στὴν ἀξιοπρέπεια καὶ τὰ δικαιώματα. \section{Legacy syntax} When he goes---``Hello World!''\\ She replies—“Hello dear!” \section{Ligatures} %\fontspec[Ligatures={Common, Historical}]{Linux Libertine O Italic} \fontsize{12pt}{18pt}\selectfont Questo è strano assai! \section{Numerals} %\fontspec[Numbers={OldStyle}]{Linux Libertine O}Old style: 1234567\\ %\fontspec[Numbers={Lining}]{Linux Libertine O}Lining: 1234567 \end{document}
- If some fonts do not come out, see http://mirror.ibcp.fr/pub/CTAN/macros/latex/contrib/fontspec/fontspec.pdf
as well as the package polyglossia http://www.tex.ac.uk/ctan/macros/xetex/latex/polyglossia/polyglossia.pdf which is a replacement of the Babel package for XeTeX.
- Libertine Linux fonts. In order to verify that the OpenType font is on your disk, you can use the otfinfo program. Here is an example with the command line (first locating any file having a 'libertine' name on your disk and using the --info option for a specific file :
$ locate .otf | grep libertine /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbb.otf /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbbo.otf /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbk.otf /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbo.otf /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbob.otf /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxboi.otf /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbr.otf /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbri.otf /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbro.otf /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbs.otf /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbsb.otf /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbsi.otf /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxlb.otf /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxlbi.otf /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxlbo.otf /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxlr.otf /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxlri.otf /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxlro.otf $ otfinfo --info /usr/local/texlive/2010/texmf-dist/fonts/opentype/public/libertine/fxbbo.otf Family: Linux Biolinum Slanted O Subfamily: Bold Slanted Full name: Linux Biolinum Slanted O Bold PostScript name: LinBiolinumSlantedOB Version: Version 0.7.1 Unique ID: FontForge 2.0 : Linux Biolinum Slanted O Bold : 30-8-2010 Designer: Philipp H. Poll Designer URL: http://www.linuxlibertine.org Manufacturer: Philipp H. Poll Vendor URL: http://www.linuxlibertine.org Copyright: Linux Libertine by Philipp H. Poll, Open Font under Terms of following Free Software Licenses: GPL (General Public License) with font-exception and OFL (Open Font License). Created with FontForge (http://fontforge.sf.net) Sept 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 License URL: http://www.fsf.org/licenses/gpl.html AND http://scripts.sil.org/OFL License Description: GPL- General Public License AND OFL-Open Font License