I am trying to define some macros in which I need an "if" which test contains an argument of the macro. The issue arises when this argument is \vec{<arg>} and the amsmath package is loaded. Here is a minimal working example:
\documentclass{article}
\begin{document}
$\if\vec{x}\empty true\else false\fi$
\end{document}
and here is a minimal non-working example:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\if\vec{x}\empty true\else false\fi$
\end{document}
I would be happy to understand what causes the errors in the definition of vec by the amsmath package, and how to fix it.
To give you more information, I create the macro:
\newcommand*\ifpresent[2]{\expandafter\if#1\empty\else#2\fi}
and I want
$\ifpresent{\ifpresent{x}{a}}{b}$
to write "b", and
$\ifpresent{\ifpresent{}{a}}{b}$
to write nothing.
I also tried:
\newcommand*\ifpresent[2]{\expandafter\ifx#1\empty\else#2\fi}
but in this case
$\ifpresent{\ifpresent{x}{a}}{b}$
gives me the "Extra \else" and "extra \fi" errors.
What I want then is to define macros like
\newcommand\foo[1]{\ifpresent{#1}{foo#1}}
and
\newcommand\bar[1]{\ifpresent{#1}{bar#1}}
such that
\foo{\bar{}}
gives nothing and
\foo{\bar{yeah}}
gives "foobaryeah"
\ifis rather different from what C programmers would expect; it's not really clear what a use case of your\ifpresentmacro should do. – egreg Mar 19 '14 at 13:16\if\relax\detokenize{#1}\relax <true>\else <false>\fi) – Ruben Mar 19 '14 at 13:19\newcommand\ifpresent[2]{\ifx\relax\detokenize{#1}\relax\else#2\fi}but\ifpresent{\ifpresent{}{a}}{b}prints "b", exactly like when I use if. – Val Mar 19 '14 at 14:11