5

Continuing my journey into BibLaTeX + scrlayer-notecolumn. I thought, once I had the BibLaTeX working with \marginpar it would all be easy. But not so.

I want to create my sidebar using the scrlayer-notecolumn's \makenote.

MWE:

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

using the commented out \marginpar works fine:

marginpar working demo


\makenote{

using \makenote does not.

not working makenote

With errors: 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

To me this seems like maybe it was being fragile, So I used protect changing to \makenote{\protect\printfield{title}}

protected

Which gave me, basically the same set of errors.

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 Answers1

6

This is indeed an expansion problem. \makenote writes to an auxiliary file. So write expansion will be used. But \printfield{title} won't be expanded to the title. And if you protect it, just \printfield{title} will be written to that file. This does not help, because while the read state of the auxiliary file \printfield{title} cannot expand to the title too.

So what you need is the title to put it into the argument of \makenote. The standard approach to do so would be to use \edef\helpermacro{\printfield{title}} or \protected@edef\helpermacro{\printfield{title}} and then use \makenote{\helpermacro}. But this wouldn't do the job too, because while using the cite command, \printfield{title} will expand only to \printfield {title}.

But there is another hook you can use, the field format of field title. We just can define a new field format makenote that uses \makenote to print a field and use this new format to print the field 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}

format result

In opposite to the format you could also define a new wrapper \mkbibmakenote similar to \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}

wrapper result

If you need both, a cite print in the text and a cite print in the margin you have to define your own command, that does a \cite and a \tcite.

Schweinebacke
  • 26,336