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 | ||
2_programmation:macros:definir_une_macro_a_plus_de_9_arguments [2018/05/23 13:56] d.p.carlisle |
2_programmation:macros:definir_une_macro_a_plus_de_9_arguments [2021/10/21 12:01] bdumont [Avec l'extension keyval] Renvoi vers un nouvel article dédié à cette question |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | # How to break the 9-argument limit | + | ====== Comment dépasser la limite des 9 arguments pour une commande? ====== |
- | If you think about it, you will realise that Knuth' | + | Si vous y réfléchissez, vous vous rendrez compte que la syntaxe de définition de commande dans <latex> |
- | definition syntax: | + | |
- | ```latex | + | |
- | \def\blah#1#2 ... #9{<macro body>} | + | |
- | ``` | + | |
- | is intrinsically limited to just 9 arguments. | + | |
- | round this: how would you express a 10th argument?& | + | |
- | the syntax didn't gobble some other valid usage? | + | |
- | If you really must have more than 9 arguments, | + | <code latex> |
- | <!-- {% raw %} --> | + | \def\truc# |
- | ```latex | + | </ |
- | \def\blah#1#2 ... #9{% | + | |
+ | En effet, les commandes sont intrinsèquement limitées à 9 arguments (vous ne pouvez pas mettre un ''# | ||
+ | |||
+ | ===== Avec des commandes de base ===== | ||
+ | |||
+ | Si vous devez vraiment avoir plus de 9 arguments, | ||
+ | |||
+ | < | ||
+ | \def\truc#1#2 ... #9{% | ||
\def\ArgI{{# | \def\ArgI{{# | ||
\def\ArgII{{# | \def\ArgII{{# | ||
... | ... | ||
\def\ArgIX{{# | \def\ArgIX{{# | ||
- | \BlahRelay | + | \TrucBis |
} | } | ||
- | \def\BlahRelay#1#2#3{% | + | \def\TrucBis#1#2#3{% |
- | % arguments 1-9 are now in | + | % Les arguments 1 à 9 sont maintenant dans |
- | % | + | % \ArgI-\ArgIX. |
- | % arguments 10-12 are in | + | % Les arguments 10 à 12 sont maintenant dans |
- | % | + | % #1 à #3. |
- | | + | |
} | } | ||
- | ``` | + | </code> |
- | <!-- {% endraw %} --> | + | |
- | This technique is easily extendible by concert pianists of the TeX | + | |
- | keyboard, but is really hard to recommend. | + | |
- | LaTeX users have the small convenience of merely giving a number of | + | Cette technique est facilement extensible par les spécialites de <latex>\TeX</latex> mais elle n'est pas vraiment recommandée. |
- | arguments in the `\newcommand` that defines each part of the | + | |
- | relaying mechanism: Knuth' | + | |
- | just as it does to `\def`. | + | |
- | way out of such barbarous command syntax: the [`keyval`](https:// | + | |
- | package. | + | |
- | write really quite sophisticated commands, whose invocation might look | + | |
- | like: | + | |
- | <!-- {% raw %} --> | + | |
- | ```latex | + | |
- | \flowerinstance{species=Primula veris, | + | |
- | family=Primulaceae, | + | |
- | location=Coldham' | + | |
- | locationtype=Common grazing land, | + | |
- | date=1995/04/24, | + | |
- | numplants=50, | + | |
- | soiltype=alkaline | + | |
- | } | + | |
- | ``` | + | |
- | <!-- {% endraw %} --> | + | |
- | The merit of such verbosity is that it is self-explanatory: | + | |
- | doesn't have to remember that argument twelve is `soiltype`, and so | + | |
- | on: the commands may be copied from field notes quickly and | + | |
- | accurately. | + | |
- | * faq-mac-prog.tex (q-keyval): tweak words about getoptk | + | ===== En définissant des arguments clé-valeur ===== |
+ | En [[2_programmation: | ||
+ | |||
+ | <code latex> | ||
+ | \instancefleur{espece=Primula veris, | ||
+ | famille=Primulaceae, | ||
+ | localisation=Coldham' | ||
+ | typeemplacement=Paturage, | ||
+ | date=24/ | ||
+ | nombre=50, | ||
+ | typesol=alkaline | ||
+ | } | ||
+ | </ | ||
- | ---- | + | Le mérite d'une telle débauche de code est simple : l' |
- | Content last updated: 2014-06-10 | + | ----- |
+ | // | ||
+ | {{htmlmetatags> | ||
+ | metatag-og: | ||
+ | metatag-og: | ||
+ | }} |