Biblatex:彩色方括号内的彩色上标引​​用

Biblatex:彩色方括号内的彩色上标引​​用

我正在使用 Overleaf 撰写报告,并附带biblatex引文管理软件包。

我想在方括号内添加上标引用。整个引用(包括文本和括号)应为彩色,如图所示。

所需引用格式的示例。

根据其他地方的代码,我获得了括号中的上标引用,但我只能给文本上色,而不能给括号上色。见下图。

在此处输入图片描述

MWE 如下所示:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[svgnames]{xcolor}
\usepackage{hyperref}
\hypersetup
{
colorlinks=true,
citecolor={blue},
citebordercolor={blue}
}
\usepackage[
backend=biber,
style=nature]{biblatex}

%This part is to colorize the brackets%
\DeclareCiteCommand{\cite}[\color{blue}\mkbibbrackets]
  {\usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}%
   \usebibmacro{postnote}}

%This part is to put brackets around the supercitation%   
\DeclareCiteCommand{\supercite}[\mkbibsuperscript]
  {\usebibmacro{cite:init}%
   \let\multicitedelim=\supercitedelim
   \iffieldundef{prenote}
     {}
     {\BibliographyWarning{Ignoring prenote argument}}%
   \iffieldundef{postnote}
     {}
     {\BibliographyWarning{Ignoring postnote argument}}%
  \bibopenbracket}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}\bibclosebracket}

\addbibresource{sample.bib}


\begin{document}

\section{First section}

Normal cite has colorized text and brackets.\cite{einstein} Supercite only has colorized text.\supercite{dirac}

\printbibliography[
heading=bibintoc,
title={Bibliography}
]

\end{document}

我是 LaTeX 的新手,因此欢迎任何建议。

答案1

引文之所以被着色,是因为它们相互关联。对于引文周围的括号,如果括号中有多个引文,则不太清楚它们应该链接到哪里。可以将括号链接到以下或之前的引文,但由于底层引文样式相当numeric-comp复杂,因此需要大量代码。因此,我坚持为括号着色而不链接它们。

\color{blue}这个想法是通过引用周围的包装器(方括号中的命令)以某种方式插入\DeclareCiteCommand

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[svgnames]{xcolor}

\usepackage[
backend=biber,
style=nature]{biblatex}

\usepackage{hyperref}

\hypersetup{
  colorlinks=true,
  citecolor={blue},
  citebordercolor={blue},
}

%This part is to colorize the brackets%
\DeclareCiteCommand{\cite}[\color{blue}\mkbibbrackets]
  {\usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}%
   \usebibmacro{postnote}}

\newrobustcmd{\mkbibcoloursuperscript}[2]{%
  \unspace\allowhyphens\textsuperscript{%
    \begingroup
    \protected\long\def\mkbibsuperscript##1{%
      \blx@warning{Nested superscript}%
      \mkbibbrackets{##1}}%
    \color{#1}%
    #2\endgroup}}

%This part is to put brackets around the supercitation%   
\DeclareCiteCommand{\supercite}[\mkbibcoloursuperscript{blue}]
  {\usebibmacro{cite:init}%
   \let\multicitedelim=\supercitedelim
   \iffieldundef{prenote}
     {}
     {\BibliographyWarning{Ignoring prenote argument}}%
   \iffieldundef{postnote}
     {}
     {\BibliographyWarning{Ignoring postnote argument}}%
  \bibopenbracket}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}\bibclosebracket}

\addbibresource{biblatex-examples.bib}


\begin{document}

Normal cite has colorized text and brackets.\cite{sigfridsson}

Supercite only has colorized text.\supercite{nussbaum}

\printbibliography[
heading=bibintoc,
title={Bibliography}
]
\end{document}

全彩色的引文。

相关内容