I'm trying to understand why the \mymap
function in the following code does not produce any output when called with a variable in a for loop (see \myloop
). It produces output when text is explicitly passed to it. See \myloopb
. Sorry for the simple question, I wasn't able to understand explanations of the \if
and \ifx
statements on stackexchange and other places. If it matters I'm using pdflatex from MikTex on Windows.
\documentclass[12pt]{article}
\usepackage{pgffor}
% define variables
\def\vala{aa}
\def\valb{bb}
% this produces different output depending on #1
\newcommand{\mymap}[1]{
\def\temparg{#1}
\ifx\temparg\vala
Condition 1 is true
\fi
\ifx\temparg\valb
Condition 2 is true
\fi
}
\newcommand{\myloop}{
\foreach \myvar in {\vala,\valb}{
% this does not produce any output
\mymap{\myvar}
}
}
\newcommand{\myloopb}{
% this produces output
\mymap{aa}
\mymap{bb}
}
\begin{document}
\section{Using myloop does not produce output}
% no output
\myloop
\section{Using myloopb produces output}
% produces output
\myloopb
\end{document}
%
to remove the spaces caused by the line endings (see my answer, in which I did that).