防止 biblatex 书目中的 URL 出现换行符

防止 biblatex 书目中的 URL 出现换行符

与大多数人不同,我试图防止破坏我的参考书目中的 URL。在下面的例子中,第一个项目中的 URL 应该保持原样,因为它没有跨行。第二个项目中的 URL 太长,无法放在它开始的那一行,所以它跨了两行。在这种情况下,URL 应该单独放在最后一行。简而言之,我只是想防止 URL 中出现换行。参考书目条目应该像平常一样对齐。

\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}

在此处输入图片描述

答案1

请看下面的代码。请注意,我使用了一些来自这个问题,请参阅已接受的答案

梅威瑟:

\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}

结果:

在此处输入图片描述

相关内容