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 Prochaine révision Les deux révisions suivantes | ||
2_programmation:macros:que_sont_les_macros [2018/06/03 13:33] samcarter |
2_programmation:macros:que_sont_les_macros [2018/12/03 23:30] jejust |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | --- | + | ====== |
- | title: | + | |
- | category: concepts | + | |
- | permalink: / | + | |
- | date: 2014-06-10 | + | |
- | --- | + | |
- | TeX is a _macro processor_: this is a computer-science-y term | + | |
+ | TeX is a //macro processor//: this is a computer-science-y term | ||
meaning "text expander" | meaning "text expander" | ||
- | goes along, but _expands_ | + | goes along, but // |
may include instructions to TeX itself, on top of the simple text | may include instructions to TeX itself, on top of the simple text | ||
generation one might expect. | generation one might expect. | ||
- | Macros are a _good thing_, since they allow the user to | + | Macros are a //good thing//, since they allow the user to |
manipulate documents according to context. | manipulate documents according to context. | ||
- | `\TeX` is usually defined to produce " | + | '' |
(the original idea was Knuth' | (the original idea was Knuth' | ||
but in these FAQs the default definition of the macro is | but in these FAQs the default definition of the macro is | ||
- | overridden, and it simply expands to the letters " | + | overridden, and it simply expands to the letters " |
may not think this a good thing, but the author of the macros has his | may not think this a good thing, but the author of the macros has his | ||
- | reasons& | + | reasons |
- | Macro names are conventionally built from a `\` | + | Macro names are conventionally built from a '' |
followed by a sequence of letters, which may be upper or lower case | followed by a sequence of letters, which may be upper or lower case | ||
- | (as in `\TeX`, mentioned above). | + | (as in '' |
- | `<any single character> | + | '' |
sorts of oddities (many built in to most TeX macro sets, all the | sorts of oddities (many built in to most TeX macro sets, all the | ||
- | way up from the apparently simple | + | way up from the apparently simple |
here" | here" | ||
Macro programming can be a complicated business, but at their very | Macro programming can be a complicated business, but at their very | ||
- | simplest they need little introduction& | + | simplest they need little introduction |
told that: | told that: | ||
- | ```latex | + | |
+ | < | ||
\def\foo{bar} | \def\foo{bar} | ||
- | ``` | + | </ |
- | replaces each instance of `\foo` with the text " | + | replaces each instance of '' |
- | command | + | command |
- | LaTeX offers a macro `\newcommand` that goes some way towards | + | LaTeX offers a macro '' |
protecting users from themselves, but basically does the same thing: | protecting users from themselves, but basically does the same thing: | ||
- | ```latex | + | |
+ | < | ||
\newcommand{\foo}{bar} | \newcommand{\foo}{bar} | ||
- | ``` | + | </ |
Macros may have " | Macros may have " | ||
bits of the macro expansion: | bits of the macro expansion: | ||
- | ```latex | + | |
+ | < | ||
\def\foo# | \def\foo# | ||
... | ... | ||
\foo{2/4}. | \foo{2/4}. | ||
- | ``` | + | </ |
which produces: | which produces: | ||
This is a 2/4 bar. | This is a 2/4 bar. | ||
or, in LaTeX speak: | or, in LaTeX speak: | ||
- | ```latex | + | |
+ | < | ||
\newcommand{\foo}[1]{This is a #1 bar} | \newcommand{\foo}[1]{This is a #1 bar} | ||
... | ... | ||
\foo{3/4}. | \foo{3/4}. | ||
- | ``` | + | </ |
which produces: | which produces: | ||
This is 3/4 bar. | This is 3/4 bar. | ||
Ligne 62: | Ligne 62: | ||
You will have noticed that the arguments, above, were enclosed in | You will have noticed that the arguments, above, were enclosed in | ||
- | braces (`{`& | + | braces ('' |
normal way of typing arguments, though TeX is enormously flexible, | normal way of typing arguments, though TeX is enormously flexible, | ||
and you may find all sorts of other ways of passing arguments (if you | and you may find all sorts of other ways of passing arguments (if you | ||
Ligne 69: | Ligne 69: | ||
Macro writing can get very complicated, | Macro writing can get very complicated, | ||
beginner (La)TeX programmer, you are well advised to read something | beginner (La)TeX programmer, you are well advised to read something | ||
- | along the lines of the [TeXbook](FAQ-tex-books); once you're under | + | along the lines of the [[FAQ-tex-books|TeXbook]]; once you're under |
- | way, [TeX by Topic](FAQ-ol-books) is possibly a more satisfactory | + | way, [[FAQ-ol-books|TeX by Topic]] |
choice. | choice. | ||
about various issues of how to write macros. | about various issues of how to write macros. | ||
+ | |||
+ | ----- | ||
+ | |||
+ | //Source:// [[faquk> | ||
+ | |||
+ | {{htmlmetatags> | ||
+ | metatag-og: | ||
+ | metatag-og: | ||
+ | }} | ||