5

I am trying to add more information about the citations in the margins of the page. I am using the memoir document class. Essentially, I do not want to change anything about the cite command, I just want to add information in the margin.

What I have so far is this:

\documentclass[letterpaper,twoside,openany]{memoir}

\usepackage{lipsum}

\setmarginnotes{0.15in}{1.35in}{\baselineskip}
\setulmarginsandblock{1in}{1in}{*}
\setlrmarginsandblock{2.5in}{1.0in}{*}
\checkandfixthelayout
\reversemarginpar

\usepackage[hyperref=true,style=numeric-comp,
            giveninits=true,backref,autocite=superscript,
            sorting=none]{biblatex}

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

\DeclareCiteCommand{\mcite}
  {}
  {\printtext[bibhyperref]{\textsuperscript{\printfield{labelnumber}}}%
    \marginpar{\usebibmacro{sidecite}}%
   }
  {}
  {}

% 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},
}
@book{Gladwell2005,
    author = {Gladwell, Malcolm},
    address = {New York, NY},
    publisher = {Back Bay Books},
    title = {Blink: The Power of Thinking Without Thinking},
    year = {2005},
}
\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}

\lipsum[1] All hail Knuth.\mcite{Knu86}

\lipsum[2-3]
\TeX is hard\mcite{KandR,Gladwell2005}, but not impossible.

It should look like this: \TeX is hard\autocite{KandR,Gladwell2005}, but not impossible. Or perhaps even this\autocite{Knu86,KandR,Gladwell2005}.

\printbibliography

\end{document}

enter image description here

There are several problems here:

1) The superscript in the mcite command does not act as nice as the autocite command, in that it has problems figuring out its proper place when there is punctuation.

2) Citations are no longer being combined nicely, i.e. instead of "2,3", now it says "23". In the same way, citation numbers should be combined to "1-3".

3) The mcite command does not work in captions.

Any idea how to fix any of these issues?

1 Answer 1

7

Since it is quite tricky to create a \marginpar from within a superscript this approach uses the two-pass structure employed by \textcite.

\documentclass[letterpaper,twoside,openany]{memoir}
\usepackage{lipsum}

\setmarginnotes{0.15in}{1.35in}{\baselineskip}
\setulmarginsandblock{1in}{1in}{*}
\setlrmarginsandblock{2.5in}{1.0in}{*}
\checkandfixthelayout
\reversemarginpar

\usepackage[style=numeric-comp,
            giveninits=true, backref, autocite=superscript,
            sorting=none, labeldateparts]{biblatex}

\DeclareFieldFormat{sidecite}{\marginpar{\scriptsize#1}}
\newbibmacro{sidecite}{%
  \printtext[sidecite]{%
    \printfield{labelprefix}%
    \printfield{labelnumber}%
    \setunit{\addperiod\space}%
    \printnames{labelname}%
    \setunit{\printdelim{nametitledelim}}%
    \printfield[citetitle]{labeltitle}%
    \setunit{\addperiod\space}%
    \printlabeldate}%
  \setunit{}}

\makeatletter
\DeclareCiteCommand{\cbx@superpluscite}[\mkbibsuperscript]
  {\usebibmacro{cite:init}%
   \let\multicitedelim=\supercitedelim
   \iffieldundef{prenote}
     {}
     {\BibliographyWarning{Ignoring prenote argument}}%
   \iffieldundef{postnote}
     {}
     {\BibliographyWarning{Ignoring postnote argument}}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}}

\DeclareCiteCommand{\superpluscite}[\cbx@superpluscite@init\cbx@superpluscite]
  {\gdef\cbx@savedkeys{}%
   \citetrackerfalse%
   \pagetrackerfalse%
   \DeferNextCitekeyHook%
   \usebibmacro{cite:init}}
  {\xappto\cbx@savedkeys{\thefield{entrykey},}%
   \usebibmacro{sidecite}}
  {}
  {\protected@xappto\cbx@savedcites{{\cbx@savedkeys}}}

\newrobustcmd{\cbx@superpluscite@init}[2]{%
  \def\cbx@savedcites{#1}#2\cbx@savedcites\empty}

\DeclareCitePunctuationPosition{\superpluscite}{f}
\makeatother

\addbibresource{biblatex-examples.bib}

\begin{document}

\lipsum[1] All hail Knuth.\superpluscite{knuth:ct:a}

\lipsum[2-3]
\TeX is hard\superpluscite{knuth:ct:a,sigfridsson}, but not impossible.

It should look like this: \TeX is hard\autocite{knuth:ct:a,sigfridsson}, but not impossible. Or perhaps even this\autocite{knuth:ct:a,sigfridsson,worman}.

\printbibliography
\end{document}

enter image description here

edit Updated for version 3.12 (2018-10-30) of biblatex. Please look at the edit history if you are using an older version.

5
  • Awesome! One minor thing though: As you can see on the second line from the bottom, "Tex is hard..." the citations still come before the comma. Do you know of any way to ensure that the citations always come after the comma (like the autocite command does, which is shown on the last line)?
    – maero21
    Jan 14, 2018 at 15:09
  • @maero21 \autocite is the only cite command that supports this. I have added a hack to allow \superpluscite to do the same.
    – moewe
    Jan 14, 2018 at 15:28
  • This approach seems to have stopped working in TeX Live 2020 with a whole bunch of control sequence undefined for \iffieldundef, \BibliographyWarning, and LaTeX Error: Missing \begin{document}. at the call to the first iffieldundef. Any ideas on how to make this answer work with the latest LaTeX distribution?
    – maero21
    Jul 16, 2020 at 3:50
  • 2
    @maero21 Check out the edit, please.
    – moewe
    Jul 16, 2020 at 4:10
  • Thanks so much!
    – maero21
    Jul 16, 2020 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.