按照此线natbib
我尝试使用和更改文档的引用颜色
biblatex
\documentclass{article}
\usepackage{xcolor}
\usepackage{hyperref}
\hypersetup{colorlinks=true,
citecolor=red}
\usepackage[natbib=true]{biblatex}
\addbibresource{test.bib}
\newcommand\colcitep[2]{\hypersetup{citecolor=#1}\citep{#2}}
\begin{document}
The first reference should be in red \citep{dupont_2007}\par
The second reference should be in blue \colcitep{blue}{dupont_2007}\par
\hypersetup{citecolor=blue}
The third reference is OK in blue \citep{dupont_2007}\par
\printbibliography
\end{document}
测试文件
@article{dupont_2007,
title = {test title},
author = {Dupont},
date = {2007},
journaltitle = {dummy title},
shortjournal = {Short. dummy.},
volume = {64},
number = {7},
pages = {1402--1413},
}
这是使用 xelatex、biber 和 xelatex 运行的。
程序以某种方式在引用前插入一些空格
Package biblatex Warning: The following entry could not be found
(biblatex) in the database:
(biblatex) ‌​dupont_2007
(biblatex) Please verify the spelling and rerun
(biblatex) LaTeX afterwards.
这线似乎表明 newcommand 可能会插入空格,但使用 xspace 并不能解决问题。似乎有一些字符是由 newcommand 插入的。我应该使用什么正确的语法来避免这种情况?
答案1
#2
行前有一些不可见的字符\newcommand
。如果我将定义主体粘贴到转换器中,我会看到
\hypersetup{citecolor=#1}\citep{U+200CU+200B#2}
而您收到的警告应该会引起怀疑。
删除两个错误的字符;最好重新输入该行。
接下来,添加\begingroup
和\endgroup
以定位颜色变化。
\begin{filecontents*}{\jobname.bib}
@article{dupont_2007,
title = {test title},
author = {Dupont},
date = {2007},
journaltitle = {dummy title},
shortjournal = {Short. dummy.},
volume = {64},
number = {7},
pages = {1402--1413},
}
\end{filecontents*}
\documentclass{article}
\usepackage{xcolor}
\usepackage[natbib=true]{biblatex}
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
citecolor=red
}
\addbibresource{\jobname.bib}
\newcommand\colcitep[2]{\begingroup\hypersetup{citecolor=#1}\citep{#2}\endgroup}
\begin{document}
The first reference should be in red \citep{dupont_2007}
The second reference should be in blue \colcitep{green}{dupont_2007}
The third reference is OK in blue \citep{dupont_2007}
\printbibliography
\end{document}
我使用该filecontents*
环境只是为了使示例自成一体。