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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

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