在 LaTeX 中引用同一篇论文两次(使用 Biber)

在 LaTeX 中引用同一篇论文两次(使用 Biber)

我正在使用 LaTeX 撰写我的硕士论文,但参考书目方面有些问题。我使用 Biber 和样式bath

我有一篇论文(目前,但在同样的情况下可能会有更多),我需要在引言部分和讨论部分引用。

问题是,当我使用 时\parencite,论文只出现在引言部分,而讨论部分只有“()”。但如果我\cite在讨论部分使用 ,它又会出现,但没有括号(我想要括号,因此使用\parencite)。

你能帮助我吗?

梅威瑟:

\documentclass[a4paper, 12pt]{report}

\usepackage{xpatch}
\usepackage{csquotes}
\usepackage[style = bath, defernumbers = true,  backend = biber, sorting = nyt, minbibnames=1, maxbibnames=99,  maxcitenames = 2]{biblatex}
\ExecuteBibliographyOptions{labelnumber}
\DeclareFieldFormat{labelnumberwidth}{\mkbibbrackets{#1}}


\renewbibmacro*{isonline}{}
\DeclareBibliographyDriver{online}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{url}%
  \usebibmacro{title}%
  \usebibmacro{urldate}%
  \usebibmacro{finentry}}
\DeclareFieldFormat[online]{title}{#1\addcomma}
\DeclareFieldFormat[online]{url}{#1\addcolon\addspace}
\DeclareFieldFormat{urldate}{\bibstring{urlseen}\space#1}

\defbibenvironment{onlinebib}
  {\list
     {\printtext[labelnumberwidth]{%
        \printfield{labelprefix}%
        \printfield{labelnumber}}}
     {\setlength{\labelwidth}{\labelnumberwidth}%
      \setlength{\leftmargin}{\labelwidth}%
      \setlength{\labelsep}{\biblabelsep}%
      \addtolength{\leftmargin}{\labelsep}%
      \setlength{\itemsep}{\bibitemsep}%
      \setlength{\parsep}{\bibparsep}}%
      \renewcommand*{\makelabel}[1]{\hss##1}}
  {\endlist}
  {\item}


\providebool{bbx:subentry}

\newbibmacro*{cite:num}{%
  \printtext[bibhyperref]{%
    \printfield{labelprefix}%
    \printfield{labelnumber}%
    \ifbool{bbx:subentry}
      {\printfield{entrysetcount}}
      {}}}

\DeclareCiteCommand{\parencite}
  {\ifentrytype{online}{\bibopenbracket}{\bibopenparen}%
   \usebibmacro{prenote}}%
  {\usebibmacro{citeindex}%
   \ifentrytype{online}{\usebibmacro{cite:num}}{\usebibmacro{cite}}}
  {\multicitedelim}
  {\usebibmacro{postnote}%
   \ifentrytype{online}{\bibclosebracket}{\bibcloseparen}}


\addbibresource{\jobname.bib}
\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@article{author2001,
  author = {Author, A.},
  year = {2001},
  title = {Title},
  journal={Journal},
}

@article{buthor2001,
  author = {Buthor, B. and Cuthor, C.},
  year = {2001},
  title = {Title},
  journal={Journal},
}

@online{tex,
  title={Online},
  url={https://tex.stackexchange.com/},
  urldate={2019-02-06},
}
\end{filecontents}

\begin{document}
\section*{Introduction}
Lorem ipsum \parencite{author2001}.
Lorem ipsum \parencite{buthor2001}.

\section*{Discussion}
Lorem ipsum \parencite{tex}. Lorem ipsum \parencite{buthor2001}. Lorem ipsum \parencite{author2001}.

\printbibliography[type=article, heading = subbibliography, title={Articles}]
\newrefcontext[sorting=none]
\printbibliography[env=onlinebib, heading = subbibliography, type=online, title={Online}, resetnumbers]
\end{document}

应该给出:

介绍

Lorem ipsum(作者,2001 年)。 Lorem ipsum(Buthor 和 Cuthor,2001 年)。

讨论

乱数假文 [1]. Lorem ipsum(Buthor 和 Cuthor,2001 年)。 Lorem ipsum(作者,2001 年)。

文章

作者,A.,日期。标题。杂志

Buthor, B. 和 Cuthor, C.,日期。标题。杂志

但给予

介绍

Lorem ipsum(作者,2001 年)。 Lorem ipsum(Buthor 和 Cuthor,2001 年)。

讨论

乱数假文 [1].乱数假文()。 Lorem ipsum(作者,2001 年)。

文章

作者,A.,日期。标题。杂志

buthor, B. 和 Cuthor, C.,日期。标题。杂志

答案1

biblatex-bath的引用样式基于标准样式authoryear-comp。这意味着对其引用命令的所有修改都应基于authoryear-comp的定义,而不是authoryear或其他更通用的样式。

特别是的定义\parencite应该更像

\DeclareCiteCommand{\parencite}
  {\ifentrytype{online}{\bibopenbracket}{\bibopenparen}%
   \usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \ifentrytype{online}{\usebibmacro{cite:num}}{\usebibmacro{cite}}}
  {}
  {\usebibmacro{postnote}%
   \ifentrytype{online}{\bibclosebracket}{\bibcloseparen}}

因为您需要确保您的引用命令应用了需要cite:init的管理()authoryear-comp

您会发现这个错误与上下文非常相关。例如,如果您在第一部分中更改了author2001和的引用顺序buthor2001,则问题就不会出现。但是,如果 的作者也这样buthor2001做,您会看到不同的有趣效果。Author, A.

样式-comp需要记住最后一个labelname和,year以便正确压缩引用列表。但biblatex不会清除引用末尾记住的最后一个引用属性。相反,存储这些信息的宏会在开始引用命令的cite:init。在 MWE 中没有调用cite:init,因此不会发生此重置,这意味着所有引用命令的行为都如同它们位于同一个括号组中一样。


@online我还建议将字段格式中的标点符号直接移到驱动程序中\setunit。我还强烈建议您使用\urlURL 命令来获取正确的换行和链接,如果您不喜欢默认的打字机/等宽字体,您可以使用进行更改\urlstyle{same}

\documentclass[british, a4paper, 12pt]{report}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[style = bath, defernumbers = true,  backend = biber, sorting = nyt, minbibnames=1, maxbibnames=99, maxcitenames = 2]{biblatex}
\ExecuteBibliographyOptions{labelnumber}
\DeclareFieldFormat{labelnumberwidth}{\mkbibbrackets{#1}}


\DeclareFieldFormat[online]{title}{#1}
\DeclareFieldFormat[online]{url}{\url{#1}}
\DeclareFieldFormat{urldate}{\bibstring{urlseen}\space#1}

\renewbibmacro*{isonline}{}
\DeclareBibliographyDriver{online}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{url}%
  \setunit{\addcolon\space}%
  \usebibmacro{title}%
  \setunit{\addcomma\space}%
  \usebibmacro{urldate}%
  \usebibmacro{finentry}}


\defbibenvironment{onlinebib}
  {\list
     {\printtext[labelnumberwidth]{%
        \printfield{labelprefix}%
        \printfield{labelnumber}}}
     {\setlength{\labelwidth}{\labelnumberwidth}%
      \setlength{\leftmargin}{\labelwidth}%
      \setlength{\labelsep}{\biblabelsep}%
      \addtolength{\leftmargin}{\labelsep}%
      \setlength{\itemsep}{\bibitemsep}%
      \setlength{\parsep}{\bibparsep}}%
      \renewcommand*{\makelabel}[1]{\hss##1}}
  {\endlist}
  {\item}

\providebool{bbx:subentry}

\newbibmacro*{cite:num}{%
  \printtext[bibhyperref]{%
    \printfield{labelprefix}%
    \printfield{labelnumber}%
    \ifbool{bbx:subentry}
      {\printfield{entrysetcount}}
      {}}}

\DeclareCiteCommand{\parencite}
  {\ifentrytype{online}{\bibopenbracket}{\bibopenparen}%
   \usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \ifentrytype{online}{\usebibmacro{cite:num}}{\usebibmacro{cite}}}
  {}
  {\usebibmacro{postnote}%
   \ifentrytype{online}{\bibclosebracket}{\bibcloseparen}}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{author2001,
  author  = {Author, A.},
  year    = {2001},
  title   = {Title},
  journal = {Journal},
}
@article{buthor2001,
  author  = {Buthor, B. and Cuthor, C.},
  year    = {2001},
  title   = {Title},
  journal = {Journal},
}
@online{tex,
  title   = {Online},
  url     = {https://tex.stackexchange.com/},
  urldate = {2019-02-06},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\section*{Introduction}
Lorem ipsum \parencite{author2001}.
Lorem ipsum \parencite{buthor2001}.

\section*{Discussion}
Lorem ipsum \parencite{tex}. Lorem ipsum \parencite{buthor2001}. Lorem ipsum \parencite{author2001}.

\printbibliography[type=article, heading = subbibliography, title={Articles}]
\newrefcontext[sorting=none]
\printbibliography[env=onlinebib, heading = subbibliography, type=online, title={Online}, resetnumbers]
\end{document}

**简介**//Lorem ipsum(作者,2001)。 Lorem ipsum(Buthor 和 Cuthor,2001)。//**讨论**//Lorem ipsum [1]。 Lorem ipsum(Buthor 和 Cuthor,2001 年)。 Lorem ipsum//(作者,2001)。//**文章**//作者,A.,2001。标题。期刊。//Buthor, B. 和 Cuthor, C.,2001。标题。期刊。//**在线**//[1] https://tex.stackexchange.com/:在线,2019 年 2 月 6 日访问。

相关内容