每页仅引用一次

每页仅引用一次

我有一个页边距相当大的布局,我想用它来添加引文信息。为此,我定义了一个sidecite命令,将此信息放在页边距中。MWE 如下

\documentclass{memoir}

\setstocksize{297mm}{210mm}
\settrimmedsize{\stockheight}{\stockwidth}{*}
\setulmarginsandblock{27.4mm}{*}{1}
\setlrmarginsandblock{24mm}{79mm}{*}
\setmarginnotes{9mm}{50mm}{1em}
\setheadfoot{1.25\baselineskip}{10mm}
\setheaderspaces{*}{8mm}{*}
\checkandfixthelayout[fixed]

\usepackage[style=alphabetic]{biblatex}

\providecommand\sidecite[2]{\mbox{#1}\marginpar{\footnotesize[\mbox{#1}] #2}}

\DeclareCiteCommand{\cite}[\mkbibbrackets]
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\ifciteindex
     {\indexfield{indextitle}}
     {}%
     \sidecite{\printfield{labelalpha}}{%
               \usebibmacro{author}
               \setunit{\addcomma\space}
               \printfield[citetitle]{labeltitle}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\usepackage{filecontents}
\begin{filecontents*}{test.bib}
@book{test,
  author="John Smith",
  title="The title",
  year=1099,
  publisher="nobody",  
}
\end{filecontents*}

\bibliography{test}

\begin{document}
\cite{test}
\cite{test}
\end{document}

sidecite如果每页出现多个命令,这显然会多次打印引用信息。

有人能帮助我自动检测这样的双重引用并仅在每页边距打印一次信息吗?

我该如何textcite相应地修改宏?

答案1

你需要一个条件,\iflastciteonsamepage比如biblatex:是否有类似于 \ifciteseen 但在同一页内的命令?。要使其工作,您需要打开citetrackerpagetracker

\documentclass{memoir}

\setstocksize{297mm}{210mm}
\settrimmedsize{\stockheight}{\stockwidth}{*}
\setulmarginsandblock{27.4mm}{*}{1}
\setlrmarginsandblock{24mm}{79mm}{*}
\setmarginnotes{9mm}{50mm}{1em}
\setheadfoot{1.25\baselineskip}{10mm}
\setheaderspaces{*}{8mm}{*}
\checkandfixthelayout[fixed]

\usepackage[style=alphabetic,citetracker=true,pagetracker=true]{biblatex}

\makeatletter
\newcommand*{\scbx@registerkey}{%
  \ifcsundef{cbx@instcount@curr@\the\c@refsection @\thefield{entrykey}}
    {\csnumgdef{cbx@instcount@curr@\the\c@refsection @\thefield{entrykey}}{0}}
    {}%
  \csnumgdef{cbx@instcount@last@\the\c@refsection @\thefield{entrykey}}{%
    \csuse{cbx@instcount@curr@\the\c@refsection @\thefield{entrykey}}}%
  \csnumgdef{cbx@instcount@curr@\the\c@refsection @\thefield{entrykey}}{\value{instcount}}}

\def\iflastciteonsamepage{%
  \ifsamepage
    {\number\csuse{cbx@instcount@curr@\the\c@refsection @\thefield{entrykey}}}
    {\number\csuse{cbx@instcount@last@\the\c@refsection @\thefield{entrykey}}}}

\newcommand*{\scbx@savepunctstate}{%
  \let\scbx@saved@unitpunct\blx@unitpunct
  \let\scbx@saved@tgl@unit\etb@tgl@blx@unit
  \let\scbx@saved@tgl@block\etb@tgl@blx@block
  \let\scbx@saved@tgl@insert\etb@tgl@blx@insert
  \let\scbx@saved@tgl@lastins\etb@tgl@blx@lastins
  \let\scbx@saved@tgl@keepunit\etb@tgl@blx@keepunit
}

\newcommand*{\scbx@restorepunctstate}{%
  \global\let\blx@unitpunct\scbx@saved@unitpunct
  \global\let\etb@tgl@blx@unit\scbx@saved@tgl@unit
  \global\let\etb@tgl@blx@block\scbx@saved@tgl@block
  \global\let\etb@tgl@blx@insert\scbx@saved@tgl@insert
  \global\let\etb@tgl@blx@lastins\scbx@saved@tgl@lastins
  \global\let\etb@tgl@blx@keepunit\scbx@saved@tgl@keepunit
}

\newcommand*{\scbx@resetpunctstate}{%
  \let\blx@unitpunct\@empty
  \global\togglefalse{blx@block}%
  \global\togglefalse{blx@unit}%
  \global\togglefalse{blx@insert}%
  \global\togglefalse{blx@lastins}%
  \global\togglefalse{blx@keepunit}%
}


\newbibmacro{sidecite}{%
  \scbx@savepunctstate
  \scbx@resetpunctstate
  \marginpar{%
    \toggletrue{blx@footnote}%
    \printtext[labelalphawidth]{%
      \printfield{labelprefix}%
      \printfield{labelalpha}%
      \printfield{extraalpha}}
    \setunit{\addspace}%
    \printnames{labelname}%
    \setunit{\printdelim{nametitledelim}}%
    \printfield[citetitle]{labeltitle}%
  }%
  \scbx@restorepunctstate
}


\DeclareCiteCommand{\cite}[\mkbibbrackets]
  {\usebibmacro{prenote}}
  {\scbx@registerkey
   \ifciteindex
     {\indexfield{indextitle}}
     {}%
   \usebibmacro{cite}%
   \iflastciteonsamepage
     {}
     {\usebibmacro{sidecite}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\cbx@textcite}
  {\usebibmacro{textcite:init}}
  {\scbx@registerkey
   \usebibmacro{citeindex}%
   \usebibmacro{textcite}%
   \iflastciteonsamepage
     {}
     {\usebibmacro{sidecite}}}
  {}
  {\usebibmacro{textcite:postnote}}



\makeatother
\addbibresource{biblatex-examples.bib}

\begin{document}
Lorem \cite{sigfridsson,worman,geer}
ipsum \cite{sigfridsson}
dolor \textcite{sigfridsson,knuth:ct:a}
\clearpage
dolor \cite{sigfridsson}
sit \cite{worman,sigfridsson,knuth:ct:b}
amet \cite{knuth:ct:a}
\end{document}

正文写着“Lorem [SR98; Wor02; Gee85] ipsum [SR98] dolor Sigfridsson and Ryde [SR98] and Knuth [Knu84]”,并且对每个参考文献都附有恰好一次的边注。

相关内容