我正在尝试将我的书目条目中的个别名称放入括号中,并尝试使用 (rege)xpatch 功能修补 biblatex bibmacros。
具体来说,我正在尝试修补 bibmacrosname:given-family
和name:family-given
。
据我所知,regexpatch
提供了相同的补丁命令xpatch
,另外还提供了正则表达式功能。而且我无法从文档中了解到 的原始命令的语法有任何变化xpatch
。但是,与 配合regexpatch
使用的补丁xpatch
返回了。MWE:undefined control sequence
regexpatch
\documentclass{article}
\usepackage{xpatch}
%\usepackage{regexpatch}
\usepackage[style=authortitle]{biblatex}
\addbibresource{biblatex-examples.bib}
% These patches work with xpatch, but not with regexpatch
\xpatchbibmacro{name:given-family}
{\usebibmacro{name:hook}}
{\bibopenbracket\usebibmacro{name:hook}}
{}{}
\xapptobibmacro{name:given-family}
{\bibclosebracket}
{}{}
\xpatchbibmacro{name:family-given}
{\usebibmacro{name:hook}{#3#1}}
{\bibopenbracket\usebibmacro{name:hook}{#3#1}}
{}{}
\xpatchbibmacro{name:family-given}
{\usebibmacro{name:hook}{#1}}
{\bibopenbracket\usebibmacro{name:hook}{#1}}
{}{}
\xapptobibmacro{name:family-given}
{\bibclosebracket}
{}{}
\begin{document}
\nocite{*}
\printbibliography
\end{document}
我遗漏了什么或者做错了什么?
注意:我需要其他真正需要正则表达式功能的补丁,并且如果可能的话,为了代码的可读性,regexpatch
我愿意使用原始补丁命令。xpatch
答案1
您发现了一个隐藏的功能。;-)
这应该可以解决这个暂时的问题。
\documentclass{article}
%\usepackage{xpatch}
\usepackage{regexpatch}
% Fix regexpatch itself
\ExplSyntaxOn
\makeatletter
\exp_args:Nc \xpatchcmd { xpatchbibmacro~code }
{\xpatch_main:Ncnnnn}
{\xpatch_main_four:Ncnnnn}
{}{}
\makeatother
\ExplSyntaxOff
\usepackage[style=authortitle]{biblatex}
\addbibresource{biblatex-examples.bib}
% These patches work with xpatch, but not with regexpatch
\xpatchbibmacro{name:given-family}
{\usebibmacro{name:hook}}
{\bibopenbracket\usebibmacro{name:hook}}
{}{}
\xapptobibmacro{name:given-family}
{\bibclosebracket}
{}{}
\xpatchbibmacro{name:family-given}
{\usebibmacro{name:hook}{#3#1}}
{\bibopenbracket\usebibmacro{name:hook}{#3#1}}
{}{}
\xpatchbibmacro{name:family-given}
{\usebibmacro{name:hook}{#1}}
{\bibopenbracket\usebibmacro{name:hook}{#1}}
{}{}
\xapptobibmacro{name:family-given}
{\bibclosebracket}
{}{}
\begin{document}
\nocite{*}
\printbibliography
\end{document}