summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/generic/FAQ-en/html/FAQ-cvtlatex.html
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2009-05-22 23:51:44 +0000
committerKarl Berry <karl@freefriends.org>2009-05-22 23:51:44 +0000
commit566f5207d7e3cafb0633d31277067336ccd9cca7 (patch)
tree7af53e7ac405185168bc1dc38c4e820f442b78d0 /Master/texmf-dist/doc/generic/FAQ-en/html/FAQ-cvtlatex.html
parentb0beea26ffffd915bb6d9b82f2d65a0a05b7e23b (diff)
move generic english documents out of texmf-doc
git-svn-id: svn://tug.org/texlive/trunk@13396 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/generic/FAQ-en/html/FAQ-cvtlatex.html')
-rw-r--r--Master/texmf-dist/doc/generic/FAQ-en/html/FAQ-cvtlatex.html77
1 files changed, 77 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/generic/FAQ-en/html/FAQ-cvtlatex.html b/Master/texmf-dist/doc/generic/FAQ-en/html/FAQ-cvtlatex.html
new file mode 100644
index 00000000000..cdaf84cfbbf
--- /dev/null
+++ b/Master/texmf-dist/doc/generic/FAQ-en/html/FAQ-cvtlatex.html
@@ -0,0 +1,77 @@
+<head>
+<title>UK TeX FAQ -- question label cvtlatex</title>
+</head><body>
+<h3>Transcribing LaTeX command definitions</h3>
+<p/>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.
+<p/>The reason LaTeX has commands that replace <code>\</code><code>def</code>, is that
+there&rsquo;s a general philosophy within LaTeX that the user should be
+protected from himself: the user has different commands according to
+whether the command to be defined exists (<code>\</code><code>renewcommand</code>) or not
+(<code>\</code><code>newcommand</code>), and if its status proves not as the user expected,
+an error is reported. A third definition command,
+<code>\</code><code>providecommand</code>, only defines if the target is not already
+defined; LaTeX has no direct equivalent of <code>\</code><code>def</code>, which ignores
+the present state of the command. The final command of this sort is
+<code>\</code><code>DeclareRobustCommand</code>, which creates a command which is &ldquo;robust&rdquo;
+(i.e., will not expand if subjected to LaTeX &ldquo;protected
+expansion&rdquo;); from the Plain TeX user&rsquo;s point of view,
+<code>\</code><code>DeclareRobustCommand</code> should be treated as a non-checking version
+of <code>\</code><code>newcommand</code>.
+<p/>LaTeX commands are, by default, defined <code>\</code><code>long</code>; an optional <code>*</code>
+between the <code>\</code><code>newcommand</code> and its (other) arguments specifies that
+the command is <em>not</em> to be defined <code>\</code><code>long</code>. The <code>*</code> is
+detected by a command <code>\</code><code>@ifstar</code> which uses <code>\</code><code>futurelet</code> to switch
+between two branches, and gobbles the <code>*</code>: LaTeX users are
+encouraged to think of the <code>*</code> as part of the command name.
+<p/>LaTeX&rsquo;s checks for unknown command are done by <code>\</code><code>ifx</code> comparison
+of a <code>\</code><code>csname</code> construction with <code>\</code><code>relax</code>; since the command name
+argument is the desired control sequence name, this proves a little
+long-winded. Since <code>#1</code> is the requisite argument, we have:
+<blockquote>
+
+<pre>
+\expandafter\ifx
+ \csname\expandafter\@gobble\string#1\endcsname
+ \relax
+ ...
+</pre>
+</blockquote><p>
+(<code>\</code><code>@gobble</code> simply throws away its argument).
+<p/>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
+count is 0, the optional count argument may be omitted), and a default
+value for the first argument, if the defined command&rsquo;s first argument
+is to be optional. So:
+<blockquote>
+<pre>
+\newcommand\foo{...}
+\newcommand\foo[0]{...}
+\newcommand\foo[1]{...#1...}
+\newcommand\foo[2][boo]{...#1...#2...}
+</pre>
+</blockquote><p>
+In the last case, <code>\</code><code>foo</code> may be called as <code>\</code><code>foo{goodbye}</code>,
+which is equivalent to <code>\</code><code>foo[boo]{goodbye}</code> (employing the
+default value given for the first argument), or as
+<code>\</code><code>foo[hello]{goodbye}</code> (with an explicit first argument).
+<p/>Coding of commands with optional arguments is exemplified by the
+coding of the last <code>\</code><code>foo</code> above:
+<blockquote>
+<pre>
+\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...}
+</pre>
+</blockquote><p>
+<p/><p>This question on the Web: <a href="http://www.tex.ac.uk/cgi-bin/texfaq2html?label=cvtlatex">http://www.tex.ac.uk/cgi-bin/texfaq2html?label=cvtlatex</a>
+</body>