scrlayer-notecolumn `\makenote` 与 `BibLaTeX`

scrlayer-notecolumn `\makenote` 与 `BibLaTeX`

继续我的 BibLaTeX + scrlayer-notecolumn 之旅。我想,一旦我使用 BibLaTeX,\marginpar一切都会变得容易.但事实并非如此。

我想使用 来创建我的侧边scrlayer-notecolumn\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则不行。

没有工作 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}}\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}

包装器结果

如果您需要两者,即在文中打印引用和在边距打印引用,则必须定义自己的命令,即执行\cite\tcite

相关内容