我想要的是文本中的引用具有黄色背景( \hly{\cite{A01}} )。 颜色可能是黑色,同样重要的是,上述效果在换行时仍然有效。
梅威瑟:
\documentclass{article}
\usepackage{xcolor,ifthen,filecontents,soul}
\usepackage[authoryear,colon,square]{natbib}
\bibliographystyle{dcu}
\def\refcolor#1#2{\expandafter\xdef\csname#1color\endcsname{#2}}
\refcolor{A01}{green}
\def\setbibcolor#1{%
\expandafter\ifx\csname#1color\endcsname\relax%
\color{black}%
\else%
\color{\csname#1color\endcsname}%
\fi%
}
\makeatletter
\renewcommand\harvarditem[4][]{%
\if\relax#1\relax
\setbibcolor{#4}\bibitem[\setbibcolor{#4}#2(#3)]{#4}%
\else
\bibitem[#1(#3)#2]{#4}%
\fi
}%
\newboolean{highlighted} %Deklaration
\setboolean{highlighted}{true} %Zuweisung
\ifthenelse{\boolean{highlighted}}{
\DeclareRobustCommand{\hly}[1]{{\sethlcolor{yellow}\hl{#1}}}
}
{
\DeclareRobustCommand{\hly}[1]{#1}
}
\makeatother
\begin{filecontents}{mybib1.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha}
}
\end{filecontents}
\begin{document}
\hly{green} \citep{A01} %\hly{\cite{A01}}
\bibliography{mybib1}
\end{document}
先感谢您
保罗
答案1
使用 lualatex 和新的 lua-ul 包,您可以毫无问题地使用 cite 命令的突出显示:
\documentclass{article}
\usepackage{luacolor}
\usepackage{lua-ul}
\usepackage[authoryear,colon,square]{natbib}
\bibliographystyle{dcu}
\DeclareRobustCommand{\hly}[1]{\highLight{#1}}
\begin{filecontents}{mybib1.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha}
}
\end{filecontents}
\begin{document}
\hly{green} \citep{A01} \hly{\cite{A01}}
\bibliography{mybib1}
\end{document}