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
2_programmation:macros:definir_une_macro_latex_a_l_interieur_d_une_autre_macro [2021/11/17 08:35]
yannick.tanguy Suppression de la page, en doublon avec une autre page.
— (Version actuelle)
Ligne 1: Ligne 1:
-====== Defining LaTeX commands within other commands ====== 
- 
- 
-LaTeX command definition is significantly different from the TeX 
-primitive form discussed in an  
-[[FAQ-hash|earlier question]] about definitions within 
-macros. 
- 
-In most ways, the LaTeX situation is simpler (at least in part 
-because it imposes more restrictions on the user); however, defining a 
-command within a command still requires some care. 
- 
-The earlier question said you have to double the ''#''​ signs in command 
-definitions:​ in fact, the same rule holds, except that LaTeX 
-already takes care of some of the issues, by generating argument lists 
-for you. 
- 
-The basic problem is that: 
- 
- 
-<code latex> 
-\newcommand{\abc}[1]{joy,​ oh #1!% 
-  \newcommand{\ghi}[1]{gloom,​ oh #1!}% 
-} 
-</​code>​ 
- 
-followed by a call: 
- 
-<code latex> 
-\cmdinvoke{abc}{joy} 
-</​code>​ 
-typesets "joy, oh joy!", but defines a command ''​\ghi''​ that takes 
-one parameter, which it ignores; ''​\ghi{gloom}''​ will expand to 
-"​gloom,​ oh joy!", which is presumably not what was expected. 
- 
-And (as you will probably guess, if you've read the earlier question) 
-the definition: 
- 
- 
-<code latex> 
-\newcommand{\abc}[1]{joy,​ oh #1!% 
-  \newcommand{\ghi}[1]{gloom,​ oh ##1!}% 
-} 
-</​code>​ 
- 
-does what is required, and ''​\ghi{gloom}''​ will expand to 
-"​gloom,​ oh gloom!",​ whatever the argument to ''​\abc''​. 
- 
-The doubling is needed whether or not the enclosing command has an 
-argument, so: 
- 
- 
-<code latex> 
-\newcommand{\abc}{joy,​ oh joy!% 
-  \newcommand{\ghi}[1]{gloom,​ oh ##1!}% 
-} 
-</​code>​ 
- 
-is needed to produce a replica of the ''​\ghi''​ we defined earlier. 
- 
- 
------ 
- 
-//Source:// [[faquk>​FAQ-ltxhash|Defining LaTeX commands within other commands]] 
- 
-{{htmlmetatags>​metatag-keywords=(LaTeX,​latex,​macros,​programming) 
-metatag-og:​title=(Defining LaTeX commands within other commands) 
-metatag-og:​site_name=(FAQ LaTeX francophone) 
-}} 
  
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0