1

Before I start my apologies if this isn't how to do a follow up a question.

First, read the answer to this this post detailing what I am trying to accomplish that flushes backrefs right (with biblatex and backref option), and outside of the margins here:

Biblatex: pagebackref reference in the (flush) right margin

Now I really like this code, since I think it looks nice and clean, and allows for nice linking of backrefs. However, an issue arises when there is a reference that goes all the way to the end. The backref link gets moved to a new line, which I obviously do not want. Do any latex experts know how to fix this?

See picture below.

enter image description here

This is the code that I pasted into my thesis:

\renewbibmacro*{pageref}{%
   \iflistundef{pageref}
     {\renewcommand{\finentrypunct}{\addperiod}}
     {\renewcommand{\finentrypunct}{\addspace}%
      \printtext{\addperiod\hfill\rlap{\hskip15pt\colorbox{blue!5}{\scriptsize\printlist[pageref][-\value{listtotal}]{pageref}}}}}}

Any help is appreciated!

EDIT: Here is MWE showing the error

\documentclass{article}
\usepackage{times}
\usepackage{csquotes}
\usepackage{xcolor}
\pagecolor{white} %renders latex PDF in white background
\usepackage[style=numeric-comp,backref=true,backend=biber]{biblatex}
\usepackage{filecontents}

\begin{filecontents}{\jobname.bib} @article{RN283, author = {Sparkes, R. S. and Simon, M. and Cohn, V. H. and Fournier, R. E. and Lem, J. and Klisak, I. and Heinzmann, C. and Blatt, C. and Lucero, M. and Mohandas, T.}, title = {Assignment of the human and mouse prion protein genes to homologous chromosomes}, journal = {Proceedings of the National Academy of Sciences}, volume = {83}, number = {19}, pages = {7358}, DOI = {10.1073/pnas.83.19.7358}, url = {http://www.pnas.org/content/83/19/7358.abstract}, year = {1986}, type = {Journal Article} }

@article{RN210, author = {Stahl, Neil and Borchelt, David R. and Hsiao, Karen and Prusiner, Stanley B.}, title = {Scrapie prion protein contains a phosphatidylinositol glycolipid}, journal = {Cell}, volume = {51}, number = {2}, pages = {229-240}, ISSN = {0092-8674}, DOI = {https://doi.org/10.1016/0092-8674(87)90150-4}, url = {http://www.sciencedirect.com/science/article/pii/0092867487901504}, year = {1987}, type = {Journal Article} } \end{filecontents}

\addbibresource{\jobname.bib}

% pagereference in the right margin \renewbibmacro*{pageref}{% \iflistundef{pageref} {\renewcommand{\finentrypunct}{\addperiod}} {\renewcommand{\finentrypunct}{\addspace}% \printtext{\addperiod\hfill\rlap{\hskip15pt\colorbox{blue!5}{\scriptsize\printlist[pageref][-\value{listtotal}]{pageref}}}}}}

\begin{document} Example citation \cite{RN283, RN210} \printbibliography \end{document}

enter image description here

jfang5
  • 49
  • I cannot reproduce the problem. I tried https://gist.github.com/moewew/c91724d6cf08244c0a59dbcebdaf51c5 where an entry goes right up to the margin and I don't get a spurious line break. Please show us a short example document that reproduces the undesirable output shown in the image with as little code as possible. Without the code that reproduces the issue we will not be able to help you properly. (https://tex.meta.stackexchange.com/q/228/35864, https://tex.meta.stackexchange.com/q/6255/35864) – moewe Jul 06 '21 at 15:39
  • Sorry about that I added a MWE and the output showing what happens! – jfang5 Jul 06 '21 at 19:02

1 Answers1

2

To write into the margin I like to use the method from egreg's answer to Add a marker to the left of the text.

Here I think it would be more pleasing to have the backref appear in the first line of an entry and not on the last line, so we hook into begentry. In any case we need to be careful about the punctuation tracker to avoid unwanted punctuation in some places.

\documentclass{article}
\usepackage{times}
\usepackage{csquotes}
\usepackage{xcolor}
\usepackage[backend=biber, style=numeric-comp, backref=true,]{biblatex}
\usepackage[colorlinks]{hyperref}

\newlength{\marginwritesep} \setlength{\marginwritesep}{1em}

% based on egreg's (https://tex.stackexchange.com/users/4427/egreg) % answer to https://tex.stackexchange.com/a/123451/35864 % originally CC BY-SA 3.0, but dual-licensed under LPPL % see https://tex.meta.stackexchange.com/a/3333/35864 \newcommand{\marginwrite}[1]{% \strut\vadjust{% \vbox to 0pt{% \kern-\the\dimexpr\ht\strutbox+\dp\strutbox\relax \hfill\rlap{\kern\marginwritesep #1}% \vss }% }% }

\renewbibmacro*{pageref}{}

\makeatletter \renewbibmacro*{begentry}{% \iflistundef{pageref} {} {\marginwrite{% \colorbox{blue!5}{% \scriptsize\raggedright \printlist[pageref][-\value{listtotal}]{pageref}}}% \blx@initunit}} \makeatother

\begin{filecontents}{\jobname.bib} @article{RN283, author = {Sparkes, R. S. and Simon, M. and Cohn, V. H. and Fournier, R. E. and Lem, J. and Klisak, I. and Heinzmann, C. and Blatt, C. and Lucero, M. and Mohandas, T.}, title = {Assignment of the human and mouse prion protein genes to homologous chromosomes}, journal = {Proceedings of the National Academy of Sciences}, volume = {83}, number = {19}, pages = {7358}, DOI = {10.1073/pnas.83.19.7358}, url = {http://www.pnas.org/content/83/19/7358.abstract}, year = {1986}, type = {Journal Article} } @article{RN210, author = {Stahl, Neil and Borchelt, David R. and Hsiao, Karen and Prusiner, Stanley B.}, title = {Scrapie prion protein contains a phosphatidylinositol glycolipid}, journal = {Cell}, volume = {51}, number = {2}, pages = {229-240}, ISSN = {0092-8674}, DOI = {https://doi.org/10.1016/0092-8674(87)90150-4}, url = {http://www.sciencedirect.com/science/article/pii/0092867487901504}, year = {1987}, type = {Journal Article} } \end{filecontents} \addbibresource{\jobname.bib}

\begin{document} Example citation \cite{RN283, RN210} \printbibliography \end{document}

Backref boxes on first line of entry.

See also Biblatex: newline among pageback references in margin.

Note that the doi field should only contain the DOI proper and not the link bit https://doi.org/ or http://dx.doi.org/. So DOI = {https://doi.org/10.1016/0092-8674(87)90150-4}, should be changed to

DOI = {10.1016/0092-8674(87)90150-4},

I didn't do that in the MWE though, because we need the lines to line up as before.

moewe
  • 175,683