スタイル付きで\DeclareCiteCommandを使用する方法

スタイル付きで\DeclareCiteCommandを使用する方法

私は次のようなことを試みています:Biblatex の脚注を余白に表示 彼らの例を盗める程度には。

私がやりたいのは、本文では通常どおりテキストを引用し、次にサイドバーで著者名、日付、作品名を使用して引用することです。

この MWE の目的のため、私は単にベース ラテックス を使用しています\marginpar。(実際の作業では、Koma scrnote-layer を使用しています。しかし、私は BibLaTeX を理解しようとしているので、それはあまり重要ではありません)

MWE:

\documentclass{article}
\usepackage{blindtext}


% bib-file
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
  @book{Knu86,
    author = {Knuth, Donald E.},
    year = {1986},
    title = {The \TeX book},
  }
  @BOOK{KandR,
    AUTHOR    = {Kernighan, Brian W. and Ritchie, Dennis M.},
    TITLE     = {{The C Programming Language Second Edition}},
    PUBLISHER = {Prentice-Hall, Inc.},
    YEAR      = {1988},
}  
\end{filecontents}

\usepackage[]{biblatex}
\addbibresource{\jobname}


\newcommand{\tcite}[1]{
    \textcite{#1}
    \marginpar{
        \citeauthor{#1}, 
        \citeyear{#1}. 
        \citetitle{#1}  
    }
} 

% doc
\begin{document}
\blindtext
\tcite{Knu86}
\blindtext
\tcite{Knu86,KandR}
\blindtext
\end{document}

MSE出力

青で囲んだテキストは完璧であることがわかります。しかし、赤で囲んだテキストはフィールドごとに照合されているため間違っています。もちろん、その理由は明らかです。私のコマンドはキーごとに処理するのではなく、すべてのキーをまとめて処理します。

私の現在のコマンドは次のとおりです:

\newcommand{\tcite}[1]{
    \textcite{#1}
    \marginpar{
        \citeauthor{#1}, 
        \citeyear{#1}. 
        \citetitle{#1}  
    }
} 

私はこれをBibLaTeXで作られたものに置き換えたいと思っています。\DeclareCiteCommand

そこで私は挑戦してみました:

\DeclareCiteCommand{\tcite}
{   % prenote
    \usebibmacro{prenote}%
}
{   %loopcode
    \printnames{author}%
    \marginpar{
        \printnames{author}, 
        \printfield{year}. 
        \printfield{title}  
    }
}
{   %sepcode
    \multicitedelim%
}
{\usebibmacro{postnote}}

より良い作業

これは機能しており、青い円と赤い円の両方が別々になっている限りは問題ないことがわかります。ただし、著者名のスタイル設定のメリットは得られていません (たとえば、設定に基づいて姓のみに短縮されています)。また、使用しておらず、\textcite単に入力しただけなのでprintnames{author}、そこでのスタイル設定のメリットも得られていません。

これは、これらのことに対して低レベルのコマンドを使用したためだと思います。スタイル/構成を尊重する高レベルのコマンドを使用するにはどうすればよいでしょうか。

答え1

\citeauthorなど の高レベルコマンドは使用しないでください\DeclareCiteCommand。 では可能ですが\citeauthor{\thefield{entrykey}}、あまり良い考えではありません。

代わりに、次の目的で使用されるbibmacrosを使用してください。\citeauthor

\newbibmacro{sidecite}{%
  \printnames{labelname}%
  \setunit{\printdelim{nametitledelim}}%
  \printfield[citetitle]{labeltitle}%
  \setunit{\addperiod\space}%
  \printfield{year}}

あなたの例で\textciteは を再現したかったのでnumeric、 を選択しました。

\documentclass{article}
\usepackage{blindtext}


% bib-file
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{Knu86,
  author = {Knuth, Donald E.},
  year = {1986},
  title = {The \TeX book},
}
@BOOK{KandR,
  AUTHOR    = {Kernighan, Brian W. and Ritchie, Dennis M.},
  TITLE     = {{The C Programming Language Second Edition}},
  PUBLISHER = {Prentice-Hall, Inc.},
      YEAR      = {1988},
}  
\end{filecontents}

\usepackage[]{biblatex}


\newbibmacro{sidecite}{%
  \printnames{labelname}%
  \setunit{\printdelim{nametitledelim}}%
  \printfield[citetitle]{labeltitle}%
  \setunit{\addperiod\space}%
  \printfield{year}}

\makeatletter
\DeclareCiteCommand{\cbx@textcite}
  {\usebibmacro{textcite:init}}
  {\usebibmacro{citeindex}%
   \usebibmacro{textcite}%
   \setunit{}%
   \marginpar{\usebibmacro{sidecite}}%
   \setunit{%
     \ifbool{cbx:parens}
       {\bibcloseparen\global\boolfalse{cbx:parens}}
       {}%
     \textcitedelim}}
  {}
  {\usebibmacro{textcite:postnote}}
\makeatother

\addbibresource{\jobname.bib}

% doc
\begin{document}
\blindtext
\textcite{Knu86}
\blindtext
\textcite{Knu86,KandR}
\blindtext
\end{document}

数値例出力、切り取られた


物事authoryearは簡単になる

\documentclass{article}
\usepackage{blindtext}


% bib-file
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{Knu86,
  author = {Knuth, Donald E.},
  year = {1986},
  title = {The \TeX book},
}
@BOOK{KandR,
  AUTHOR    = {Kernighan, Brian W. and Ritchie, Dennis M.},
  TITLE     = {{The C Programming Language Second Edition}},
  PUBLISHER = {Prentice-Hall, Inc.},
      YEAR      = {1988},
}  
\end{filecontents}

\usepackage[style=authoryear]{biblatex}


\newbibmacro{sidecite}{%
  \printnames{labelname}%
  \setunit{\printdelim{nametitledelim}}%
  \printfield[citetitle]{labeltitle}%
  \setunit{\addperiod\space}%
  \printfield{year}}

\DeclareCiteCommand{\tcite}
  {\usebibmacro{prenote}}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}%
   \marginpar{\usebibmacro{sidecite}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\addbibresource{\jobname.bib}

% doc
\begin{document}
\blindtext
\tcite{Knu86}
\blindtext
\tcite{Knu86,KandR}
\blindtext
\end{document}

著者年 MWE

答え2

\usebibmacro{<macroname>}を使用すると、 内で bib マクロを呼び出すことができますDeclareCiteCommand。ただし、 を使用して定義されたものを呼び出すことはできないDeclareCiteCommandため、 は使用できません\usebibmacro{citeauthor}

したがって、新しいコードは次のようになります。

\DeclareCiteCommand{\tcite}%
{\usebibmacro{prenote}}% prenote
{   %loopcode
    \usebibmacro{cite}%
    \marginpar{\usebibmacro{cite}, \printfield{title} \\
}
}
{\multicitedelim}% sepcode
{\usebibmacro{postnote}}

これを、biblatex でより興味深い引用スタイルを設定して実行すると、 \usepackage[citestyle=authoryear]{biblatex} 次のようになります。

修理済み

関連情報