我在论文中定义了这个命令,它运行良好,但当我尝试将其包含在其他文档中时,它不起作用(编译器报告命令未定义)。我忘记定义/包含什么?
\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&%
\ignorespaces
\else
\textcolor{red}{#2}%
\fi
\fi
\else%
\ifx&%
\ignorespaces
\else
#2%
\fi
\fi}
\begin{document}
\correction{a}{b}
\end{document}
答案1
据我所知,删除文本的宏叫做\sout
,而不是\stkout
。
%
请注意,在行尾有几处错误,即在之后=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&%
\ignorespaces
\else
\textcolor{red}{#2}%
\fi
\fi
\else
\ifx&%
\ignorespaces
\else
#2%
\fi
\fi}
\begin{document}
\correction{a}{b}
\end{document}
不过,我更喜欢基于 的方法\newif
。
\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}