scrlayer-notecolumn `\makenote` 和 `BibLaTeX`

scrlayer-notecolumn `\makenote` 和 `BibLaTeX`

繼續我的 BibLaTeX + scrlayer-notecolumn 之旅。我想,一旦我有了 BibLaTeX,\marginpar一切都會變得容易。但事實並非如此。

我想使用scrlayer-notecolumn's 創建我的側邊欄\makenote

微量元素:

\documentclass{scrbook}

\usepackage{scrlayer-notecolumn}

% bib-file
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
  @book{Knu86,
    author = {Knuth, Donald E.},
    year = {1986},
    title = {The \TeX book},
  }
}  
\end{filecontents}

\usepackage[backend=bibtex, citestyle=authoryear]{biblatex}
\addbibresource{\jobname}

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


\begin{document}
    hi
    \makenote{a side note}

    \tcite{Knu86}
\end{document}

\marginpar{

使用註解掉的\marginpar效果很好:

marginpar 工作演示


\makenote{

使用則\makenote不然。

不工作

有錯誤: line 35: Undefined control sequence. \end{document} : Overwriting file `./dco2.bib'. : Using fall-back BibTeX(8) backend:(biblatex) functionality may be reduced/unavailable. : \clearnotecolumns while active non-layer page style. line 35: Flush note box `marginpar' : \pdfmdfivesum unavailable.


\makenote{\保護

對我來說,這似乎可能很脆弱,所以我曾經protect 改變過\makenote{\protect\printfield{title}}

受保護的

這給了我基本上相同的錯誤集。

line 35: Undefined control sequence. \end{document}
: Overwriting file `./dco2.bib'.
: Using fall-back BibTeX(8) backend:(biblatex) functionality may be reduced/unavailable.
: \clearnotecolumns while active non-layer page style.
line 35: Note moved down from(scrlayer-notecolumn) 11.0pt to 15.08002pt(scrlayer-notecolumn) at note box `marginpar'
line 35: Flush note box `marginpar'
: \pdfmdfivesum unavailable.

答案1

這確實是一個擴展問題。\makenote寫入輔助文件。所以會用到寫擴充。但\printfield{title}不會擴展到標題。如果你保護它,就會\printfield{title}被寫入該檔案。這沒有幫助,因為輔助文件的讀取狀態\printfield{title}也無法擴展到標題。

所以你需要的是把它放入 的論證中的標題\makenote。這樣做的標準方法是使用\edef\helpermacro{\printfield{title}}or\protected@edef\helpermacro{\printfield{title}}然後使用\makenote{\helpermacro}。但這也不能完成這項工作,因為在使用 cite 指令時,\printfield{title}只會擴展到\printfield {title}.

但是您也可以使用另一個鉤子,即 field 的欄位格式title。我們只需定義一個makenote用於\makenote列印欄位的新欄位格式並使用此新格式來列印該欄位title

\documentclass{scrbook}

\usepackage{scrlayer-notecolumn}

\usepackage[backend=bibtex, citestyle=authoryear]{biblatex}
\addbibresource{biblatex-examples}

\DeclareFieldFormat{makenote}{\makenote{#1}}% define new makenote field format

\DeclareCiteCommand{\tcite}
{\usebibmacro{prenote}}
{   %loopcode
    \usebibmacro{cite}%
    \printfield[makenote]{title}% use makenote format to print field title
    %\makenote{\printfield{title}}
    %\marginpar{\printfield{title}}
}
{\multicitedelim}
{\usebibmacro{postnote}}


\begin{document}
    hi\makenote{a side note}

    Here a \verb|\tcite{knuth:ct}|: \tcite{knuth:ct}
\end{document}

格式化結果

與格式相反,您也可以定義一個\mkbibmakenote類似於以下內容的新包裝器\mkbibfootnote

\documentclass{scrbook}

\usepackage{scrlayer-notecolumn}

\usepackage[backend=bibtex, citestyle=authoryear]{biblatex}
\addbibresource{biblatex-examples}

\newrobustcmd{\mkbibmakenote}[1]{%
  \makenote*{\blxmkmakenote{#1}}%
}
\makeatletter
\newrobustcmd{\blxmkmakenote}[1]{%
  \begingroup
    \blx@blxinit
    \blx@setsfcodes
    \blx@postpunct@agroup
    #1%
  \endgroup
}
\makeatother

\DeclareCiteCommand{\tcite}[\mkbibmakenote]
{\usebibmacro{prenote}}
{%
    \usebibmacro{author}%
    \newunit
    \usebibmacro{title}%
}
{\multicitedelim}
{\usebibmacro{postnote}}


\begin{document}
    hi\makenote{a side note}

    Here a \verb|\tcite{knuth:ct}|: \tcite{knuth:ct}done.
\end{document}

包裝結果

如果您需要兩者,文字中的引用列印和頁邊空白中的引用列印,您必須定義自己的命令,即 a\cite和 a \tcite

相關內容