3

Unlike most people, I'm trying to prevent breaking the URL in my bibliography. In the case below, the URL in the first item should stay the way it is, since it is not broken across the lines. The URL in the second item is too long to fit on the line that it starts on, and so it is broken across two lines. In that case, the URL should be on the last line on its own. In short, I just want to prevent line breaks in URLs. The bibliography entries should otherwise be justified as they normally are.

\documentclass{article}
\usepackage[paper = a4paper, vmargin = 1in]{geometry}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@BOOK{indreboe1951,
    AUTHOR = "Gustav Indreb\o",
    TITLE = "Norsk m\aa lsoga",
    YEAR = "1951",
    LOCATION = "Bergen",
    PUBLISHER = "John Grieg",
    URL = "http://urn.nb.no/URN:NBN:no-nb_digibok_2010110808058"}
@ARTICLE{haraldsrud2015,
    AUTHOR = "Andreas Droslum Haraldsrud",
    TITLE = "Dansk og norsk danna talem\aa l -- ei spr\aa khistorisk jamf\o ring",
    JOURNALTITLE = "Spr\aa klig Samling \AA rbok",
    YEAR = "2015",
    PAGES = "52--89",
    VOLUME = "2014",
    URL = "http://samnorsk.no/medlemsbladet/"}
\end{filecontents*}
\usepackage[style = authoryear-comp]{biblatex}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{*}
\printbibliography
\end{document}

enter image description here

2

Please have a look to the following code. Please see that I used some code from this question, see acepted answer .

MWE:

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@BOOK{indreboe1951,
  AUTHOR    = {Gustav Indreb\o},
  TITLE     = {Norsk m\aa lsoga},
  YEAR      = {1951},
  LOCATION  = {Bergen},
  PUBLISHER = {John Grieg},
  URL       = {http://urn.nb.no/URN:NBN:no-nb_digibok_2010110808058},
}
\end{filecontents*}


\documentclass{article}
\usepackage[%
  paper = a4paper, vmargin = 1in,
  showframe
]{geometry}
%\usepackage{ragged2e}
\usepackage{microtype}

\usepackage[%
  style = authoryear-comp,
  backend=biber,
]{biblatex}

% Following code you find in 
% https://tex.stackexchange.com/questions/29802/biblatex-and-new-line-for-doi-url-and-eprint
\newbibmacro*{bbx:parunit}{%
  \ifbibliography
    {\setunit{\bibpagerefpunct}\newblock
     \usebibmacro{pageref}%
     \clearlist{pageref}%
     \setunit{\adddot\par\nobreak}}
    {}}

\renewbibmacro*{doi+eprint+url}{%
  \usebibmacro{bbx:parunit}% Added
  \iftoggle{bbx:doi}
    {\printfield{doi}}
    {}%
  \iftoggle{bbx:eprint}
    {\usebibmacro{eprint}}
    {}%
  \iftoggle{bbx:url}
    {\usebibmacro{url+urldate}}
    {}}

\renewbibmacro*{eprint}{%
  \usebibmacro{bbx:parunit}% Added
  \iffieldundef{eprinttype}
    {\printfield{eprint}}
    {\printfield[eprint:\strfield{eprinttype}]{eprint}}}

\renewbibmacro*{url+urldate}{%
  \usebibmacro{bbx:parunit}% Added
  \printfield{url}%
  \iffieldundef{urlyear}
    {}
    {\setunit*{\addspace}%
     \printtext[urldate]{\printurldate}}}

\addbibresource{\jobname.bib}

\begin{document}
\nocite{indreboe1951}

\printbibliography

\end{document}

and the result:

enter image description here

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.