Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
2_programmation:macros:que_sont_les_environnements [2018/12/03 23:30] jejust |
2_programmation:macros:que_sont_les_environnements [2021/11/27 10:02] (Version actuelle) yannick.tanguy Correction d'une coquille suite à traduction. |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ====== | + | ====== |
+ | Les // | ||
- | While TeX makes direct provision for commands, LaTeX adds a | + | ===== Environnement sans paramètre ===== |
- | concept of " | + | |
- | (of something or other) rather than than just doing something at one | + | |
- | place in your document. | + | |
- | A totally trivial environment could change the font in use for a chunk | + | Un environnement simple pourrait changer la police utilisée pour une partie du texte. En voici un exemple de définition : |
- | of text, as | + | |
<code latex> | <code latex> | ||
- | \newenvironment{monoblock}% | + | \newenvironment{chassefixe}% |
- | {\ttfamily}% | + | {% Code exécuté au début de l' |
- | {} | + | \ttfamily}% |
+ | {% Code exécuté en fin d' | ||
+ | | ||
</ | </ | ||
- | which defines a '' | ||
+ | L' | ||
+ | |||
+ | <WRAP column 50ex> | ||
<code latex> | <code latex> | ||
- | \begin{monoblock} | + | Voici un exemple% |
- | some text set in monospace | + | \begin{chassefixe} |
- | \end{monoblock} | + | de texte à chasse fixe. |
+ | \end{chassefixe} | ||
</ | </ | ||
- | which will look like: | + | </ |
- | '' | + | <WRAP column 30ex> |
- | so it is a particularly simple example. | + | < |
- | environment is introduced by '' | + | \documentclass{article} |
- | simple, but needs all sorts of special TeX code to make it work | + | |
- | " | + | |
- | '' | + | |
- | '' | + | |
- | An environment puts its content inside a TeX //group//, so that | + | \newenvironment{chassefixe}% |
- | commands used inside the environment don't "leak out" --- the | + | {\ttfamily}% |
- | '' | + | {} |
- | its own contents | + | |
- | and '' | + | \begin{document} |
- | sort of thing. | + | Voici un exemple% |
+ | \begin{chassefixe} | ||
+ | de texte à chasse fixe. | ||
+ | \end{chassefixe} | ||
+ | \end{document} | ||
+ | </latexdoc> | ||
+ | </WRAP> | ||
+ | <WRAP clear /> | ||
+ | |||
+ | Certains environnements s' | ||
+ | |||
+ | Un environnement place son contenu dans un //groupe// < | ||
- | So that's " | + | <note tip> |
- | doesn't actually gain us much over | + | Certains environnements simples ne nous font pas gagner beaucoup de temps en matière de saisie. De fait, notre environnement |
<code latex> | <code latex> | ||
- | {\ttfamily | + | Voici un exemple |
</ | </ | ||
- | though in fact many useful environments are just as simple (to look | ||
- | at). Some, such as '' | ||
- | actually very tricky inside. | ||
- | LaTeX also allows arguments to an environment: | + | Cependant, ces environnements : |
+ | * peuvent rendre votre code plus lisible ; | ||
+ | * permettent de mieux gérer la mise en forme de votre document. Ainsi, modifier la définition de votre environnement modifiera la mise en forme de tous les environnements présents dans votre document. | ||
+ | </ | ||
+ | |||
+ | ===== Environnement avec paramètres ===== | ||
+ | |||
+ | < | ||
<code latex> | <code latex> | ||
- | \newenvironment{fontblock}[1]% | + | \newenvironment{blocfonte}[1]% |
{# | {# | ||
{} | {} | ||
</ | </ | ||
- | and use of '' | + | |
+ | Cet environnement s'utilise alors ainsi (et produit ici le même résultat que l'environnement | ||
<code latex> | <code latex> | ||
- | \begin{fontblock}{\ttfamily} | + | Voici un exemple% |
+ | \begin{blocfonte}{\ttfamily} | ||
+ | de texte à chasse fixe. | ||
+ | \end{blocfonte} | ||
</ | </ | ||
- | would produce the same effect as the '' | ||
- | environment. | ||
- | Environments may also have optional arguments, in much the same way as | + | ==== Les paramètres optionnels ==== |
- | commands: | + | |
+ | Les environnements peuvent également avoir des paramètres optionnels, à l' | ||
<code latex> | <code latex> | ||
- | \newenvironment{normaltext}[1][\itshape]% | + | \newenvironment{textespecial}[1][\itshape]% |
{#1}% | {#1}% | ||
{} | {} | ||
</ | </ | ||
- | which will ordinarily set its body in italic, but | + | |
+ | En temps normal, cet environnement compose son contenu en italique mais, dès qu'un paramètre lui est transmis, il modifie la mise en forme (ici, une nouvelle fois pour restituer la mise en forme obtenue avec '' | ||
<code latex> | <code latex> | ||
- | \begin{normaltext}[\ttfamily] | + | Voici un exemple% |
- | ... | + | \begin{textespecial}{\ttfamily} |
- | \end{normaltext} | + | de texte à chasse fixe. |
+ | \end{textespecial} | ||
</ | </ | ||
- | will observe its optional argument, and behave the same as the | ||
- | '' | ||
- | Note that an environments argument(s) (mandatory or optional) are | + | ==== La gestion des paramètres en fin d' |
- | //not// passed to the '' | + | |
- | is specified as a macro with no arguments, so that | + | Les paramètres d' |
<code latex> | <code latex> | ||
- | \newenvironment{normaltext}[1][\itshape]% | + | \newenvironment{textespecial}[1][extrait]% |
- | {#1}% | + | {Ici commence notre #1.}% |
- | {\typeout{what was #1, again?} | + | {Ici finit notre #1.} |
</ | </ | ||
- | produces an error message | ||
- | < | + | Il se produit ici l' |
- | ! Illegal parameter number in definition of \endnormaltext. | + | |
+ | < | ||
+ | ! Illegal parameter number in definition of \endtextespecial. | ||
</ | </ | ||
- | So, if you need to pass an environment argument to the end-code, you | ||
- | have to wrap it in a macro of its own: | ||
+ | Aussi, si vous devez passer un paramètre d' | ||
<code latex> | <code latex> | ||
- | \newenvironment{normaltext}[1][Intro]% | + | \newenvironment{textespecial}[1][extrait]% |
- | {#1% | + | {Ici commence notre #1.% |
- | | + | |
- | {\typeout{what was \foo{}, again?} | + | {Ici finit notre \transfert.} |
</ | </ | ||
- | |||
----- | ----- | ||
+ | //Source:// [[faquk> | ||
- | //Source:// [[faquk> | + | {{htmlmetatags> |
- | + | metatag-og: | |
- | {{htmlmetatags> | + | |
- | metatag-og: | + | |
metatag-og: | metatag-og: | ||
}} | }} | ||
- |