首次引用作品时在边距中显示标题

首次引用作品时在边距中显示标题

我的问题的核心是如何定义一个宏,该宏在第一次使用给定参数调用时会执行不同的操作。此外,还可以重置该宏,以便恢复第一次的行为。

我想用这个功能让引用在第一次使用时在边距中显示所引用作品的标题。

这是我想出的办法,使用电子工具箱旗子。

\documentclass[]{article}
\usepackage{etoolbox}
\usepackage[style=authoryear, backend=biber]{biblatex}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Arguments: namespace,key,if first-action, if-not-first action
\newcommand{\iffirstuse}[4]{%
    \global\providetoggle{#1#2}%
    \global\nottoggle{#1#2}{#3}{#4}%
    \global\toggletrue{#1#2}%
}

\let\oldcite\cite
\def\citenamespace{citeA}
\renewcommand{\cite}[1]{%
    \iffirstuse{\citenamespace}{#1}%
    {%
        \oldcite{#1}%
        \marginpar{\citetitle{#1}}%
    }{%
    \oldcite{#1}%
    }%
}

\newcommand{\resetcitescount}{%
    \xdef\citenamespace{{\citenamespace}A}
}

%%%%%%%%%%%%%%%%%%%%%%


\begin{filecontents}{\jobname.bib}
    @book{Labov1972,
        Address = {Philadelphia},
        Author = {William Labov},
        Publisher = {University of Pennsylvania Press},
        Title = {Sociolinguistic Patterns},
        Year = {1972}}

    @book{Chomsky1957,
        Address = {The Hague},
        Author = {Noam Chomsky},
        Publisher = {Mouton},
        Title = {Syntactic Structures},
        Year = {1957}}
\end{filecontents}

\addbibresource{\jobname.bib}


\begin{document}
It was said that there were patterns (\cite{Labov1972}.)\\
\cite{Labov1972} speaks of patterns in language based on society.\\
This can be contrasted with the earlier work of \cite{Chomsky1957}.\\
\cite{Labov1972} is newer than \cite{Chomsky1957}\\
With all that said\\
and all that done\\
\resetcitescount{} 
Do not forget \cite{Chomsky1957}

\end{document}

演示截图

这可行,但我不确定这是否是最好的方法。

此外,我不知道它能多好地适应 biblatex 中不同 cite 命令的所有复杂性,例如\parencite{refone,reftwo,refthree}

有没有更聪明的方法来做到这一点?

答案1

测试\ifciteseen检查当前条目是否之前被查看过/引用过。必须使用该citetracker选项启用它。

在下面的例子中,我修补了citebibmacro,以便xpatch在需要时将标题包含在边距中。

\documentclass[]{article}
\usepackage{etoolbox}
\usepackage[style=authoryear, backend=biber, citetracker=true]{biblatex}

\usepackage{xpatch}

\makeatletter
\xapptobibmacro{cite}{%
  \ifciteseen
    {}
    {\scbx@savepunctstate
     \marginpar{%
       \scbx@resetpunctstate
       \printfield[citetitle]{labeltitle}}%
     \scbx@restorepunctstate}%
}{}{}

\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}%
}
\makeatletter


\begin{filecontents}{\jobname.bib}
@book{Labov1972,
  address   = {Philadelphia},
  author    = {William Labov},
  publisher = {University of Pennsylvania Press},
  title     = {Sociolinguistic Patterns},
  year      = {1972},
}

@book{Chomsky1957,
  address   = {The Hague},
  author    = {Noam Chomsky},
  publisher = {Mouton},
  title     = {Syntactic Structures},
  year      = {1957},
}
\end{filecontents}

\addbibresource{\jobname.bib}


\begin{document}
It was said that there were patterns \parencite{Labov1972,Chomsky1957}.

\cite{Labov1972} speaks of patterns in language based on society.

This can be contrasted with the earlier work of \cite{Chomsky1957}.

\cite{Labov1972} is newer than \cite{Chomsky1957}

With all that said
and all that done

\citereset
Do not forget \cite{Chomsky1957}
\end{document}

\scbx@savepunctstate和朋友只是为了避免两种不同的标点符号跟踪级别带来的不良副作用,请参阅每页仅引用一次

三个边距条目。一个用于 <code>Labov1972</code>,然后用于 <code>Chomsky1957</code>,重置后再次用于 <code>Chomsky1957</code>。

相关内容