Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Using biblatex with alphabetic style, how could I insert a line break (\\ or \linebreak) before the URL output (with the aim to have less linebreaks within URL)? (I use url and hyperref)


Slightly enhancing @Marco's original answer:

If it should be totally like in the original but with a line break, use

\DeclareFieldFormat{url}{\newline\mkbibacro{URL}\addcolon\space\url{#1}}
\newbibmacro*{url+urldate}{%
 \printfield[url]{url}%   
 \iffieldundef{urlyear}     
 {}     
 {\setunit*{\addspace}%      
 \printtext[urldate]{\printurldate}}}
share|improve this question
add comment

2 Answers

up vote 6 down vote accepted
\documentclass{scrartcl}
\usepackage{xcolor}
\usepackage[style=authoryear,backend=biber,]{biblatex}
\usepackage[colorlinks=true,urlcolor=red!50!black]{hyperref}
\addbibresource{biblatex-examples.bib}
\DeclareFieldFormat{formaturl}{\newline #1}
\newbibmacro*{url+urldate}{%
\printtext[formaturl]{%
  \printfield{url}}%
  \iffieldundef{urlyear}
    {}
    {\setunit*{\addspace}%
     \printtext[urldate]{\printurldate}}}

\begin{document}
\cite{ctan}
\printbibliography
\end{document}

With DeclaredFieldFormat you can format the whole string of url and urldate. In this case I insert a \newline in front of the ouput.

EDIT:

added printtext

enter image description here

share|improve this answer
    
thanks, it adds a line.. but it changes the text style, before it was kind of verbatim and now it's like the rest of the text.. How come? –  Johannes L Sep 9 '11 at 12:31
    
@JohannesL: Now it works ;-) –  Marco Daniel Sep 9 '11 at 12:48
    
I also found a version were it works (in my output, the URL wasn't colored anyway) –  Johannes L Sep 9 '11 at 12:50
    
@JohannesL: I used colorlinks=true to demonstrate a link. The boxes around a link are not printed. –  Marco Daniel Sep 9 '11 at 12:51
add comment

I found the following package useful for line breaking an URL. At the preamble, just put \usepackage{breakurl} somewhere after \usepackage{hyperref}. The \burl command is defined and, by default, the package also turns the \url command into a synonym of \burl.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.