Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
Prochaine révision Les deux révisions suivantes
2_programmation:macros:que_sont_les_environnements [2018/05/23 08:40]
joseph.wright
2_programmation:macros:que_sont_les_environnements [2021/07/06 07:06]
jejust Compilation du code d'un exemple.
Ligne 1: Ligne 1:
-What are LaTeX ''environments''+====== What are LaTeX environments”? ======
  
-While TeX makes direct provision for commands, LaTeX adds a + 
-concept of ''environment''; environments perform an action on a block +While TeX makes direct provision for commands, LaTeX adds a concept of "environment". 
-(of something or other) rather than than just doing something at one+Environments perform an action on a block (of something or other) rather than just doing something at one
 place in your document. place in your document.
  
 A totally trivial environment could change the font in use for a chunk A totally trivial environment could change the font in use for a chunk
 of text, as of text, as
-```latex+ 
 +<code latex>
 \newenvironment{monoblock}% \newenvironment{monoblock}%
   {\ttfamily}%   {\ttfamily}%
   {}   {}
-``` +</code> 
-which defines a `monoblockwhich may be used as +which defines a ''monoblock'' environment which may be used as: 
-```latex+ 
 +<WRAP column 50ex> 
 +<code latex>
 \begin{monoblock} \begin{monoblock}
-  some text set in monospace+  Some text set in monospace.
 \end{monoblock} \end{monoblock}
-``` +</code> 
-which will look like: +</WRAP> 
-  `some text set in monospace` +<WRAP column 30ex> 
-so it is a particularly simple example.  A rather complicated +<latexdoc> 
-environment is introduced by `\begin{document}`; it looks+\documentclass{article} 
 +  \usepackage{lmodern} 
 +  \pagestyle{empty} 
 + 
 +\newenvironment{monoblock}% 
 +  {\ttfamily}% 
 +  {} 
 + 
 +\begin{document} 
 +\large 
 +\begin{monoblock} 
 +  Some text set in monospace
 +\end{monoblock} 
 +\end{document} 
 +</latexdoc> 
 +</WRAP> 
 +<WRAP clear /> 
 + 
 +It is a particularly simple example.  A rather complicated 
 +environment is introduced by ''\begin{document}''; it looks
 simple, but needs all sorts of special TeX code to make it work simple, but needs all sorts of special TeX code to make it work
-''transparently''; most environments are more elaborate than +"transparently"; most environments are more elaborate than 
-`monoblockand _much_ simpler than +''monoblock'' and //much// simpler than ''document''.
-`document`.+
  
-An environment puts its content inside a TeX _group_, so that +An environment puts its content inside a TeX //group//, so that 
-commands used inside the environment don'''leak out''&nbsp;&mdash; the +commands used inside the environment don'"leak out" --- the 
-`monoblockenvironment, above, restricts its effect to +''monoblock'' environment, above, restricts its effect to 
-its own contents (the stuff between the `\begin{monoblock}` +its own contents (the stuff between the ''\begin{monoblock}'' 
-and `\end{monoblock}`), which is just what you need for this+and ''\end{monoblock}''), which is just what you need for this
 sort of thing. sort of thing.
  
-So that'''simple'' environments; the `monoblock`, above+So that'"simpleenvironments; the ''monoblock'', above
 doesn't actually gain us much over doesn't actually gain us much over
-```latex+ 
 +<code latex>
 {\ttfamily some text set in monospace} {\ttfamily some text set in monospace}
-``` +</code> 
-though in fact many useful environments are just as simple (to look +though in fact many useful environments are just as simple (to look at). 
-at).  Some, such as `verbatim`, look simple but are +Some, such as ''verbatim'', look simple but are actually very tricky inside.
-actually very tricky inside.+
  
 LaTeX also allows arguments to an environment: LaTeX also allows arguments to an environment:
-```latex+ 
 +<code latex>
 \newenvironment{fontblock}[1]% \newenvironment{fontblock}[1]%
   {#1\selectfont}%   {#1\selectfont}%
   {}   {}
-``` +</code> 
-and use of `fontblockas: +and use of ''fontblock'' as: 
-```latex+ 
 +<code latex>
 \begin{fontblock}{\ttfamily} \begin{fontblock}{\ttfamily}
-``` +</code> 
-would produce the same effect as the `monoblock+would produce the same effect as the ''monoblock'' environment.
-environment.+
  
 Environments may also have optional arguments, in much the same way as Environments may also have optional arguments, in much the same way as
 commands: commands:
-```latex+ 
 +<code latex>
 \newenvironment{normaltext}[1][\itshape]% \newenvironment{normaltext}[1][\itshape]%
   {#1}%   {#1}%
   {}   {}
-```+</code>
 which will ordinarily set its body in italic, but which will ordinarily set its body in italic, but
-```latex+ 
 +<code latex>
 \begin{normaltext}[\ttfamily] \begin{normaltext}[\ttfamily]
   ...   ...
 \end{normaltext} \end{normaltext}
-```+</code>
 will observe its optional argument, and behave the same as the will observe its optional argument, and behave the same as the
-`monoblockwe started with.+''monoblock'' we started with.
  
 Note that an environments argument(s) (mandatory or optional) are Note that an environments argument(s) (mandatory or optional) are
-_not_ passed to the `\endtext of the environment&nbsp;&mdash; that+//not// passed to the ''\end'' text of the environment --- that
 is specified as a macro with no arguments, so that is specified as a macro with no arguments, so that
-```latex+ 
 +<code latex>
 \newenvironment{normaltext}[1][\itshape]% \newenvironment{normaltext}[1][\itshape]%
   {#1}%   {#1}%
   {\typeout{what was #1, again?}   {\typeout{what was #1, again?}
-```+</code>
 produces an error message produces an error message
-```latex+ 
 +<code text>
 ! Illegal parameter number in definition of \endnormaltext. ! Illegal parameter number in definition of \endnormaltext.
-```+</code>
 So, if you need to pass an environment argument to the end-code, you So, if you need to pass an environment argument to the end-code, you
 have to wrap it in a macro of its own: have to wrap it in a macro of its own:
-<!-- {% raw %} --> + 
-```latex+ 
 +<code latex>
 \newenvironment{normaltext}[1][Intro]% \newenvironment{normaltext}[1][Intro]%
   {#1%   {#1%
    \newcommand{\foo}{#1}}%    \newcommand{\foo}{#1}}%
   {\typeout{what was \foo{}, again?}   {\typeout{what was \foo{}, again?}
-``` +</code> 
-<!-- {% endraw %} -->+
  
-----+----
 +//Source:// [[faquk>FAQ-whatenv|What are LaTeX “environments”]]
  
-Content last updated: 2014-06-10+{{htmlmetatags>metatag-keywords=(LaTeX,programmation,environnements personnalisés) 
 +metatag-og:title=(What are LaTeX “environments”?
 +metatag-og:site_name=(FAQ LaTeX francophone) 
 +}}
  
2_programmation/macros/que_sont_les_environnements.txt · Dernière modification: 2022/07/05 13:53 de dbitouze
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0