![通过 xstring+etoolbox 使用 biblatex 的 printbibliography 和作者加粗时出现不必要的偏移](https://linux22.com/image/470540/%E9%80%9A%E8%BF%87%20xstring%2Betoolbox%20%E4%BD%BF%E7%94%A8%20biblatex%20%E7%9A%84%20printbibliography%20%E5%92%8C%E4%BD%9C%E8%80%85%E5%8A%A0%E7%B2%97%E6%97%B6%E5%87%BA%E7%8E%B0%E4%B8%8D%E5%BF%85%E8%A6%81%E7%9A%84%E5%81%8F%E7%A7%BB.png)
我正在尝试在出版物列表中加粗我的名字。经过一段令人尴尬的时间/实验后,我通过以下方式获得了一些让我满意的etoolbox
东西xstring
:
\renewcommand{\mkbibnamegiven}[1]{\ifboolexpr{(test {\IfSubStr{\namepartfamily}{Knowles}} and (test {\IfSubStr{\namepartgiven}{David}})}{\mkbibbold{#1}}{#1}}
\renewcommand{\mkbibnamefamily}[1]{\mkbibnamegiven{#1}}
printbibliography
但是,当我执行两次 时,会导致出现奇怪的压痕伪影:
是我使用宏时做错了什么吗?还是这真的是个错误?谢谢!MWE:
\documentclass[10pt, a4paper]{article}
\usepackage{filecontents}
\usepackage[backend=biber]{biblatex}
\begin{filecontents}{test.bib}
@ARTICLE{Isaev2023-ax,
title = "Investigating {RNA} splicing as a source of cellular diversity
using a binomial mixture model",
author = "Isaev, Keren and Knowles, David A",
journal = "bioRxiv",
year = 2023,
Keywords = {Working}
}
@ARTICLE{Brown2023-fm,
title = "MCFA",
author = "Brown†, Brielin C and Knowles†, David A and Lappalainen†, Tuuli",
journal = "Cell Genomics",
year = 2023,
bibbase_note = {†Co-corresponding},
Keywords = {Genetics}
}
\end{filecontents}
\addbibresource{test.bib}
\usepackage{xstring}
\usepackage{etoolbox}
\renewcommand{\mkbibnamegiven}[1]{\ifboolexpr{(test {\IfSubStr{\namepartfamily}{Knowles}} and (test {\IfSubStr{\namepartgiven}{David}})}{\mkbibbold{#1}}{#1}}
\renewcommand{\mkbibnamefamily}[1]{\mkbibnamegiven{#1}}
\begin{document}
\nocite{*}
\printbibliography[title=Journal articles, type=article, keyword=Genetics]
\noindent % doesn't help
\setlength{\parindent}{0pt}
\printbibliography[title=Working, type=article, keyword=Working]
\end{document}
答案1
圆括号内的字符没有正确匹配\ifboolexpr
。不幸的是,etoolbox
并没有对此发出警告,它只是弄乱了周围的排版。
以下 MWE(没有任何圆括号 - 这里不需要它们)按预期工作
\documentclass[10pt, a4paper]{article}
\usepackage[backend=biber]{biblatex}
\usepackage{xstring}
\renewcommand{\mkbibnamegiven}[1]{%
\ifboolexpr{ test {\IfSubStr{\namepartfamily}{Knowles}}
and test {\IfSubStr{\namepartgiven}{David}}}
{\mkbibbold{#1}}
{#1}}
\renewcommand{\mkbibnamefamily}[1]{\mkbibnamegiven{#1}}
\begin{filecontents}{\jobname.bib}
@ARTICLE{Isaev2023-ax,
title = "Investigating {RNA} splicing as a source of cellular diversity
using a binomial mixture model",
author = "Isaev, Keren and Knowles, David A",
journal = "bioRxiv",
year = 2023,
Keywords = {Working}
}
@ARTICLE{Brown2023-fm,
title = "MCFA",
author = "Brown†, Brielin C and Knowles†, David A and Lappalainen†, Tuuli",
journal = "Cell Genomics",
year = 2023,
bibbase_note = {†Co-corresponding},
Keywords = {Genetics}
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{*}
\printbibliography[title=Journal articles, type=article, keyword=Genetics]
\printbibliography[title=Working, type=article, keyword=Working]
\end{document}