Generalifmtarg; can't reproduce examples in documentation

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
leo simon
Posts: 17
Joined: Wed Aug 19, 2009 5:41 pm

ifmtarg; can't reproduce examples in documentation

Post by leo simon »

Hi, I'm trying to get ifmtarg to work. In desparation, I tried simply to recreate the examples given in the documentation, i.e., in

ftp://ftp.dante.de/tex-archive/macros/l ... fmtarg.pdf

The following code is cribbed almost verbatim from the above document, except that I had to add \makeatletter and \makeatother to get it to compile without error. Also, the only way I could get the code to compile was to define the macros *after* \begin{document}, which seems to be the reverse of what one is supposed to do. Anyway, the code below compiles, but gives nonsense output. Could anybody please advise?

Code: Select all

\documentclass{article}
\usepackage{ifmtarg}
\begin{document}
\makeatletter
\newcommand{\isempty}{1}{%
\@ifmtarg{#1}{YES}{NO}}
\newcommand{\isnotempty}[1]{%
\@ifnotmtarg{#1}{YES}}
\makeatother
Output from these macros:\\
This line should return YES but returns \isempty{} \\
This line should return YES but returns \isempty{ } \\
This line should return NO but returns \isempty{E} \\
This line should return NO but returns \isempty{ E } \\
This line should return NO but returns \isnotempty{} \\
This line should return YES but returns \isnotempty{E} \\
\end{document}
The output I get when I compile this is:
NO
Output from these macros:
This line should return YES but returns 1
This line should return YES but returns 1
This line should return NO but returns 1E
This line should return NO but returns 1 E
This line should return NO but returns
This line should return YES but returns YES
i.e., I'm zero for 6, and in addition, there's the NO that's printed out, presumably coming from my definition of \isempty. I presume that the NO problem is related to all the others, but, as I said, I copied pretty much verbatim from the documentation.

Thanks very much advance for any help!

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

ifmtarg; can't reproduce examples in documentation

Post by Johannes_B »

Look closer at the definition of your macros, the first is defined to print the number 1 (one) and then the argument you are giving. There is a small type in the manual, that's why that is a bit confusing. I admit that ;-)

By the way, if you just need to know if something is empty or not, the package might suit you just right. If you need more, you might want to take a look at package etoolbox. It provides a lot of stuff useful for package authors.

Code: Select all

\documentclass{article}
\usepackage{ifmtarg}
\makeatletter
\newcommand{\isempty}[1]{%
	\@ifmtarg{#1}{YES}{NO}%
}
\newcommand{\isnotempty}[1]{%
	\@ifnotmtarg{#1}{YES}
}
\makeatother
\begin{document}
Output from these macros:\\
This line should return YES but returns \isempty{} \\
This line should return YES but returns \isempty{ } \\
This line should return NO but returns \isempty{E} \\
This line should return NO but returns \isempty{ E } \\
This line should return NO but returns \isnotempty{} \\
This line should return YES but returns \isnotempty{E} \\
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
leo simon
Posts: 17
Joined: Wed Aug 19, 2009 5:41 pm

Re: ifmtarg; can't reproduce examples in documentation

Post by leo simon »

Thanks very much, Johannes for your superfast reply. I *was* wondering about the {1} vs [1] thing. I need the \ifmtarg command for something a good bit more complicated, but got completely stuck trying to get past square one.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

ifmtarg; can't reproduce examples in documentation

Post by Johannes_B »

All you need in those situations is a fresh set of eyes. You could have paused for half a day and would have seen it yourself, i am sure.


As i said, etoolbox has a lot of useful commands, such as \ifdefempty, ifcsempty, ifstrempty, ifblank, and may many more stuff.



btw, the maintainer has a git-rep where all the packages are sitting. THe typo was fixed there about five years ago, but apparently the fix never reached CTAN.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply