将 5-6 压缩到 5f。在引用的后注中:\rangelen in \ifnumequal

将 5-6 压缩到 5f。在引用的后注中:\rangelen in \ifnumequal

我正在尝试自动将后记中的页面范围转换\textcite[4-5]{Smi83}4f.当且仅当范围正好是两页长。看来 biblatex 就是\rangelen为此而设计的,然而与文档相反,每当我尝试在 etoolbox 中使用它时,它就会崩溃\ifnumequal

! Missing number, treated as zero.
<to be read again> 
                \begingroup 
l.36 Test: \ifnumequal{2}{\rangelen{4-5}}
                                        {f.}{something has gone wrong.}

我究竟做错了什么?

这是一个显示错误的完整示例:

\documentclass{article}

\usepackage[style=authoryear]{biblatex}

\renewcommand*{\postnotedelim}{\addcolon}

\DeclareFieldFormat{postnote}{%
\ifpages{#1}%
    {\ifnumequal{2}{\rangelen{#1}}%
        {\mkfirstpage{#1}\bibstring{sequens}}%f.
        {\ifnumequal{\rangelen{#1}}{0}% open range
            {\mkfirstpage{#1}\bibstring{sequentes}}%ff.
            {\mkcomprange{#1}}}}% compress closed range
    {#1}}% no range -> just print it

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@misc{Smi83,
author = {Smith, S.},
year = {1983},
title = {Sierra},
}
@misc{Jon01,
author = {Jones, J.},
year = {2001},
title = {Juliet},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}

% Works:
Rangelen: \rangelen{4-5}

% Breaks:
Test: \ifnumequal{2}{\rangelen{4-5}}{f.}{something has gone wrong.}
%! Missing number, treated as zero.
%<to be read again> 
%                   \begingroup 
%l.36 Test: \ifnumequal{2}{\rangelen{4-5}}
%                                         {f.}{something has gone wrong.}

See e.g. \textcites[4-5]{Smi83}[10-15]{Jon01}. Also see \textcite[42]{Smi83}
and \textcite[90\psqq]{Jon01} as well as \textcite[ although this is only
slightly relevant]{Smi83}.

\printbibliography

\end{document}

答案1

我已\rangelen在 Sourceforge 上更新了 biblatex (3.0) 的开发版本,其中 Joseph Wright 重写了此内容,解决了此问题。此外,还有一个新宏,\frangelen它接受范围字段(如pages)名称并返回范围,以便您可以执行以下操作:

\ifnumequal{2}{\frangelen{pages}}{f.}{something has gone wrong.}

此宏需要biber后端为biber活动biblatex数据模型中数据类型为“范围”的所有字段计算此值,并将结果放入.bbl。 的好处\frangelen是它可以处理许多棘手的情况:

  • ASCII 和 Unicode 表示中的罗马数字(大写和小写),甚至特殊的 Unicode 组成的罗马数字。
  • 隐含范围,如“22-4”和“132-37”
  • 同一范围字段中的多个范围(如“i-iii、1-8、10-20”)将导致长度为“21”
  • 范围分隔符可以是任何有效的 Unicode 破折号字符

biber除了biblatex3.0之外,您还需要2.0 开发版本

相关内容