Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
2_programmation:macros:que_sont_les_environnements [2021/07/06 07:06] – Compilation du code d'un exemple. jejust | 2_programmation:macros:que_sont_les_environnements [2022/07/05 13:53] (Version actuelle) – [La gestion des paramètres en fin d'environnement] <> → ⟨⟩ dbitouze | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ====== | + | ====== |
+ | Les // | ||
- | While TeX makes direct provision for commands, LaTeX adds a concept of " | + | ===== Environnement sans paramètre ===== |
- | Environments perform an action on a block (of something or other) rather 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'environnement | ||
<WRAP column 50ex> | <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} | ||
</ | </ | ||
</ | </ | ||
Ligne 29: | Ligne 31: | ||
\pagestyle{empty} | \pagestyle{empty} | ||
- | \newenvironment{monoblock}% | + | \newenvironment{chassefixe}% |
{\ttfamily}% | {\ttfamily}% | ||
{} | {} | ||
\begin{document} | \begin{document} | ||
- | \large | + | Voici un exemple% |
- | \begin{monoblock} | + | \begin{chassefixe} |
- | Some text set in monospace. | + | de texte à chasse fixe. |
- | \end{monoblock} | + | \end{chassefixe} |
\end{document} | \end{document} | ||
</ | </ | ||
Ligne 43: | Ligne 45: | ||
<WRAP clear /> | <WRAP clear /> | ||
- | It is a particularly simple example. | + | Certains environnements s' |
- | environment is introduced by '' | + | |
- | simple, but needs all sorts of special | + | |
- | " | + | |
- | '' | + | |
- | An environment puts its content inside a TeX //group//, so that | + | Un environnement place son contenu dans un //groupe// < |
- | commands used inside the environment don't "leak out" --- the | + | |
- | '' | + | |
- | its own contents | + | |
- | and '' | + | |
- | sort of thing. | + | |
- | 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 '' | ||
- | 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 '' | ||
- | 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' | ||
<code text> | <code text> | ||
- | ! 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> | + | {{htmlmetatags> |
- | metatag-og: | + | metatag-og: |
metatag-og: | metatag-og: | ||
}} | }} | ||
- |