[Tex/LaTex] showlabels: wrap labels in marginpar

marginparshowlabelswrap

I use the showlabels package to highlight labels, references and citations. It appears that, by default, showlabels cannot wrap the keys in the marginpar. If I have a series of citations in one line, only one or two keys are shown and the rest disappears.

Is it possible to force the wrapping of keys in the marginpar?

MWE:

\documentclass{article}

% \usepackage{showkeys}

\usepackage{showlabels}
\showlabels{cite}

\usepackage{filecontents}
\usepackage[
    style=alphabetic,
    sorting=nyt,
    firstinits=true,
    backend=biber
]{biblatex}

\begin{filecontents}{references.bib}
  @report{example1,
    author={{Archibald Author}},
    title={Archies first report}
    }
  @report{example2,
    author={{Archibald Author}},
    sortname={Author, Archibald},
    title={Archies second report}
    }
  @report{example3,
    author={Archibald Author},
    sortname={Author, Archibald},
    title={Archies third report}
    }
  @report{example4,
    author={Buthor, Baltasar},
    title={Balties report}
    }
  @report{example5,
    author={Cuthor, Charlie},
    title={Charlies report}
    }
\end{filecontents}
\bibliography{references.bib}

\begin{document}
  \cite{example1,example2,example3,example4,example5}
  \printbibliography
\end{document}

enter image description here

Best Answer

Always good to hack the opposition:-)

enter image description here

\documentclass{article}

% \usepackage{showkeys}

\usepackage{showlabels}
\showlabels{cite}

\makeatletter
\def\SL@margtext#1{%
  \ifmmode
    \xdef\SL@labelname{\SL@prlabelname{#1}}%
  \else
    \setbox\@tempboxa=\vtop to 0pt{\vss
  \@for\@tmpa:=#1\do{%
      \hbox to \hsize{\expandafter\SL@lrtext\expandafter{\@tmpa}}}\vss}%
    \dp\@tempboxa\z@
    \ifvmode
      \@tempdima=\prevdepth
      \nointerlineskip\box\@tempboxa\nobreak
      \prevdepth=\@tempdima
    \else
      \vadjust{\box\@tempboxa\nobreak}%
    \fi
  \fi
}
\let\SL@setlabel\SL@margtext
\makeatother

\usepackage{filecontents}
\usepackage[
    style=alphabetic,
    sorting=nyt,
    firstinits=true,
    backend=bibtex
]{biblatex}

\begin{filecontents}{references.bib}
  @report{example1,
    author={{Archibald Author}},
    title={Archies first report}
    }
  @report{example2,
    author={{Archibald Author}},
    sortname={Author, Archibald},
    title={Archies second report}
    }
  @report{example3,
    author={Archibald Author},
    sortname={Author, Archibald},
    title={Archies third report}
    }
  @report{example4,
    author={Buthor, Baltasar},
    title={Balties report}
    }
  @report{example5,
    author={Cuthor, Charlie},
    title={Charlies report}
    }
\end{filecontents}
\bibliography{references.bib}

\begin{document}
  \cite{example1,example2,example3,example4,example5}
  \printbibliography
\end{document} 
Related Question