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
2_composition:macros:definir_une_macro_a_l_interieur_d_une_autre_macro [2018/06/03 15:08]
joseph.wright
2_composition:macros:definir_une_macro_a_l_interieur_d_une_autre_macro [2018/12/04 00:25] (Version actuelle)
jejust
Ligne 1: Ligne 1:
---- +====== ​Defining macros within macros ​======
-title: ​Defining macros within macros +
-category: programming +
-tags: macros +
-permalink: /FAQ-hash +
----+
  
-The way to think of this is that `##gets replaced by `#in just the + 
-same way that `#1gets replaced by "​whatever is the first argument"​.+The way to think of this is that ''​##'' ​gets replaced by ''​#'' ​in just the 
 +same way that ''​#1'' ​gets replaced by "​whatever is the first argument"​.
  
 So if you define a macro: So if you define a macro:
-```latex+ 
 +<​code ​latex>
 \newcommand\a[1]{+#​1+#​1+#​1+} \newcommand\a[1]{+#​1+#​1+#​1+}
-``` +</​code>​ 
-or (using the TeX primitive ​`\def`): +or (using the TeX primitive ​''​\def''​): 
-```latex+ 
 +<​code ​latex>
 \def\a#​1{+#​1+#​1+#​1+} \def\a#​1{+#​1+#​1+#​1+}
-``` +</​code>​ 
-and use it as `\a{b}`,+and use it as ''​\a{b}''​,
 the macro expansion produces "​+b+b+b+",​ the macro expansion produces "​+b+b+b+",​
 as most people would expect. as most people would expect.
  
 However, if we now replace part of the macro: However, if we now replace part of the macro:
-```latex+ 
 +<​code ​latex>
 \newcommand\a[1]{+#​1+\newcommand\x[1]{xxx#​1}} \newcommand\a[1]{+#​1+\newcommand\x[1]{xxx#​1}}
-``` +</​code>​ 
-then `\a{b}will give us the rather odd +then ''​\a{b}'' ​will give us the rather odd 
-  +b+`\newcommand{x}[1]{xxxb}` +  +b+''​\newcommand{x}[1]{xxxb}''​ 
-so that the new `\xignores its argument.+so that the new ''​\x'' ​ignores its argument.
  
 If we use the TeX primitive: ​ If we use the TeX primitive: ​
-```latex+ 
 +<​code ​latex>
 \def\a#​1{+#​1+\def\x #1{xxx#1}} \def\a#​1{+#​1+\def\x #1{xxx#1}}
-``` +</​code>​ 
-`\a{b}will expand to "+b+`\def\x b{xxxb}`"​. ​ This +''​\a{b}'' ​will expand to "+b+''​\def\x b{xxxb}''​"​. ​ This 
-defines ​`\xto be a macro _delimited_ ​by `b`, and taking no+defines ​''​\x'' ​to be a macro //​delimited// ​by ''​b''​, and taking no
 arguments, which is surely not what was intended! arguments, which is surely not what was intended!
  
-Actually, to define ​`\xto take an argument, we need +Actually, to define ​''​\x'' ​to take an argument, we need 
-```latex+ 
 +<​code ​latex>
 \newcommand\a[1]{+#​1+\newcommand\x[1]{xxx##​1}} \newcommand\a[1]{+#​1+\newcommand\x[1]{xxx##​1}}
-```+</​code>​
 or, using the TeX primitive definition: or, using the TeX primitive definition:
-```latex+ 
 +<​code ​latex>
 \def\a#​1{+#​1+\def\x ##​1{xxx##​1}} \def\a#​1{+#​1+\def\x ##​1{xxx##​1}}
-``` +</​code>​ 
-and `\a{b}will expand to  +and ''​\a{b}'' ​will expand to  
-  +b+`\def\x #1{xxx#1}` +  +b+''​\def\x #1{xxx#1}''​ 
-because ​`#1gets replaced by "​b"​ +because ​''​#1'' ​gets replaced by "​b"​ 
-and `##gets replaced by `#`.+and ''​##'' ​gets replaced by ''​#''​.
  
 To nest a definition inside a definition inside a definition then you To nest a definition inside a definition inside a definition then you
-need `####1`, doubling the number of `#signs; and at the next level +need ''​####1''​, doubling the number of ''​#'' ​signs; and at the next level 
-you need 8&nbsp;`#`s each time, and so on.+you need 8 ''​#''​s each time, and so on. 
 + 
 + 
 +----- 
 + 
 +//Source:// [[faquk>​FAQ-hash|Defining macros within macros]]
  
 +{{htmlmetatags>​metatag-keywords=(LaTeX,​programming)
 +metatag-og:​title=(Defining macros within macros)
 +metatag-og:​site_name=(FAQ LaTeX francophone)
 +}}
  
2_composition/macros/definir_une_macro_a_l_interieur_d_une_autre_macro.1528031282.txt.gz · Dernière modification: 2018/06/03 15:08 par joseph.wright
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0