[英]How can I highlight `\cite` (linebreak preserving) in latex
How can I highlight (set a background color) \cite
(linebreak preserving) like this: [1]
我怎样才能像这样突出显示(设置背景颜色) \cite
(保留换行符): [1]
I got a compile error when I tried \hl
in the package soul
like:当我在 package soul
中尝试\hl
时出现编译错误,例如:
\hl{\cite{xxx}}
\mobx
can fix this but doesn't support line break. \mobx
可以解决这个问题,但不支持换行符。
I also tried \colorbox
and \newcommand\hl{\bgroup\markoverwith {\textcolor{GhostWhite}{\rule[-.5ex]{2pt}{2.5ex}}}\ULon}
, but they do not support line break either.我也试过\colorbox
和\newcommand\hl{\bgroup\markoverwith {\textcolor{GhostWhite}{\rule[-.5ex]{2pt}{2.5ex}}}\ULon}
,但它们也不支持换行符.
main.tex: main.tex:
\documentclass{article}
\usepackage{soul}
\begin{document}
\hl{{\cite{c1, c2, c3}}}
\bibliographystyle{plain}
\bibliography{ref}
\end{document}
ref.bib:参考书目:
@book{c1,
...
}
@book{c2,
...
}
@book{c3,
...
}
\cite
突出显示\cite
的正确方法是什么 Wrap the \cite
macro into an additional group of curly brackets:将\cite
宏包装到另一组花括号中:
\documentclass{article}
\begin{filecontents*}[overwrite]{\jobname.bib}
@book{knuth,
author = {Knuth, Donald E.},
title = {The {\TeX} book},
date = 1984,
maintitle = {Computers \& Typesetting},
volume = {A},
publisher = {Addison-Wesley},
location = {Reading, Mass.},
langid = {english},
langidopts = {variant=american},
sortyear = {1984-1},
sorttitle = {Computers & Typesetting A},
indexsorttitle= {The TeXbook},
indextitle = {\protect\TeX book, The},
shorttitle = {\TeX book}
}
\end{filecontents*}
\usepackage{soul}
\begin{document}
\hl{{\cite{knuth}}}
\bibliographystyle{plain}
\bibliography{\jobname}
\end{document}
For multiple citation, one could either wrap them in an \mbox{...}
(this will lose the ability to have line breaks), or use lualatex instead:对于多次引用,可以将它们包装在\mbox{...}
中(这将失去换行的能力),或者使用 lualatex 代替:
% !TeX TS-program = lualatex
\documentclass{article}
\usepackage{lua-ul,luacolor}
\begin{filecontents*}[overwrite]{\jobname.bib}
@book{c1,
...
}
@book{c2,
...
}
@book{c3,
...
}
\end{filecontents*}
\begin{document}
\underLine{\cite{c1, c2, c3}}
\highLight{\cite{c1, c2, c3}}
\bibliographystyle{plain}
\bibliography{\jobname}
\end{document}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.