I use frequently a user defined command to highlight modifications in latex documents.
\providecommand{\ifeqthenelse}[4]{\edef\tempa{#1}\def\tempb{#2}\ifx\tempa\tempb {#3} \else {#4}\fi}
\providecommand{\changed}[5]{{\ifeqthenelse{#3}{#5}{{\color{black}#1}}{\color{#4}#1}}%
{\ifeqthenelse{#3}{#5}{}{\color{grey}\ifeqthenelse{#2}{}{}{(}#2\ifeqthenelse{#2}{}{}{)~}}}%
{\ifeqthenelse{#3}{#5}{}{\ifeqthenelse{#3}{}{}{[}{\it\color{#4}#3}\ifeqthenelse{#3}{}{}{]~}}}}
\providecommand{\mychanged}[3]{\changed{#1}{#2}{#3}{blue}{accept}}
The last command mychanged is actually used when making modifications. Its first argument will be the new text and its second argument the old text. Finally the third argument is used by others to accept my modifications by providing accept. Now I find that the behaviour of mychanged is asymmetric in the first two arguments in the following sense: I can use all kinds of complex latex like equations, citations and references in the first argument, while in the second argument citations and references often lead to latex errors. For this reason I always need to modify the old text. This second argument enters the conditionals of the ifeqthenelse command so I suspect that this is why it does not work. Is there a suitable replacement for ifeqthenelse e.g. a better way to construct a if-then-else conditional which will accept even citations etc. in a string comparison? Note that, preferably, I would like to avoid using packages escpecially if they are not platform/distribution independent.
Here is a full example. It works but stops working if you uncomment the second line in the document enviroment.
\documentclass[a4paper,10pt]{article}
\usepackage{color}
\definecolor{blue}{rgb}{0,0,0.5}
\definecolor{grey}{rgb}{0.5,0.5,0.5}
\providecommand{\ifeqthenelse}[4]{\edef\tempa{#1}\def\tempb{#2}\ifx\tempa\tempb {#3} \else {#4}\fi}
\providecommand{\changed}[5]{{\ifeqthenelse{#3}{#5}{{\color{black}#1}}{\color{#4}#1}}%
{\ifeqthenelse{#3}{#5}{}{\color{grey}\ifeqthenelse{#2}{}{}{(}#2\ifeqthenelse{#2}{}{}{)~}}}%
{\ifeqthenelse{#3}{#5}{}{\ifeqthenelse{#3}{}{}{[}{\it\color{#4}#3}\ifeqthenelse{#3}{}{}{]~}}}}
\providecommand{\mychanged}[3]{\changed{#1}{#2}{#3}{blue}{accept}}
\begin{document}
\section{test}
This is a \mychanged{cite \cite{Fukugita:1986hr}}{}{}.
%This is a \mychanged{}{cite \cite{Fukugita:1986hr}}{}.
\bibliographystyle{apsrev}
\begin{thebibliography}{1}
\expandafter\ifx\csname natexlab\endcsname\relax\def\natexlab#1{#1}\fi
\expandafter\ifx\csname bibnamefont\endcsname\relax
\def\bibnamefont#1{#1}\fi
\expandafter\ifx\csname bibfnamefont\endcsname\relax
\def\bibfnamefont#1{#1}\fi
\expandafter\ifx\csname citenamefont\endcsname\relax
\def\citenamefont#1{#1}\fi
\expandafter\ifx\csname url\endcsname\relax
\def\url#1{\texttt{#1}}\fi
\expandafter\ifx\csname urlprefix\endcsname\relax\def\urlprefix{URL }\fi
\providecommand{\bibinfo}[2]{#2}
\providecommand{\eprint}[2][]{\url{#2}}
\bibitem[{\citenamefont{Fukugita and Yanagida}(1986)}]{Fukugita:1986hr}
\bibinfo{author}{\bibfnamefont{M.}~\bibnamefont{Fukugita}} \bibnamefont{and}
\bibinfo{author}{\bibfnamefont{T.}~\bibnamefont{Yanagida}},
\bibinfo{journal}{Phys. Lett. B} \textbf{\bibinfo{volume}{174}},
\bibinfo{pages}{45} (\bibinfo{year}{1986}).
\end{thebibliography}
\end{document}
Ilustration for swallowed spaces in current version (there is no space between "a" and "test" but it would be very nice if there was one)
\documentclass[a4paper,10pt]{article}
\usepackage{color}
\definecolor{blue}{rgb}{0,0,0.5}
\definecolor{grey}{rgb}{0.5,0.5,0.5}
\newcommand{\printifnonempty}[2]{\if\relax\detokenize{#1}\relax\else#2\fi}
\newcommand{\changed}[5]{%
\def\temp{#3}%
\def\accept{#5}%
\ifx\temp\accept
#1
\else
\textcolor{#4}{\printifnonempty{#1}{#1}}%
\textcolor{grey}{\printifnonempty{#2}{(#2)}}%
\textcolor{#4}{\printifnonempty{#3}{[#3]}}%
\fi
}
\begin{document}
\section{Test}
This is a\changed{ test}{ old}{comment}{blue}{accept}.
\end{document}
\edef
for\tempa
and\def
for\tempb
. A real "use case" should be good for suggesting some improvement.\edef
into\def
.