0

I have a bibliography in which I included hyperlinks to the publication sites in the bibliography. Now I would like to include a line break within the hyperlink because the references are too long.

None of the options I have found so far have worked, I would appreciate any help. Apologies, if this has an obvious solution, I'm a Latex beginner. I am using the LaTex compiler on Overleaf.

Here is my code:

\documentclass{scrbook}
\usepackage[backend=biber, style=chem-angew]{biblatex}
\usepackage{hyperref}

\DeclareFieldFormat{doilink}{% \iffieldundef{url}{% #1% }{% \href{http://dx.doi.org/\thefield{url}}{#1}% }% } \DeclareBibliographyDriver{article}{% \printtext[doilink]{% \usebibmacro{author}% \newunit \usebibmacro{journal+issuetitle}% \newunit \usebibmacro{note+pages}% }% }

\addbibresource{Library.bib} \begin{document}

\noindent Reference 1\autocite{RN398} \newline Reference 2\autocite{RN404} \printbibliography[heading=none]

\end{document}

and my References

@article{RN398,
   author = {Stabile, Paolo and Lamonica, Alessandro and Ribecai, Arianna and Castoldi, Damiano and Guercio, Giuseppe and Curcuruto, Ornella},
   journal = {Tetrahedron Lett.},
   volume = {51},
   number = {37},
   pages = {4801-4805},
   url = {10.1016/j.tetlet.2010.06.139},
   year = {2010}
}

@article{RN404, author = {Cordes, D. B. and Hua, G. and Slawin, A. M. and Woollins, J. D.}, journal = {Acta Crystallogr C}, volume = {67}, number = {Pt 12}, pages = {509-514}, url = {10.1107/S0108270111049900}, year = {2011} }

Bernard
  • 271,350
piggy
  • 71

1 Answers1

1

The following code breaks lines correctly with pdfLaTeX, LuaLaTeX and XeLaTeX.

It was only slightly modified from your code to use the doi field instead of url, because 10.1016/j.tetlet.2010.06.139 is not a URL an the code links to teh DOI resolver all the time anyway.

\documentclass{scrbook}
\usepackage[backend=biber, style=chem-angew]{biblatex}

\usepackage{showframe}

\usepackage{hyperref}

\DeclareFieldFormat{doilink}{% \iffieldundef{doi} {#1} {\href{https://doi.org/\thefield{doi}}{#1}}}

\DeclareBibliographyDriver{article}{% \printtext[doilink]{% \usebibmacro{author}% \newunit \usebibmacro{journal+issuetitle}% \newunit \usebibmacro{note+pages}% }% }

\begin{filecontents}{\jobname.bib} @article{RN398, author = {Stabile, Paolo and Lamonica, Alessandro and Ribecai, Arianna and Castoldi, Damiano and Guercio, Giuseppe and Curcuruto, Ornella}, journal = {Tetrahedron Lett.}, volume = {51}, number = {37}, pages = {4801-4805}, doi = {10.1016/j.tetlet.2010.06.139}, year = {2010}, } @article{RN404, author = {Cordes, D. B. and Hua, G. and Slawin, A. M. and Woollins, J. D.}, journal = {Acta Crystallogr C}, volume = {67}, number = {Pt 12}, pages = {509-514}, doi = {10.1107/S0108270111049900}, year = {2011}, } \end{filecontents} \addbibresource{\jobname.bib} \begin{document} Reference 1\autocite{RN398}

Reference 2\autocite{RN404}

\printbibliography[heading=none] \end{document}

Nicely broken lines

Note that the screenshot does not reproduce the link boxes, but the links are there.

Just to verify that everything works as expected on Overleaf as well, follow https://www.overleaf.com/read/zvsvhcvgsbgy to see the MWE on overleaf.

moewe
  • 175,683
  • Hi, thanks for the help. For another reason, I have to use the LaTex compiler, is there a way to get line breaks with the LaTex compiler as well? – piggy Jul 20 '21 at 09:46
  • @piggy I'm pretty sure that on the LaTeX-to-DVI route you can't get your links broken nicely. There is \usepackage[breaklinks]{hyperref}, which allows links to break, but messes up the link targets. I'd look into a way to use a compiler different from LaTeX. There are ways to get .eps graphics into your PDF file even with pdfLaTeX for example. – moewe Jul 20 '21 at 09:51
  • Alright, I'll look into that, thanks! – piggy Jul 20 '21 at 19:54