如何使用 \DeclareCiteCommand,風格

如何使用 \DeclareCiteCommand,風格

我正在嘗試類似的事情:Biblatex 頁邊註腳 在某種程度上我可以竊取他們的例子。

我想做的是,通常在正文中引用文本,然後在側欄中使用作者姓名,然後是日期,然後是作品名稱。

出於本 MWE 的目的,我僅使用基礎乳膠\marginpar。 (在我的實際工作中,我使用 Koma scrnote-layer 的東西。但這並不重要,因為我正在嘗試理解 BibLaTeX)

微量元素:

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

均方誤差輸出

可以看出,藍色圈起來的文字已經很完美了。但紅色圓圈的文字是錯誤的,因為它是按字段整理的。原因當然是顯而易見的。我的命令不會處理每個鍵,而是一起處理所有鍵。

我目前的命令是:

\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}},但這不是一個好主意。

相反,只需使用用於\citeauthor

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

由於在您的範例中您想重新創建\textcitenumeric所以我同意了。

\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>}讓您可以在DeclareCiteCommand.但是,它不允許您呼叫本身使用DeclareCiteCommandso no定義的內容\usebibmacro{citeauthor}

所以新的程式碼可能是:

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

運行這個,在 biblatex 中設定更有趣的引用樣式: \usepackage[citestyle=authoryear]{biblatex} 給:

固定的

相關內容