BibLaTeX:如何创建 \NewDocumentCommand 以实现自动 Prenotes?

BibLaTeX:如何创建 \NewDocumentCommand 以实现自动 Prenotes?

描述:

我正在使用一个小修改来自动将缩写“cf.”添加到引用预注中:

\renewbibmacro*{prenote}{%
    \iffieldundef{prenote}%
    {% true
        \printtext{cf\adddot}%
    }{% false
        \printfield{prenote}}%
    \setunit{\prenotedelim}%
}%

总是添加“cf.”在大多数情况下很有用,但并非在所有情况下都如此。因此,我想将此自动预注外包到单独的 中。仅在键入或缩写\NewDocumentCommand时才应将其添加为预注。\cf-cite\cf-autocite

我该如何介绍这一点?


最小工作示例(MWE):

\begin{filecontents}{\jobname.bib}  
    @book{Doe,author = {Doe, Jon},date = {1998}}
\end{filecontents}

% ----------------------------------------------------------------------------------

\documentclass{book}

\usepackage[backend=biber,citestyle=numeric,style=authoryear,natbib=true]{biblatex}
\usepackage{filecontents}

\setlength\parindent{0pt}

\renewbibmacro*{prenote}{%
    \iffieldundef{prenote}%
    {% true
        \printtext{cf\adddot}%
    }{% false
        \printfield{prenote}}%
    \setunit{\prenotedelim}%
}%

\bibliography{\jobname}

\begin{document}

    This is a very simple example to demonstrate citing with auto-added prenotes \autocite[25]{Doe}.

    \par\bigskip As you can see, the abbreviation \enquote{cf.} will always be displayed. It is not possible to keep this field empty anymore. However, this is not useful in every case. Therefore I want to generate two \textbackslash NewDocumentCommand's:

    \begin{itemize}
        \item \textbackslash cf-cite and
        \item \textbackslash cf-autocite
    \end{itemize}

    Only when using one of those two new commands, the previous mentioned \enquote{cf.} should be displayed as a prenote. In all other cases the field should remain empty.

    \par\bigskip How can I do that?

\end{document}

编辑:\autocite[cf.][35]{Doe}当我想到我以前的想法时,这已经没有什么意义了。无论我是否必须写或写,都无所谓\cf-autocite[35]{Doe}。:-)

答案1

这并非您所要求的,但我认为这是对您的尝试的改进。我确实认为内置预注释有点过头了,但要像您建议的那样拥有自己的“外包”预注释,则需要针对您希望此功能可用的\DeclareCitationCommand几个命令的每个变体进行相当多的结构化。biblatex

我认为您原来的结构在实践中会运行得很好,而且只需一个简单的切换就可以轻松禁用“cf.”的自动插入。

\begin{filecontents}{\jobname.bib}
  @book{Doe,author = {Doe, Jon},date = {1998}}
\end{filecontents}

% ----------------------------------------------------------------------------------

\documentclass{book}

\usepackage[backend=biber,citestyle=numeric,style=authoryear,natbib=true]{biblatex}
\usepackage{filecontents}

\setlength\parindent{0pt}

\newtoggle{nocf}
\newcommand*{\nocf}{\AtNextCite{\toggletrue{nocf}}}

\renewbibmacro*{prenote}{%
  \iffieldundef{prenote}%
  {% true
    \iftoggle{nocf}{}{%
      \printtext{cf\adddot}%
    }%
  }{% false
    \printfield{prenote}%
  }%
  \setunit{\prenotedelim}%
}

\addbibresource{\jobname.bib}

\begin{document}

This is a very simple example to demonstrate citing with auto-added prenotes
\autocite[25]{Doe}.

\bigskip
As you can see, the abbreviation “cf.” will be displayed by
default. But it is possible to leave it empty with
‘\verb|\nocf|’ \nocf\autocite[34]{Doe}.

\bigskip
However, without it, the default behavior is back \autocite[29]{Doe}.

\end{document}

在此处输入图片描述

相关内容