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_programmation:macros:macros_a_plusieurs_arguments_optionnels [2018/05/25 21:20]
joseph.wright
2_programmation:macros:macros_a_plusieurs_arguments_optionnels [2018/12/03 23:28] (Version actuelle)
jejust
Ligne 1: Ligne 1:
---- +====== More than one optional argument ======
-title: More than one optional argument +
-category: programming +
-tags: macros latex +
-permalink: /FAQ-twooptarg +
-date: 2014-06-10 +
----+
  
-# More than one optional argument 
  
 If you've already read  If you've already read 
-''[breaking the 9-argument limit](/FAQ-moren9)''+"[[FAQ-moren9|breaking the 9-argument limit]]"
-you can probably guess the ''simple'' solution to this problem:+you can probably guess the "simplesolution to this problem:
 command relaying. command relaying.
  
 LaTeX allows commands with a single optional argument thus: LaTeX allows commands with a single optional argument thus:
-```latex+ 
 +<code latex>
   \newcommand{\blah}[1][Default]{...}   \newcommand{\blah}[1][Default]{...}
-```+</code>
  
 You may legally call such a command either with its optional argument You may legally call such a command either with its optional argument
 present, as present, as
-`\blah[nonDefault]or without, as `\blah`; in the latter +''\blah[nonDefault]'' or without, as ''\blah''; in the latter 
-case, the code of `\blahwill have an argument of `Default`.+case, the code of ''\blah'' will have an argument of ''Default''.
  
 To define a command with two optional arguments, we use the relaying To define a command with two optional arguments, we use the relaying
 technique, as follows: technique, as follows:
-<!-- {% raw %} --> + 
-```latex+ 
 +<code latex>
 \newcommand{\blah}[1][Default1]{% \newcommand{\blah}[1][Default1]{%
   \def\ArgI{{#1}}%   \def\ArgI{{#1}}%
Ligne 38: Ligne 33:
   ...%   ...%
 } }
-``` +</code> 
-<!-- {% endraw %} --+ 
-Of course, `\BlahRelaymay have as many mandatory arguments as are+Of course, ''\BlahRelay'' may have as many mandatory arguments as are
 allowed, after allowance for the one taken up with its own allowed, after allowance for the one taken up with its own
-optional argument&nbsp;&mdash; that is, 8.+optional argument --- that is, 8.
  
-Variants of `\newcommand(and friends), with names like +Variants of ''\newcommand'' (and friends), with names like 
-`\newcommandtwoopt`, are available in the [`twoopt`](https://ctan.org/pkg/twooptpackage.+''\newcommandtwoopt'', are available in the [[ctanpkg>twoopt|twoopt]] package.
 However, if you can, it's probably better to learn to write the commands However, if you can, it's probably better to learn to write the commands
 yourself, just to see why they're not even a good idea from the yourself, just to see why they're not even a good idea from the
Ligne 53: Ligne 48:
 sensible: obviously you can extend the technique to provide as many sensible: obviously you can extend the technique to provide as many
 optional arguments as your fevered imagination can summon.  However, optional arguments as your fevered imagination can summon.  However,
-see the comments on the use of the [`keyval`](https://ctan.org/pkg/keyvalpackage, in  +see the comments on the use of the [[ctanpkg>keyval|keyval]] package, in  
-''[breaking the 9-argument limit](/FAQ-moren9)'',+"[[FAQ-moren9|breaking the 9-argument limit]]",
 which offers an alternative way forward. which offers an alternative way forward.
  
-If you must, however, consider the [`optparams`](https://ctan.org/pkg/optparamsor +If you must, however, consider the [[ctanpkg>optparams|optparams]] or 
-[`xargs`](https://ctan.org/pkg/xargs) packages.  [`Optparams`](https://ctan.org/pkg/Optparams) +[[ctanpkg>xargs]packages.  [[ctanpkg>Optparams|Optparams]] 
-provides a `\optparamscommand that you use as an intermediate in+provides a ''\optparams'' command that you use as an intermediate in
 defining commands with up to nine optional arguments.  The defining commands with up to nine optional arguments.  The
 documentation shows examples of commands with four optional arguments documentation shows examples of commands with four optional arguments
 (and this from an author who has his own key-value package!). (and this from an author who has his own key-value package!).
  
-The [`xargs`](https://ctan.org/pkg/xargs) package uses a key-value package +The [[ctanpkg>xargs]package uses a key-value package 
-([`xkeyval`](https://ctan.org/pkg/xkeyval)) to _define_ the layout of the optional+([[ctanpkg>xkeyval]]) to //define// the layout of the optional
 arguments.  Thus arguments.  Thus
-```latex+ 
 +<code latex>
 \usepackage{xargs} \usepackage{xargs}
 ... ...
 \newcommandx{\foo}[3][1=1, 3=n]{...} \newcommandx{\foo}[3][1=1, 3=n]{...}
-``` +</code> 
-defines a command `\foothat has an optional first argument+defines a command ''\foo'' that has an optional first argument
 (default 1), a mandatory second argument, and an optional third (default 1), a mandatory second argument, and an optional third
 argument (default n). argument (default n).
  
 An alternative approach is offered by Scott Pakin's An alternative approach is offered by Scott Pakin's
-`newcommandprogram, which takes a command name and a+''newcommand'' program, which takes a command name and a
 definition of a set of command arguments (in a fairly definition of a set of command arguments (in a fairly
 readily-understood language), and emits (La)TeX macros which enable readily-understood language), and emits (La)TeX macros which enable
 the command to be defined.  The command requires that a the command to be defined.  The command requires that a
-`Pythoninterpreter (etc.) be installed on your computer.+Python interpreter (etc.) be installed on your computer. 
 + 
 + 
 +----- 
 + 
 +//Source:// [[faquk>FAQ-twooptarg|More than one optional argument]]
  
 +{{htmlmetatags>metatag-keywords=(LaTeX,latex,macros,programming)
 +metatag-og:title=(More than one optional argument)
 +metatag-og:site_name=(FAQ LaTeX francophone)
 +}}
  
2_programmation/macros/macros_a_plusieurs_arguments_optionnels.1527283228.txt.gz · Dernière modification: 2018/05/25 21:20 de joseph.wright
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0