simple_macro.texi 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. \input texinfo @c -*-texinfo-*-
  2. @node Top
  3. @top Basic macro calls
  4. Define a simple macro
  5. @example
  6. @@macro macro1 @{arg1, arg2 @}
  7. result: @@emph@{\arg1\@} protected \\ -> \\arg1\\ @@emp@{\arg2\@}
  8. @@end macro
  9. @end example
  10. before macro @macro macro1 { arg1 , arg2 }
  11. result: @emph{\arg1\} protected \\ -> \\arg1\\ @emph{\arg2\}
  12. @end macro after end macro
  13. Calling (normal)
  14. @example
  15. the @@macro1 @{ @@samp@{f\irst arg@}, second arg @} after macro
  16. @end example
  17. ==================================
  18. the @macro1 { @samp{f\irst arg}, second arg } after macro
  19. -----------------------------------
  20. the result: @emph{@samp{first arg}} protected \ -> \arg1\ @emph{second arg } after macro
  21. ====================================
  22. Calling (one arg)
  23. @example
  24. @@macro1 @{ @@samp@{f\irst arg@}@}
  25. @end example
  26. ==================================
  27. @macro1 { @samp{f\irst arg}}
  28. -----------------------------------
  29. result: @emph{@samp{first arg}} protected \ -> \arg1\ @emph{}
  30. ====================================
  31. Calling (no args)
  32. @example
  33. @@macro1 @@samp@{f\irst arg@}, second arg
  34. @end example
  35. ==================================
  36. @macro1 @samp{f\irst arg}, second arg
  37. -----------------------------------
  38. result: @emph{} protected \ -> \arg1\ @emph{} @samp{f\irst arg}, second arg
  39. ====================================
  40. @ifhtml
  41. Calling (three args)
  42. @example
  43. @@macro1 @{ @@samp@{f\irst arg@}, second arg, third arg@}
  44. @end example
  45. ==================================
  46. @macro1 { @samp{f\irst arg}, second arg, third arg}
  47. -----------------------------------
  48. result: @emph{@samp{first arg}} protected \ -> \arg1\ @emph{second arg}
  49. ====================================
  50. @end ifhtml
  51. define a macro with one arg
  52. @example
  53. @@macro macro2 @{ arg @}
  54. we get \arg\ and another \arg\
  55. and a last one on another line \arg\
  56. and a last in another paragraph
  57. @@end macro
  58. @end example
  59. @macro macro2 { arg }
  60. we get \arg\ and another \arg\
  61. and another one on another line \arg\
  62. and a last in another paragraph
  63. @end macro
  64. Calling
  65. @example
  66. @@macro2 @{ arg, comma \, @}
  67. @end example
  68. ==================================
  69. @macro2 { arg, comma \, }
  70. -----------------------------------
  71. we get arg, comma , and another arg, comma ,
  72. and another one another line arg, comma ,
  73. and a last in another paragraph
  74. ==================================
  75. Calling
  76. @example
  77. @@macro2 arg, comma \,
  78. @end example
  79. ==================================
  80. @macro2 arg, comma \,
  81. -----------------------------------
  82. we get arg, comma \, and another arg, comma \,
  83. and another one on another line arg, comma \,
  84. and a last in another paragraph
  85. ==================================
  86. @macro ab
  87. a
  88. b
  89. @end macro
  90. now @@set comma ,
  91. @set comma ,
  92. @@set flagab @@ab
  93. @set flagab @ab
  94. the values:
  95. ======================================
  96. flagab: @value{flagab}
  97. --------------------------------------
  98. makeinfo result (the macro in set is expanded and all the resulting lines
  99. are replaced):
  100. flagab: a
  101. b
  102. ======================================
  103. comma: @value{comma}
  104. Calling macro1 with value
  105. @example
  106. @@macro1 @{ arg1 @@value@{comma@} arg2 @}
  107. @end example
  108. =======================================
  109. @macro1 { arg1 @value{comma} arg2 }
  110. ---------------------------------------
  111. makeinfo result (the comma don't separate args ; the value is expanded after
  112. arguments parsing):
  113. result: @emph{arg1 , arg2 } protected \ -> \arg1\ @emph{}
  114. =======================================
  115. In verbatim
  116. @verbatim
  117. comma: @value{comma}
  118. @macro1{ bidule, truc}
  119. @end verbatim
  120. @set argument arg
  121. @set bodyarg \arg\
  122. Define macro
  123. @example
  124. @@macro testvaluebody @{ arg @}
  125. result: @@emph@{\@@value@{bodyarg@}\ @}
  126. @@end macro
  127. @end example
  128. @macro testvaluebody { arg }
  129. result: @emph{\@value{bodyarg}\ }
  130. @end macro
  131. ==================================
  132. @testvaluebody{macro_arg1}
  133. ----------------------------------
  134. makeinfo result (according to error message, the value isn't expanded
  135. when the body is expanded; it is kept, but the second \ isn't):
  136. result: @emph{\\arg\ }
  137. ==================================
  138. Define macro
  139. @example
  140. @@macro testvalue @{ arg , the@@value@{argument@} @}
  141. result: @@emph@{\arg\@} the \the\ thearg \thearg\ with value \the@@value@{argument@}\
  142. @@end macro
  143. @end example
  144. @macro testvalue { arg , the@value{argument} }
  145. result: @emph{\arg\} the \the\ thearg \thearg\ with value \the@value{argument}\
  146. @end macro
  147. ==================================
  148. @testvalue{macro_arg1}
  149. ----------------------------------
  150. makeinfo (breaks) result:
  151. result: @emph{macro_arg1} the \the thearg \thearg with value \thearg
  152. ==================================
  153. Define macro without arg
  154. @example
  155. @@macro test1
  156. test1
  157. @@end macro
  158. @end example
  159. @macro test1
  160. test1
  161. @end macro
  162. Call with @{@}:
  163. ==================================
  164. @test1{} abc
  165. ----------------------------------
  166. test1 abc
  167. ==================================
  168. Call with something on the line
  169. ==================================
  170. @test1 abc
  171. ----------------------------------
  172. test1 abc
  173. ==================================
  174. An empty set value
  175. @set myspace
  176. 1 @value{myspace} 1
  177. @contents
  178. @bye