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 Dernière révision Les deux révisions suivantes | ||
2_programmation:macros:que_sont_les_environnements [2018/05/23 20:28] joseph.wright |
2_programmation:macros:que_sont_les_environnements [2021/11/27 10:02] yannick.tanguy Correction d'une coquille suite à traduction. |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | --- | + | ====== Que sont les environnements |
- | ID: Q-whatenv | + | |
- | section: Bits and pieces of (La)TeX | + | |
- | revised: 2014-06-10 | + | |
- | --- | + | |
- | # What are LaTeX '' | + | |
- | While TeX makes direct provision for commands, | + | Les // |
- | 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 | + | ===== Environnement sans paramètre ===== |
- | of text, as | + | |
- | ```latex | + | Un environnement simple pourrait changer la police utilisée pour une partie du texte. En voici un exemple de définition : |
- | \newenvironment{monoblock}% | + | |
+ | < | ||
+ | \newenvironment{chassefixe}% | ||
+ | {% Code exécuté au début de l' | ||
+ | | ||
+ | {% Code exécuté en fin d' | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | L' | ||
+ | |||
+ | <WRAP column 50ex> | ||
+ | <code latex> | ||
+ | Voici un exemple% | ||
+ | \begin{chassefixe} | ||
+ | de texte à chasse fixe. | ||
+ | \end{chassefixe} | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP column 30ex> | ||
+ | < | ||
+ | \documentclass{article} | ||
+ | \usepackage{lmodern} | ||
+ | \pagestyle{empty} | ||
+ | |||
+ | \newenvironment{chassefixe}% | ||
{\ttfamily}% | {\ttfamily}% | ||
{} | {} | ||
- | ``` | ||
- | which defines a `monoblock` which may be used as | ||
- | ```latex | ||
- | \begin{monoblock} | ||
- | some text set in monospace | ||
- | \end{monoblock} | ||
- | ``` | ||
- | which will look like: | ||
- | `some text set in monospace` | ||
- | so it is a particularly simple example. | ||
- | environment is introduced by `\begin{document}`; | ||
- | simple, but needs all sorts of special TeX code to make it work | ||
- | '' | ||
- | `monoblock` and _much_ simpler than | ||
- | `document`. | ||
- | An environment puts its content inside a TeX _group_, so that | + | \begin{document} |
- | commands used inside the environment don't '' | + | Voici un exemple% |
- | `monoblock` environment, | + | \begin{chassefixe} |
- | its own contents (the stuff between the `\begin{monoblock}` | + | de texte à chasse fixe. |
- | and `\end{monoblock}`), which is just what you need for this | + | \end{chassefixe} |
- | sort of thing. | + | \end{document} |
+ | </ | ||
+ | </ | ||
+ | <WRAP clear /> | ||
- | So that's '' | + | Certains environnements |
- | doesn't actually gain us much over | + | |
- | ```latex | + | |
- | {\ttfamily some text set in monospace} | + | |
- | ``` | + | |
- | though in fact many useful environments are just as simple (to look | + | |
- | at). Some, such as `verbatim`, look simple but are | + | |
- | actually very tricky inside. | + | |
- | LaTeX also allows arguments to an environment: | + | Un environnement place son contenu dans un //groupe// < |
- | ```latex | + | |
- | \newenvironment{fontblock}[1]% | + | <note tip> |
+ | Certains environnements simples ne nous font pas gagner beaucoup de temps en matière de saisie. De fait, notre environnement '' | ||
+ | |||
+ | <code latex> | ||
+ | Voici un exemple {\ttfamily de texte à chasse fixe.} | ||
+ | </ | ||
+ | |||
+ | 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 ===== | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | \newenvironment{blocfonte}[1]% | ||
{# | {# | ||
{} | {} | ||
- | ``` | + | </ |
- | and use of `fontblock` as: | + | |
- | ```latex | + | |
- | \begin{fontblock}{\ttfamily} | + | |
- | ``` | + | |
- | would produce the same effect as the `monoblock` | + | |
- | environment. | + | |
- | Environments may also have optional arguments, in much the same way as | + | Cet environnement s' |
- | commands: | + | |
- | ```latex | + | <code latex> |
- | \newenvironment{normaltext}[1][\itshape]% | + | Voici un exemple% |
+ | \begin{blocfonte}{\ttfamily} | ||
+ | de texte à chasse fixe. | ||
+ | \end{blocfonte} | ||
+ | </ | ||
+ | |||
+ | ==== Les paramètres optionnels ==== | ||
+ | |||
+ | Les environnements peuvent également avoir des paramètres optionnels, à l' | ||
+ | |||
+ | < | ||
+ | \newenvironment{textespecial}[1][\itshape]% | ||
{#1}% | {#1}% | ||
{} | {} | ||
- | ``` | + | </ |
- | which will ordinarily set its body in italic, but | + | |
- | ```latex | + | |
- | \begin{normaltext}[\ttfamily] | + | |
- | ... | + | |
- | \end{normaltext} | + | |
- | ``` | + | |
- | will observe its optional argument, and behave the same as the | + | |
- | `monoblock` we started with. | + | |
- | Note that an environments argument(s) (mandatory or optional) are | + | 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 '' |
- | _not_ passed to the `\end` text of the environment& | + | |
- | is specified as a macro with no arguments, so that | + | <code latex> |
- | ```latex | + | Voici un exemple% |
- | \newenvironment{normaltext}[1][\itshape]% | + | \begin{textespecial}{\ttfamily} |
- | {#1}% | + | de texte à chasse fixe. |
- | {\typeout{what was #1, again?} | + | \end{textespecial} |
- | ``` | + | </ |
- | produces an error message | + | |
- | ```latex | + | ==== La gestion des paramètres en fin d' |
- | ! Illegal parameter number in definition of \endnormaltext. | + | |
- | ``` | + | Les paramètres d' |
- | So, if you need to pass an environment argument to the end-code, you | + | |
- | have to wrap it in a macro of its own: | + | < |
- | <!-- {% raw %} --> | + | \newenvironment{textespecial}[1][extrait]% |
- | ```latex | + | {Ici commence notre #1.}% |
- | \newenvironment{normaltext}[1][Intro]% | + | {Ici finit notre #1.} |
- | {#1% | + | </ |
- | | + | |
- | {\typeout{what was \foo{}, again?} | + | Il se produit ici l' |
- | ``` | + | |
- | <!-- {% endraw %} --> | + | <code text> |
+ | ! Illegal parameter number in definition of \endtextespecial. | ||
+ | </ | ||
+ | |||
+ | Aussi, si vous devez passer un paramètre d' | ||
+ | |||
+ | <code latex> | ||
+ | \newenvironment{textespecial}[1][extrait]% | ||
+ | {Ici commence notre #1.% | ||
+ | | ||
+ | {Ici finit notre \transfert.} | ||
+ | </code> | ||
+ | |||
+ | ----- | ||
+ | //Source:// [[faquk>FAQ-whatenv|What are LaTeX “environments”]] | ||
+ | {{htmlmetatags> | ||
+ | metatag-og: | ||
+ | metatag-og: | ||
+ | }} |