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:def_newcommand_providecommand [2018/05/25 10:56]
joseph.wright
2_programmation:macros:def_newcommand_providecommand [2018/12/04 00:26] (Version actuelle)
jejust
Ligne 1: Ligne 1:
---- +====== Transcribing LaTeX command definitions ======
-section: Macro programming +
-subsection: ''​Generic''​ macros and techniques +
-permalink: /​FAQ-cvtlatex +
-date: 2014-06-10 +
----+
  
-# Transcribing LaTeX command definitions 
  
 At several places in this FAQ, questions are answered in terms At several places in this FAQ, questions are answered in terms
Ligne 14: Ligne 8:
 definitions for use in other packages. definitions for use in other packages.
  
-The reason LaTeX has commands that replace ​`\def`, is that+The reason LaTeX has commands that replace ​''​\def''​, is that
 there'​s a general philosophy within LaTeX that the user should be there'​s a general philosophy within LaTeX that the user should be
 protected from himself: the user has different commands according to protected from himself: the user has different commands according to
-whether the command to be defined exists (`\renewcommand`) or not +whether the command to be defined exists (''​\renewcommand''​) or not 
-(`\newcommand`), and if its status proves not as the user expected,+(''​\newcommand''​), and if its status proves not as the user expected,
 an error is reported. ​ A third definition command, an error is reported. ​ A third definition command,
-`\providecommand`, only defines if the target is not already +''​\providecommand''​, only defines if the target is not already 
-defined; LaTeX has no direct equivalent of `\def`, which ignores+defined; LaTeX has no direct equivalent of ''​\def''​, which ignores
 the present state of the command. ​ The final command of this sort is the present state of the command. ​ The final command of this sort is
-`\DeclareRobustCommand`, which creates a command which is ''​robust''​ +''​\DeclareRobustCommand''​, which creates a command which is "robust" 
-(i.e., will not expand if subjected to LaTeX ''​protected +(i.e., will not expand if subjected to LaTeX "protected expansion"); 
-expansion''​); from the Plain TeX user's point of view, +from the Plain TeX user's point of view, 
-`\DeclareRobustCommandshould be treated as a non-checking version +''​\DeclareRobustCommand'' ​should be treated as a non-checking version 
-of `\newcommand`.+of ''​\newcommand''​.
  
-LaTeX commands are, by default, defined ​`\long`; an optional ​`*` +LaTeX commands are, by default, defined ​''​\long''​; an optional ​''​*''​ 
-between the `\newcommandand its (other) arguments specifies that +between the ''​\newcommand'' ​and its (other) arguments specifies that 
-the command is _not_ to be defined ​`\long`.  The `*is +the command is //​not// ​to be defined ​''​\long''​.  The ''​*'' ​is 
-detected by a command ​`ifstarwhich uses `\futureletto switch +detected by a command ​''​ifstar'' ​which uses ''​\futurelet'' ​to switch 
-between two branches, and gobbles the `*`: LaTeX users are +between two branches, and gobbles the ''​*''​: LaTeX users are 
-encouraged to think of the `*as part of the command name.+encouraged to think of the ''​*'' ​as part of the command name.
  
-LaTeX'​s checks for unknown command are done by `\ifxcomparison +LaTeX'​s checks for unknown command are done by ''​\ifx'' ​comparison 
-of a `\csnameconstruction with `\relax`; since the command name+of a ''​\csname'' ​construction with ''​\relax''​; since the command name
 argument is the desired control sequence name, this proves a little argument is the desired control sequence name, this proves a little
-long-winded. ​ Since `#1is the requisite argument, we have: +long-winded. ​ Since ''​#1'' ​is the requisite argument, we have: 
-```latex+ 
 +<​code ​latex>
 \expandafter\ifx \expandafter\ifx
   \csname\expandafter\@gobble\string#​1\endcsname   \csname\expandafter\@gobble\string#​1\endcsname
   \relax   \relax
     ...     ...
-``` +</​code>​ 
-(`gobblesimply throws away its argument).+(''​\@gobble'' ​simply throws away its argument).
  
 The arguments of a LaTeX command are specified by two optional The arguments of a LaTeX command are specified by two optional
-arguments to the defining command: a count of arguments (0&ndash;9: if the+arguments to the defining command: a count of arguments (0--9: if the
 count is 0, the optional count argument may be omitted), and a default count is 0, the optional count argument may be omitted), and a default
 value for the first argument, if the defined command'​s first argument value for the first argument, if the defined command'​s first argument
 is to be optional. ​ So: is to be optional. ​ So:
-```latex+ 
 +<​code ​latex>
 \newcommand\foo{...} \newcommand\foo{...}
 \newcommand\foo[0]{...} \newcommand\foo[0]{...}
 \newcommand\foo[1]{...#​1...} \newcommand\foo[1]{...#​1...}
 \newcommand\foo[2][boo]{...#​1...#​2...} \newcommand\foo[2][boo]{...#​1...#​2...}
-``` +</​code>​ 
-In the last case, `\foomay be called as `\foo{goodbye}`+In the last case, ''​\foo'' ​may be called as ''​\foo{goodbye}''​
-which is equivalent to `\foo[boo]{goodbye}(employing the+which is equivalent to ''​\foo[boo]{goodbye}'' ​(employing the
 default value given for the first argument), or as default value given for the first argument), or as
-`\foo[hello]{goodbye}(with an explicit first argument).+''​\foo[hello]{goodbye}'' ​(with an explicit first argument).
  
 Coding of commands with optional arguments is exemplified by the Coding of commands with optional arguments is exemplified by the
-coding of the last `\fooabove: +coding of the last ''​\foo'' ​above: 
-<!-- {% raw %} --> + 
-```latex+ 
 +<​code ​latex>
 \def\foo{\futurelet\next\@r@foo} \def\foo{\futurelet\next\@r@foo}
 \def\@r@foo{\ifx\next[% \def\@r@foo{\ifx\next[%
Ligne 77: Ligne 74:
 } }
 \def\@x@foo[#​1]#​2{...#​1...#​2...} \def\@x@foo[#​1]#​2{...#​1...#​2...}
-``` +</code> 
-<!-- {% endraw %} -->+ 
 + 
 + 
 +----
 + 
 +//Source:// [[faquk>FAQ-cvtlatex|Transcribing LaTeX command definitions]]
  
 +{{htmlmetatags>​metatag-keywords=(LaTeX,​programming)
 +metatag-og:​title=(Transcribing LaTeX command definitions)
 +metatag-og:​site_name=(FAQ LaTeX francophone)
 +}}
  
2_programmation/macros/def_newcommand_providecommand.1527238586.txt.gz · Dernière modification: 2018/05/25 10:56 par joseph.wright
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0