Generalifmtarg | Unexpected Behaviour

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
mojo
Posts: 7
Joined: Sat Feb 26, 2011 5:19 am

ifmtarg | Unexpected Behaviour

Post by mojo »

This is almost certainly a limitation of the user, but I can't get the ifmtarg to do what I expect.

I have a macro that adds some text to its arg. I'd like for the macro to output nothing if the arg is empty.

Something like

Code: Select all

\newcommand{\hexaddr}[1]{%
\texttt{\#0#1h}%
}
I'd like to avoid having "#0h" emitted when the arg is empty.

It sounds like ifmtarg should do the trick, but it doesn't work for me.

Here's a simplistic example, using code in the ifmtarg docs:

Code: Select all

\documentclass{article}
\usepackage{ifmtarg}
\newcommand{\isempty}[1]{%
  \@ifmtarg{#1}{YES}{NO}}

\begin{document}
Should be empty: \isempty{}

Not empty: \isempty{notempty}
\end{document}
The result looks like:
Should be empty: ifmtargYESNO
Not empty: ifmtargnotemptyYESNO
I'm using pdflatex on a typical MiKTeX 2.9 install.

Clearly, I'm not using the package correctly. Can someone help me understand what I'm doing wrong?
Thanks.


todd.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

ifmtarg | Unexpected Behaviour

Post by josephwright »

You need to make @ a 'letter' to access code internals:

Code: Select all

\documentclass{article}
\usepackage{ifmtarg}
\makeatletter
\newcommand{\isempty}[1]{%
  \@ifmtarg{#1}{YES}{NO}}
\makeatother

\begin{document}
Should be empty: \isempty{}

Not empty: \isempty{notempty}
\end{document}
Joseph Wright
mojo
Posts: 7
Joined: Sat Feb 26, 2011 5:19 am

Re: ifmtarg | Unexpected Behaviour

Post by mojo »

Excellent! Thanks.
Post Reply