Biblatex:\ifentryseen 命令不起作用

Biblatex:\ifentryseen 命令不起作用

跟随上一个问题,我定义了一个新cite命令,它执行以下操作:

  • 如果该条目之前没有被引用过,请在文内\citenumeric和边注中注明引用编号、作者和年份
  • 如果之前已经看到过该条目,则只需在文本中\citenumeric

我使用 命令 执行了此\ifentryseen操作biblatex,并将citetracker选项设置为true并将citereset选项设置为chapter。但是,该命令似乎\ifentryseen无法识别不同段落之间已引用的条目。

梅威瑟:

\documentclass[nobib,notoc,nofonts,symmetric,justified,titlepage]{tufte-book}
\usepackage[T1]{fontenc}
\usepackage[
citestyle=numeric,
hyperref=true,
doi=false, url=false, isbn=false, eprint=false,
giveninits=true,
abbreviate=false,
backend=biber,
citetracker=true,
citereset=chapter,
sorting=none
]{biblatex}


\addbibresource{references.bib}

\makeatletter

% Functional foreach construct 
% #1 - Function to call on each comma-separated item in #3
% #2 - Parameter to pass to function in #1 as first parameter
% #3 - Comma-separated list of items to pass as second parameter to function #1
\def\foreach#1#2{%
    \@test@foreach{#1}#2,\@end@token%
}

% Internal helper function - Eats one input
\def\@swallow#1{}

% Internal helper function - Checks the next character after #1 and #2 and 
% continues loop iteration if \@end@token is not found 
\def\@test@foreach#1{%
    \@ifnextchar\@end@token%
    {\@swallow}%
    {\@foreach{#1}}%
}

% Internal helper function - Calls #1{#2}{#3} and recurses
% The magic of splitting the third parameter occurs in the pattern matching of the \def
\def\@foreach#1#2,#3\@end@token{%
    #1{#2}%
    \@test@foreach{#1}#3\@end@token%
}

\makeatother



% Modify citation style
\let\citenumeric\cite
\newcommand{\citemargin}[1]{\marginnote{\citenumeric{#1}\addnbspace\citeauthor{#1}\addnbspace(\citeyear{#1}).}}
\renewcommand{\cite}[1]{\ifentryseen{#1}{\citenumeric{#1}}{\citenumeric{#1}\foreach{\citemargin}{#1}} }


\begin{document}


\chapter{First Chapter}


Two grouped citations should be split in separate margin notes  \cite{one,two}.
Now I will cite again \cite{one}, and the margin note should NOT appear.


\chapter{Second Chapter}

Now stuff is reset.
Two grouped citations should be split in separate margin notes  \cite{one,two}.
Now I will cite again \cite{one}, and the margin note should NOT appear.

However in a new paragraph it appears again \cite{one,two} and \cite{two}.

\end{document}

references.bib

@article{one,
    author = {John Doe},
    title = {The ABC program system},
    journal = {Journal of Sci. Prog.},
    volume = {2},
    number = {1},
    pages = {5-10},
    year ={2021}
}


@book{two,
    title={A guide to Latex and Biblatex},
    author={Richard Doe},
    year={2000},
    publisher={Some Publisher}
}

答案1

\ifentryseen按照示例中所述工作。\ifentryseen采用单个<key>并检查与该键相对应的条目是否之前出现过(考虑到重置等)。

在 的定义中\cite \ifentryseen传递了第一个参数#1,这意味着当您调用 时,\cite{key1,key2}您会测试\ifciteseen{key1,key2}。由于没有条目被调用,因此key1,key2此测试始终给出 false。您需要确保只测试单个键(在您的设置中\ifciteseen应该在 内\foreach)。

我建议采用不同的方法。通常,最好尝试通过使用 定义\...cite命令来解决这些问题\DeclareCiteCommand。将多个\...cite命令组合成一个命令\newcommand可能会对引用跟踪产生不良影响(在这种情况下,如果不小心的话)。此外,\DeclareCiteCommand已经附带了处理多个键的代码,因此您甚至不需要\foreach

这里的想法是定义两个\...cite命令。一个命令打印通常的引文并收集页边距所需的引文,另一个命令打印页边距引文。

\documentclass[nobib,notoc,nofonts,symmetric,justified,titlepage]{tufte-book}
\usepackage[T1]{fontenc}
\usepackage[
  backend=biber,
  style=numeric,
  sorting=none,
  doi=false, url=false, isbn=false, eprint=false,
  giveninits=true,
  abbreviate=false,
  citetracker=true,
  citereset=chapter,
]{biblatex}

\newbibmacro{cite:authoryear}{%
  \printtext[labelnumberwidth]{%
    \usebibmacro{cite}%
  }%
  \setunit{\addspace}%
  \printnames{labelname}%
  \setunit{\printdelim{nameyeardelim}}%
  \begingroup
  \DeclareFieldFormat{date}{\mkbibparens{##1}}%
  \printdate
  \endgroup
}

\makeatletter
\newrobustcmd*{\makebibmarginnote}[1]{%
  \marginnote{\blxmkbibnote{foot}{#1}}}

\DeclareCiteCommand{\maycite}[\makebibmarginnote]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:authoryear}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\newcommand*{\cbx@savedcites}{}

\newcommand*{\cbx@margcitewrap}[1]{%
  \global\let\cbx@savedcites\empty
  \mkbibbrackets{#1}%
  \cbx@savedcites
}

\DeclareCiteCommand{\margincite}[\cbx@margcitewrap]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}%
   \ifciteseen
     {}
     {\xappto\cbx@savedcites{\noexpand\maycite{\thefield{entrykey}}}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareMultiCiteCommand{\margincites}[\cbx@margcitewrap]{\margincite}{\multicitedelim}

\DeclareAutoCiteCommand{margin}{\margincite}{\margincites}
\ExecuteBibliographyOptions{autocite=margin}
\makeatother

\addbibresource{biblatex-examples.bib}

\begin{document}
\chapter{First Chapter}

Two grouped citations should be split in separate margin notes \autocite{sigfridsson,worman}.
Now I will cite again \autocite{sigfridsson}, and the margin note should NOT appear.

\chapter{Second Chapter}
Now stuff is reset.
Two grouped citations should be split in separate margin notes  \autocite{sigfridsson,worman}.
Now I will cite again \autocite{sigfridsson}, and the margin note should NOT appear.

However in a new paragraph it appears again \autocite{sigfridsson,worman}.

\chapter{Third Chapter}
Now stuff is reset.
Two grouped citations should be split in separate margin notes  \autocites{sigfridsson}{worman}.
Now I will cite again \autocite{sigfridsson}, and the margin note should NOT appear.

However in a new paragraph it appears again \autocites{sigfridsson}{worman}.

\printbibliography
\end{document}

第二章,附有两条边注。

相关内容