![如何在 \DeclareRobustCommand 中使用 \cite](https://linux22.com/image/367314/%E5%A6%82%E4%BD%95%E5%9C%A8%20%5CDeclareRobustCommand%20%E4%B8%AD%E4%BD%BF%E7%94%A8%20%5Ccite.png)
我如何使用\cite
?\DeclareRobustCommand
我正在使用\DeclareRobustCommand
包创建两种突出显示文本的方法soul
。例如,这是我在文档标题中的内容:
\definecolor{electricgreen}{rgb}{0.0, 1.0, 0.0}
\DeclareRobustCommand{\hlyg}[1]{{\sethlcolor{electricgreen}\hl{#1}}}
\DeclareRobustCommand{\hly}[1]{{\sethlcolor{yellow}\hl{#1}}}
当我像这样使用这些命令时,它有效:
\hlyg{This is my text here}
但是,当我使用这些命令时\cite
,它会失败并引发以下错误:
\hlyg{This is~\cite{someone} my text here}
这是我使用 Miktex 2.9 编译文档时出现的错误:
template.tex
191
Argument of \@citex has an extra }.
<inserted text>
\par
l.191 ...ct and limitations on larger scenarios. }
这是一个 MWE
\documentclass{article}
\usepackage{color}
\usepackage{soul}
\definecolor{electricgreen}{rgb}{0.0, 1.0, 0.0}
\DeclareRobustCommand{\hly}[1]{{\sethlcolor{yellow}\hl{#1}}}
\DeclareRobustCommand{\hlyg}[1]{{\sethlcolor{electricgreen}\hl{#1}}}
\begin{document}
\noindent In order to outline the changes made to the document, the revised
sentences/words are highlighted in two colours:
\begin{enumerate}
\item \hly{Yellow} colour for reviewer 1's comments.
\item \hlyg{Green} colour for reviewer 2's comments.
\end{enumerate}
\\hly{Lorem Ipsum~\cite{lipsum} is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum}
\begin{thebibliography}{9}
\bibitem{lipsum}
Lorem Ipsum
\\\texttt{https://www.lipsum.com/}
\end{thebibliography}
\end{document}
答案1
您只需要用括号括起来即可\cite{someone}
。无需将\hlyg
和声明\hly
为强命令,除非您需要在章节标题或说明中使用它们。
\documentclass{article}
\usepackage{soul,xcolor}
\definecolor{electricgreen}{rgb}{0.0, 1.0, 0.0}
\newcommand{\hlyg}[1]{{\sethlcolor{electricgreen}\hl{#1}}}
\newcommand{\hly}[1]{{\sethlcolor{yellow}\hl{#1}}}
\begin{document}
\hlyg{This is my text here}
\hlyg{This is~{\cite{someone}} my text here}
\begin{thebibliography}{1}
\bibitem{someone} A. Uthor, Title, Journal.
\end{thebibliography}
\end{document}
答案2
我在另一篇文章中找到了答案,但基本上 \cite 需要括在花括号中:
\hlyg{This is{~\cite{someone}} my text here}