1

I have this command defined in my thesis and it works fine, but when I try to include it in some other document it doesn't work (compiler reports the command is not defined). What do I forget to define/include ?

\documentclass{article}
\usepackage[normalem]{ulem}
\usepackage{xcolor}

\def\revisionHighlight{True}
\def\revisionHighlightOld{True}

\newcommand{\correction}[2]{% old word, new word
\ifnum\pdfstrcmp{\revisionHighlight}{True}=0%
    \ifnum\pdfstrcmp{\revisionHighlightOld}{True}=0%
        \stkout{#1}\textcolor{red}{#2}%
    \else%
        \ifx&#2&%
            \ignorespaces
        \else
            \textcolor{red}{#2}%
        \fi
    \fi
\else%
    \ifx&#2&%
        \ignorespaces
    \else
        #2%
    \fi
\fi}

\begin{document}
\correction{a}{b}
\end{document}
1

As far as I know, the macro for striking out text is called \sout, not \stkout.

Note you have a couple of bad % at the end of lines, namely after =0.

\documentclass{article}
\usepackage[normalem]{ulem}
\usepackage{xcolor}

\def\revisionHighlight{True}
\def\revisionHighlightOld{True}

\newcommand{\correction}[2]{% old word, new word
\ifnum\pdfstrcmp{\revisionHighlight}{True}=0
    \ifnum\pdfstrcmp{\revisionHighlightOld}{True}=0
        \sout{#1}\textcolor{red}{#2}%
    \else
        \ifx&#2&%
            \ignorespaces
        \else
            \textcolor{red}{#2}%
        \fi
    \fi
\else
    \ifx&#2&%
        \ignorespaces
    \else
        #2%
    \fi
\fi}

\begin{document}
\correction{a}{b}
\end{document}

enter image description here

I'd prefer an approach based on \newif, though.

\documentclass{article}
\usepackage[normalem]{ulem}
\usepackage{xcolor}

\newif\ifrevisionHighlight
\revisionHighlighttrue
\newif\ifrevisionHighlightOld
\revisionHighlightOldtrue


\newcommand{\correction}[2]{% old word, new word
  \ifrevisionHighlight
    \ifrevisionHighlightOld
        \sout{#1}\textcolor{red}{#2}%
    \else
        \if\relax\detokenize{#2}\relax
            \ignorespaces
        \else
            \textcolor{red}{#2}%
        \fi
    \fi
\else
    \if\relax\detokenize{#2}\relax
        \ignorespaces
    \else
        #2%
    \fi
\fi}

\begin{document}
\correction{a}{b}
\end{document}
  • The macro for striking out depends on which package you use. I have used \stkout instead of \sout (if I remember right) because it works also in math mode. Your code works, thank you, but I would like to understand why mine does not ... – dario Apr 16 '17 at 10:50
  • Furthermore I had to add the % characters on purpose to avoid some funny spacing effect in the case that any of the 2 parameters is not given – dario Apr 16 '17 at 10:59
  • @dario In your example you only loaded ulem, if you think \stkout is defined by some other package, then you need to load that package. It might even be defined by the class you used for your thesis, assuming you used some custom class. – Torbjørn T. Apr 16 '17 at 11:02
  • I am an idiot. I was convinced \stkout came with ulem but I have defined that. Solved – dario Apr 16 '17 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.