File: FAQ-empty.html

package info (click to toggle)
tetex-base 3.0.dfsg.3-5
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 239,540 kB
  • ctags: 10,610
  • sloc: xml: 103,461; perl: 9,398; ruby: 2,850; python: 1,551; php: 1,067; sh: 981; lisp: 494; makefile: 371; awk: 88
file content (36 lines) | stat: -rw-r--r-- 1,995 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<head>
<title>UK TeX FAQ -- question label empty</title>
</head><body>
<h3>Detecting that something is empty</h3>
<p>Suppose you need to know that the argument of your command is empty:
that is, to distinguish between <code>\</code><code>cmd{}</code> 
and <code>\</code><code>cmd{blah}</code>.  This is pretty simple:
<blockquote>
<pre>
\def\cmd#1{%
  \def\tempa{}%
  \def\tempb{#1}%
  \ifx\tempa\tempb
    &lt;empty case&gt;
  \else
    &lt;non-empty case&gt;
  \fi
}
</pre>
</blockquote>
The case where you want to ignore an argument that consists of nothing
but spaces, rather than something completely empty, is more tricky.
It's solved in the code fragment <i>ifmtarg</i>, which defines
commands <code>\</code><code>@ifmtarg</code> and <code>\</code><code>@ifnotmtarg</code>, which distinguish (in
opposite directions) between a second and third argument.  The
package's code also appears in the LaTeX <i>memoir</i> class.
<p><i>Ifmtarg</i> makes challenging reading; there's also a discussion of the
issue in number two of the "around the bend" articles by the late
lamented Mike Downes.
<dl>
<dt><tt><i>Around the bend series</i></tt><dd><a href="ftp://cam.ctan.org/tex-archive/info/aro-bend.tar.gz">info/aro-bend</a> (<a href="ftp://cam.ctan.org/tex-archive/info/aro-bend.zip">zip</a>, <a href="http://www.tex.ac.uk/tex-archive/info/aro-bend/">browse</a>)
<dt><tt><i>ifmtarg.sty</i></tt><dd><a href="ftp://cam.ctan.org/tex-archive/macros/latex/contrib/misc/ifmtarg.sty">macros/latex/contrib/misc/ifmtarg.sty</a>
<dt><tt><i>memoir.cls</i></tt><dd><a href="ftp://cam.ctan.org/tex-archive/macros/latex/contrib/memoir.tar.gz">macros/latex/contrib/memoir</a> (<a href="ftp://cam.ctan.org/tex-archive/macros/latex/contrib/memoir.zip">zip</a>, <a href="http://www.tex.ac.uk/tex-archive/macros/latex/contrib/memoir/">browse</a>)
</dl>
<p><p>This question on the Web: <a href="http://www.tex.ac.uk/cgi-bin/texfaq2html?label=empty">http://www.tex.ac.uk/cgi-bin/texfaq2html?label=empty</a>
</body>