# Redefine macro in macro with parameter

I've been trying this for hours now. Probably is something simple I missed...

I have a macro \newcommand{\cf}[1]{\footnote{Cf. #1}} (usage usually \cf{\cite{xx}}). Now I want to extend it, that it remembers which reference I used last, and if it is the same again, does not print the citation but "Ibd." instead.

Thus I modified it like

\newcommand{\cf}[1]{
Cf.
\ifthenelse{\equals{\SVE}{#1}}{%
ibd.}{%
#1
\def\SVE#1
}
}


But that does not work. \SVE remains empty (or however I initialized it first). I experimented a lot till now, putting \expandafters, \noexpands,... around like crazy... But no result.

-- Edit:

Heres the full code copied:

\documentclass{article}

% somewhere in my preamble
\usepackage{ifthen}
\newcommand{\LLfootnoteLastCite}{}
\newcommand\LLfootnoteCite[1]{%
\ifthenelse{\equal{\LLfootnoteLastCite}{#1}}{%
ibd.}{%
#1%
\def\LLfootnoteLastCite{#1}%
}%
}
\newcommand{\LLfootnote}[3]{\footnote{#3~#2\ifx#10\else, S. #1\fi.}}

% the exposed commands
\newcommand{\vgl}[2][0]{\LLfootnote{#1}{\LLfootnoteCite{#2}}{Vgl.}}

% small working example
\begin{document}
This is a\vgl{\cite{Reference}}. And this is the second\vgl{\cite{Reference}}. And this is a third\vgl{\cite{Reference2}}
\end{document}

• Thanks @Christian How "full" should the example be? like containing \documentclass \begin{document}... ? – Alexander Niederklapfer Jun 3 '17 at 18:42
• Exactly -- compilable, but reduced to the real issue – user31729 Jun 3 '17 at 18:45
• @ChristianHupfer \if...\fi is not a group – David Carlisle Jun 3 '17 at 19:26
• Are you aware that many packages for typesetting citations and bibliographies can do this for you? If you use Biblatex/Biber, you can usually just add the relevant option when loading Biblatex, for example. – cfr Jun 3 '17 at 19:31
• @DavidCarlisle: True, I confused it with something different – user31729 Jun 3 '17 at 19:37

\documentclass{article}

\usepackage{ifthen}

\newcommand\SVE{}% initialize

\newcommand{\cf}[1]{%you need this %
Cf.
\ifthenelse{\equal% \equal not \equals
{\SVE}{#1}}{%
ibd.}{%
#1% you need thi s%
\def\SVE{#1}% braces are mandatory for \def
}% you need this %
}
\begin{document}

\cf{aaa} \cf{aaa} \cf{zzz} \cf{zzz}

\end{document}

• So now that's spooky. Your code does exactly what it should, mine looks the same (as far as I can tell) but does not. I edited my original question to show the full code I use... And thanks for your comments, those I actually had already correct in the orginal but messed up when trying to simplify my question. – Alexander Niederklapfer Jun 3 '17 at 20:16
• Probably it has something to do with \cite{...} ? Thats at least what made me try various versions... – Alexander Niederklapfer Jun 3 '17 at 20:20
• @AlexanderNiederklapfer you have edited the question since the answer was posted (which makes the archive hard to follow) but I put comments in my code where it differed from yours. Notably you had a syntax error of missing braces for \def. you can't test \cite with \equal you don't want to test \cite but just the string used as a cite key. – David Carlisle Jun 3 '17 at 20:39