如何扩展论点#1?

如何扩展论点#1?

#1如果我像这样使用它,这个论点就会得到很好的扩展:

\DeclareFieldFormat{file}
                   {#1}

但是,如果我像这样使用它:

\usepackage{xstring}

\DeclareFieldFormat{file}
                   {\StrBetween[1,2]{#1}{:}{:}}

然后,\StrBetween宏将应用于文字字符串#1,而不是#1“指向”的内容。我想知道:

  1. 为什么会这样?
  2. 我怎样才能“取消引用” #1

编辑:

这是我想要实现的一个最小工作示例:

\documentclass{article}
\usepackage{filecontents}
\usepackage{xstring}
\usepackage{biblatex}

\begin{filecontents}{jobname.bib}
@book{author_book,
title = {Book's title},
author = {Author, Some},
location = {The City},
publisher = {Publisher},
date = {2005},
file = {:name between colons:}
}
\end{filecontents}

% This works fine 
%\DeclareFieldFormat{file}{#1}
% This just outputs an empty string
\DeclareFieldFormat{file}{\StrBetween[1,2]{#1}{:}{:}}

\AtEveryBibitem{%
    \printfield{file}
}

\bibliography{jobname}

\begin{document}
\nocite{*}
\printbibliography
\end{document}

答案1

事实证明#1 工作(感谢@egreg 对此的跟进),你只是不能在声明中换行

\DeclareFieldFormat*{file}{\StrBetween[1,2]{\thefield{file}}{:}{:}}

\AtEveryBibitem{%
    \printfield{file}%
}

答案2

应该有参数之间的空格\DeclareFieldFormat。事实上

\DeclareFieldFormat{file}
                   {#1}

似乎只是偶然的。如果你尝试

\DeclareFieldFormat{file}
                   {XX#1XX}

你得到

Runaway argument?
{:name between colons:}\blx@endunit \addspace \blx@execute \blx@initunit \ETC.
! File ended while scanning use of \blx@theformat.

只要输入正确,我看不出使用#1和之间有什么区别\thefield{file}

\begin{filecontents}{jobname.bib}
@book{author_book,
title = {Book's title},
author = {Author, Some},
location = {The City},
publisher = {Publisher},
date = {2005},
file = {:name between colons:}
}
\end{filecontents}

\documentclass{article}
\usepackage{xstring}
\usepackage{biblatex}

\AtEveryBibitem{%
    \printfield{file}\addspace
}

\addbibresource{\jobname.bib}

\begin{document}

\nocite{*}

\DeclareFieldFormat{file}{%
  (\StrBetween[1,2]{\thefield{file}}{:}{:})%
}

\printbibliography

\DeclareFieldFormat{file}{%
  [\StrBetween[1,2]{#1}{:}{:}]%
}

\printbibliography

\end{document}

我在第一种情况下添加了括号,在第二种情况下添加了方括号,以显示字段格式已更改。

在此处输入图片描述

相关内容