显示带有自定义字符的宏的定义?

显示带有自定义字符的宏的定义?

考虑以下 MWE:

\documentclass{book}

\usepackage{biblatex}

\begin{document}

\typeout{1.=\meaning\usebibmacro}
\typeout{2.=\meaning\usebibmacro{name:first-last}}

\makeatletter
\typeout{3.=\meaning\abx@macro@name:first-last}

\typeout{4.=\meaning \csname abx@macro@name:first-last \endcsname}
\typeout{5.=\expandafter\meaning \csname abx@macro@name:first-last \endcsname}
\typeout{6.=\expandafter\expandafter\expandafter\meaning \csname abx@macro@name:first-last \endcsname}
\makeatother

\end{document}

使用 运行此程序pdflatex,结果为:

1.=\protected macro:#1->\ifcsundef {abx@macro@\detokenize {#1}} {\blx@error {Bi
bliography macro '\detokenize {#1}' undefined} {Use '\string \newbibmacro ' to 
define this macro}} {\csuse {abx@macro@\detokenize {#1}}}

2.=\protected macro:#1->\ifcsundef {abx@macro@\detokenize {#1}} {\blx@error {Bi
bliography macro '\detokenize {#1}' undefined} {Use '\string \newbibmacro ' to 
define this macro}} {\csuse {abx@macro@\detokenize {#1}}}{name:first-last}

3.=undefined:first-last

4.=\csnameabx@macro@name:first-last \endcsname 

5.=\relax

6.=\relax

...也就是说,我能最接近的定义\abx@macro@name:first-last\relax;但我很确定事实并非如此,因为:

即使\abx@macro@name:first-last没有按照该名称逐字定义biblatex.sty,看看texdef报告的内容:

$ texdef -t latex -c book -p biblatex abx@macro@name:first-last  -f
\abx@macro@name:first-last first defined in "biblatex.sty".

\abx@macro@name:first-last:
macro:#1#2#3#4->\usebibmacro {name:delim}{#2#3#1}\usebibmacro {name:hook}{#2#3#1}\ifblank {#2}{}{\mkbibnamefirst {#2}\isdot \bibnamedelimd }\ifblank {#3}{}{\mkbibnameprefix {#3}\isdot \ifpunctmark {'} {} {\ifuseprefix {\bibnamedelimc }{\bibnamedelimd }}}\mkbibnamelast {#1}\isdot \ifblank {#4}{}{\bibnamedelimd \mkbibnameaffix {#4}\isdot }

...这正是我所寻找的!

人们可能会认为\protect这里(如宏 - 如何查看 \LaTeX 命令的“实现”? - TeX - LaTeX)是合适的——但我看不出\abx@macro@name:first-last是受保护的;我能看到的唯一问题是名称中使用冒号字符(\csname然后应该由/处理endcsname,但事实并非如此)。

有人能指出,如何\abx@macro@name:first-last在 Latex 中列出这个宏(和类似的宏)吗?

答案1

按顺序采取步骤:

  1. 显示 的含义\usebibmacro,这是一个受保护的宏
  2. 与 (1) 完全相同,因为\meaning根本不扩展下一个标记
  3. 显示不存在的宏的含义\abx@macro@name,因为:它不是“字母”
  4. \csname显示(由于(2))的含义
  5. 显示不存在的宏的含义\abx@macro@name:first-last,其中末尾有一个空格
  6. 与 (5) 相同

你想要的是

\expandafter\meaning\csname abx@macro@name:first-last\endcsname

last和之间的空间\endcsname。这给出

macro:#1#2#3#4->\usebibmacro {name:delim}{#2#3#1}\usebibmacro {name:hook}{#2
#3#1}\ifblank {#2}{}{\mkbibnamefirst {#2}\isdot \bibnamedelimd }\ifblank {#3}{}
{\mkbibnameprefix {#3}\isdot \ifpunctmark {'} {} {\ifuseprefix {\bibnamedelimc 
}{\bibnamedelimd }}}\mkbibnamelast {#1}\isdot \ifblank {#4}{}{\bibnamedelimd \m
kbibnameaffix {#4}\isdot }

这与保护无关:您只需要观察空间。

(顺便说一下,在和标准样式biblatex中定义,而不是在 中。)biblatex.defbiblatex.sty

答案2

您的测试编号 5 是最接近的:

\typeout{5.=\expandafter\meaning \csname abx@macro@name:first-last\endcsname}

是正确的(在那之前有一个空格\endcsname是重要的)。

是找到正确标记\expandafter所必需的\meaning;在示例 4 中,您可以简单获得 的含义\csname


从终端编译的以下输入,

\documentclass{book}

\usepackage{biblatex}
\usepackage{xpatch}

\xshowbibmacro{name:first-last}

会给

> \abx@macro@name:first-last=macro:
#1#2#3#4->\usebibmacro {name:delim}{#2#3#1}\usebibmacro {name:hook}{#2#3#1}\ifb
lank {#2}{}{\mkbibnamefirst {#2}\isdot \bibnamedelimd }\ifblank {#3}{}{\mkbibna
meprefix {#3}\isdot \ifpunctmark {'} {} {\ifuseprefix {\bibnamedelimc }{\bibnam
edelimd }}}\mkbibnamelast {#1}\isdot \ifblank {#4}{}{\bibnamedelimd \mkbibnamea
ffix {#4}\isdot }.

xpatch您还可以使用套餐

\xpatchbibmacro
\xpretobibmacro
\xapptobibmacro

它们是的类似物\patchcmd\pretocmd并由\apptocmd提供etoolbox

这些命令的第一个参数是用作 参数的字符串\usebibmacro。没有\xmeaning:这种调试最好从终端进行。

相关内容