Biblatex:重新定义 cite 命令以打印另一个字段

Biblatex:重新定义 cite 命令以打印另一个字段

在我的参考书目中,我有一个自定义字段。我想重新定义命令\parencite{},以便此字段也打印在文本中(但不在参考书目中)。在下面的例子中,我希望结果不是

(Gossens,1993 年)

(Gossens,1993,示例)

我知道我可以使用某种后引用命令,例如\parencite[][Example]{}命令;但是我需要使用新命令直接引用参考书目中的字段,例如:\parenciteNEW。应该可以使用\DeclareCiteCommand,但我无法通过更改其设置来完成此操作。

您对如何实现这一目标有什么想法吗?

\documentclass{minimal}

\usepackage[american]{babel}
\usepackage[utf8]{inputenc}
\usepackage{csquotes}
\usepackage[style=apa,
        bibencoding=utf8,
        sortcites=true,
        bibwarn=true,
        firstinits=true,
        isbn=false,
        dashed=false,
        maxbibnames=99,
        babel=other,
        backend=biber,
        hyperref=true]{biblatex}

\begin{filecontents}{myworks.bib}
@book{goossens93,
    author    = "Michel Goossens",
    title     = "The LaTeX Companion",
    year      = "1993",
    publisher = "Addison-Wesley",
    address   = "Reading, Massachusetts",
    custom    = "Example"
}

\end{filecontents}


\addbibresource{myworks.bib} 

\DeclareLanguageMapping{american}{american-apa}

\begin{document}

Here is an example\parencite{goossens93}.

\selectlanguage{american}
\printbibliography
\end{document}

答案1

您应该将自定义字段映射到已知字段,例如 usera。然后,您可以使用\printfieldpostnote 参数打印它,或者在某些 cite 命令定义中使用它:

\documentclass{article}

\usepackage[american]{babel}
\usepackage[utf8]{inputenc}
\usepackage{csquotes}
\usepackage[style=apa,
        bibencoding=utf8,
        sortcites=true,
        bibwarn=true,
        firstinits=true,
        isbn=false,
        dashed=false,
        maxbibnames=99,
        babel=other,
        backend=biber,
        hyperref=true]{biblatex}

\begin{filecontents}{myworks.bib}
@book{goossens93,
    author    = "Michel Goossens",
    title     = "The LaTeX Companion",
    year      = "1993",
    publisher = "Addison-Wesley",
    address   = "Reading, Massachusetts",
    custom    = "Example"
}

\end{filecontents}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=custom, fieldtarget=usera]
    }
  }
}

\addbibresource{myworks.bib}

\DeclareLanguageMapping{american}{american-apa}

 \DeclareCiteCommand{\parenciteNEW}[\mkbibparens]
 {\renewcommand{\finalnamedelim}{\ifnum\value{liststop}>2 \finalandcomma\fi\addspace\&\space}%
   \usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}%
   \setunit{\postnotedelim}%
   \printfield{usera}}
  {}
  {%
   \usebibmacro{postnote}%
   \usebibmacro{cite:post}}

\begin{document}

Here is an example \parencite[\printfield{usera}]{goossens93}.
And another
\parenciteNEW[postnote]{goossens93}

\printbibliography
\end{document}

相关内容