根据关键词突出显示参考书目条目

根据关键词突出显示参考书目条目

我想通过更改背景颜色来突出显示特定的参考书目条目。我非常喜欢 moewe 的解决方案这里,但我想通过设置关键字来指定要突出显示哪些条目,而不是突出显示每个第二个条目。

突出显示方法这些答案允许我根据关键字选择参考书目条目,但我只能弄清楚如何使用它来突出显示文本颜色,而不是背景颜色。

有人能建议一种通过改变背景颜色来突出显示具有特定关键字的条目的方法吗(使用链接方法或其他方法)?我使用 Biblatex,但绑定到 bibtex 后端和常规 pdflatex。

谢谢!

这是一个(简单的) MWE:

\documentclass[fontsize=11pt,twoside,numbers=noendperiod]{scrartcl}

\usepackage[
citestyle=numeric,
bibstyle=authoryear,
sorting=none,
,uniquename=false
,uniquelist=false
,backref=false
,block=space
,maxbibnames=99
,maxcitenames=2
,doi=false
,url=false
,date=year
,backend=bibtex
]{biblatex}

\makeatletter
\input{numeric.bbx}
\makeatother

\addbibresource{highlighting.bib}

\begin{document}

\cite{bender-koller-2020-climbing,hovy21biases}

\printbibliography

\end{document}

这是highlighting.bib:


@article{hovy21biases,
  author          = {Dirk Hovy and Shrimai Prabhumoye},
  journal         = {Language and Linguistics Compass},
  number          = {15},
  issue = {8},
  title           = {Five sources of bias in natural language processing},
  year            = {2021},
  doi = {10.1111/lnc3.12432}
}


@inproceedings{bender-koller-2020-climbing,
    title = "Climbing towards {NLU}: {On} meaning, form, and understanding in the {Age} of {Data}",
    author = "Bender, Emily M.  and
      Koller, Alexander",
    booktitle = "Proceedings of the 58th Annual Meeting of the
                  Association for Computational Linguistics (ACL)",
    month = jul,
    year = "2020",
    keywords = {pi},
    url = "https://www.aclweb.org/anthology/2020.acl-main.463",
    doi = "10.18653/v1/2020.acl-main.463",
}

答案1

我们可以复制如何使用 biblatex 为每个第二个参考书目条目的背景着色并只保护用 突出显示的位\ifkeyword{pi}

\documentclass[fontsize=11pt,twoside,numbers=noendperiod]{scrartcl}

\usepackage[
citestyle=numeric,
bibstyle=authoryear,
sorting=none,
,uniquename=false
,uniquelist=false
,backref=false
,block=space
,maxbibnames=99
,maxcitenames=2
,doi=false
,url=false
,date=year
,backend=bibtex
]{biblatex}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usetikzlibrary{calc}

\makeatletter
\input{numeric.bbx}
\makeatother
\setlength{\bibitemsep}{\itemsep}

\newcounter{zebrabibentry}
\newcounter{zebrabibbibenv}

\defbibenvironment{bibliography}
  {\list
     {\ifkeyword{pi}
        {\stepcounter{zebrabibentry}%
         \zebrabibstart{zebrabib-%
           \the\value{zebrabibbibenv}-%
           \the\value{zebrabibentry}}}
        {}%
      \printtext[labelnumberwidth]{%
        \printfield{labelprefix}%
        \printfield{labelnumber}}}
     {\stepcounter{zebrabibbibenv}%
      \setcounter{zebrabibentry}{0}%
      \setlength{\labelwidth}{\labelnumberwidth}%
      \setlength{\leftmargin}{\labelwidth}%
      \setlength{\labelsep}{\biblabelsep}%
      \addtolength{\leftmargin}{\labelsep}%
      \setlength{\itemsep}{\bibitemsep}%
      \setlength{\parsep}{\bibparsep}}%
      \renewcommand*{\makelabel}[1]{\hss##1}}
  {\endlist}
  {\item}

\newcommand*{\zebrabibstart}[2][]{%
  \tikz[remember picture,overlay]
  \draw[line width=1pt,rectangle,
    draw=blue!20,
    fill=blue!10,]
    let \p1=(pic cs:#2) in
    ({0pt,10pt}) node [anchor=base] (#2){} rectangle  (\columnwidth+2pt,\y1-\bibitemsep);%
}

\newcommand\zebrabibend[2][]{%
  \tikz[remember picture with id=#2] \node {#1};}

\renewbibmacro{finentry}{%
  \finentry
  \ifkeyword{pi}
    {\zebrabibend{zebrabib-%
       \the\value{zebrabibbibenv}-%
       \the\value{zebrabibentry}}}
    {}}

\begin{filecontents}{\jobname.bib}
@article{hovy21biases,
  author          = {Dirk Hovy and Shrimai Prabhumoye},
  journal         = {Language and Linguistics Compass},
  number          = {15},
  issue = {8},
  title           = {Five sources of bias in natural language processing},
  year            = {2021},
  doi = {10.1111/lnc3.12432}
}
@inproceedings{bender-koller-2020-climbing,
    title = "Climbing towards {NLU}:
             {On} meaning, form, and understanding in the {Age} of {Data}",
    author = "Bender, Emily M.  and
      Koller, Alexander",
    booktitle = "Proceedings of the 58th Annual Meeting of the
                  Association for Computational Linguistics (ACL)",
    month = jul,
    year = "2020",
    keywords = {pi},
    url = "https://www.aclweb.org/anthology/2020.acl-main.463",
    doi = "10.18653/v1/2020.acl-main.463",
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\autocite{bender-koller-2020-climbing,hovy21biases}

\printbibliography
\end{document}

包含两个条目的参考书目:其中一个已突出显示。

相关内容