summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/generic/FAQ-en/html/FAQ-empty.html
blob: 56e0e35b7e86fea325bbb7c0654df8e519ae8147 (plain)
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
37
<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
    &#60;empty case&#62;
  \else
    &#60;non-empty case&#62;
  \fi
}
</pre>
</blockquote><p>
The case where you want to ignore an argument that consists of nothing
but spaces, rather than something completely empty, is more tricky.
It&#8217;s solved in the code fragment <i>ifmtarg</i>, which defines
commands <code>\</code><code>@ifmtarg</code> and <code>\</code><code>@ifnotmtarg</code>, which examine their
first argument, and select (in opposite directions) their second or
third argument.  The package&#8217;s code also appears in the LaTeX
<i>memoir</i> class.
<p/><i>Ifmtarg</i> makes challenging reading; there&#8217;s also a discussion of the
issue in number two of the &#8220;around the bend&#8221; articles by the late
lamented Mike Downes.
<dl>
<dt><tt><i>Around the bend series</i></tt><dd><a href="http://www.tex.ac.uk/tex-archive/info/challenges/aro-bend.zip">info/challenges/aro-bend</a> (or <a href="http://www.tex.ac.uk/tex-archive/info/challenges/aro-bend/">browse the directory</a>)
<dt><tt><i>ifmtarg.sty</i></tt><dd><a href="http://www.tex.ac.uk/tex-archive/macros/latex/contrib/ifmtarg.zip">macros/latex/contrib/ifmtarg</a> (or <a href="http://www.tex.ac.uk/tex-archive/macros/latex/contrib/ifmtarg/">browse the directory</a>)
<dt><tt><i>memoir.cls</i></tt><dd><a href="http://www.tex.ac.uk/tex-archive/macros/latex/contrib/memoir.zip">macros/latex/contrib/memoir</a> (or <a href="http://www.tex.ac.uk/tex-archive/macros/latex/contrib/memoir/">browse the directory</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>