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/06/03 15:18]
d.p.carlisle
2_programmation:macros:que_sont_les_environnements [2018/12/04 00:30]
jejust
Ligne 1: Ligne 1:
---- +====== ​What are LaTeX "​environments" ​====== 
-title: ​What are LaTeX "​environments"​ +
-category: concepts +
-permalink: /​FAQ-whatenv +
----+
  
 While TeX makes direct provision for commands, LaTeX adds a While TeX makes direct provision for commands, LaTeX adds a
Ligne 12: Ligne 9:
 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'' ​which may be used as 
-```latex+ 
 +<​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: which will look like:
-  ​`some text set in monospace`+  ​''​some text set in monospace''​
 so it is a particularly simple example. ​ A rather complicated so it is a particularly simple example. ​ A rather complicated
-environment is introduced by `\begin{document}`; it looks+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't "leak out"&​nbsp;&​mdash; ​the +commands used inside the environment don't "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's "​simple"​ environments;​ the `monoblock`, above+So that's "​simple"​ environments;​ 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).  Some, such as `verbatim`, look simple but are+at).  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 ​latex>
 ! 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"​]] 
 + 
 +{{htmlmetatags>​metatag-keywords=(LaTeX,​concepts) 
 +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: 2021/11/27 11:02 par yannick.tanguy
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0