Ceci est une ancienne révision du document !

— section: Macro programming subsection: Generic macros and techniques permalink: /FAQ-cvtlatex.html date: 2014-06-10 —

# Transcribing LaTeX command definitions

At several places in this FAQ, questions are answered in terms of how to program a LaTeX macro. Sometimes, these macros might also help users of Plain TeX or other packages; this answer attempts to provide a rough-and-ready guide to transcribing such macro definitions for use in other packages.


LaTeX commands are, by default, defined \long; an optional * between the \newcommand and its (other) arguments specifies that the command is _not_ to be defined \long. The * is detected by a command ifstar which uses \futurelet to switch between two branches, and gobbles the *: LaTeX users are encouraged to think of the * as part of the command name.

LaTeX's checks for unknown command are done by \ifx comparison of a \csname construction with \relax; since the command name argument is the desired control sequence name, this proves a little long-winded. Since #1 is the requisite argument, we have: latex \expandafter\ifx

\csname\expandafter\@gobble\string#1\endcsname
\relax
...

 (gobble simply throws away its argument).


Coding of commands with optional arguments is exemplified by the coding of the last \foo above: <!– {% raw %} –> latex \def\foo{\futurelet\next\@r@foo} \def\@r@foo{\ifx\next[%

  \let\next\@x@foo
\else
\def\next{\@x@foo[boo]}%
\fi
\next

} \def\@x@foo[#1]#2{…#1…#2…}  <!– {% endraw %} –>

2_programmation/macros/def_newcommand_providecommand.1527181638.txt.gz · Dernière modification: 2018/05/24 17:07 de joseph.wright