为Bibtex的单一Reference添加颜色
论文修改会让你为添加的内容做特殊标记,例如标记为蓝色,如何把新添加的引用变蓝呢?网上各种方法,都不太靠谱,终于找到一个靠谱的方法,这里记录一下。
1. 参考
- 知乎回答。评价:看了半天,不知所云
- tex.stackexchange回答。评价:靠谱、易懂、易实现
2. 实践
myref.bib示例
@article{citeone,
author = {D. de la Fuente and J.G. Castaño and M. Morcillo},
title = {Long-term atmospheric corrosion of zinc},
journal = {Corrosion Science},
volume = {49},
year = {2007},
pages = {1420–1436},
}
@article{citetwo,
author = {Xaver Zorro},
title = {Vampires},
}
主文件修改
在主文件中的合适部位添加下述重点代码即可,其中\newcommand*{\bibitem@citeone}{blue}
和\newcommand*{\bibitem@citetwo}{blue}
代表将citeone
和citetwo
代表的reference标记为蓝色。
\usepackage{color} % 使用color包
\begin{document}
...
\makeatletter % 重点代码区开始 <=======================================================
\let\myorg@bibitem\bibitem
\def\bibitem#1#2\par{%
\@ifundefined{bibitem@#1}{%
\myorg@bibitem{#1}#2\par
}{%
\begingroup
\color{\csname bibitem@#1\endcsname}%
\myorg@bibitem{#1}#2\par
\endgroup
}%
}
\newcommand*{\bibitem@citeone}{blue}
\newcommand*{\bibitem@citetwo}{blue}
\makeatother % 重点代码区结束 <========================================================
...
\bibliographystyle{IEEEtran}
\bibliography{myref.bib} % 你的bib文件
\end{document}
3. 注意事项
注意被修改颜色的引用的名字中不能带有数字,例如:
@article{liu2006toll,
title={Toll-like receptor triggering of a vitamin D-mediated human antimicrobial response},
author={Liu, Philip T and Stenger, Steffen and Li, Huiying and Wenzel, Linda and Tan, Belinda H and Krutzik, Stephan R and Ochoa, Maria Teresa and Schauber, Jürgen and Wu, Kent and Meinken, Christoph and others},
journal={Science},
volume={311},
number={5768},
pages={1770--1773},
year={2006},
publisher={American Association for the Advancement of Science}
}
这里,使用liu2006toll
导致reference不能被着色,可以将其改为toll
:
@article{toll,
title={Toll-like receptor triggering of a vitamin D-mediated human antimicrobial response},
author={Liu, Philip T and Stenger, Steffen and Li, Huiying and Wenzel, Linda and Tan, Belinda H and Krutzik, Stephan R and Ochoa, Maria Teresa and Schauber, Jürgen and Wu, Kent and Meinken, Christoph and others},
journal={Science},
volume={311},
number={5768},
pages={1770--1773},
year={2006},
publisher={American Association for the Advancement of Science}
}
OK,现在就可以起飞了🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫🛫