# biblatex, using space in url doesnt work

when I try to use a space in an url, it displays %20 instead of space. I looked for answers on the internet and found that the use of

\PassOptionsToPackage{obeyspaces}{url}%


should do the trick. It does, but at least for me not inside the bibliography.

Here is a MWE:

\documentclass{article}

\PassOptionsToPackage{obeyspaces}{url}%
\usepackage[backend=biber,sorting=nyt,style=alphabetic]{biblatex}
\usepackage{hyperref}
\bibliography{test}
\begin{document}
\cite{mean_well_rcp-1600_2018}
\url{C:/Test Folder/file}
\printbibliography
\end{document}

@misc{mean_well_rcp-1600_2018,
langid = {Englisch},
title = {RCP-1600 series},
url = {C:/Test Filder/file},
shorttitle = {RCP-1600},
date = {2018-01-15},
author = {MEAN\textasciitilde{}WELL}
}


any suggestions what I'm doing wrong?

• The correct URL is file:///C:/Test%20Folder/file (without any space). See this documentation. – Paul Gaborit Jul 28 '18 at 21:41
• thanks for the info, but thats not what I want it to loke like ob the paper – Jannis.D Jul 28 '18 at 21:54
• A URL/URI can't contain spaces (see RFC 3986). – Paul Gaborit Jul 28 '18 at 22:02
• I know. I don't want to create a valid URL i want to show the file path to the reader of a printed document (the file is on a cd given with the document) – Jannis.D Jul 28 '18 at 22:11

You could redefine the url bibmacro to use urlraw instead of url:

\documentclass{article}

\PassOptionsToPackage{obeyspaces}{url}%
\usepackage[backend=biber,sorting=nyt,style=alphabetic]{biblatex}
\usepackage{hyperref}
\bibliography{test}

\renewbibmacro*{url}{\printfield{urlraw}}
\begin{document}
\cite{mean_well_rcp-1600_2018}
\url{C:/Test Folder/file}
\printbibliography
\end{document}


• Ohhhh beaten by 18 seconds ... And just when I was hoping to test the picture hypothesis you add a picture... – moewe Jul 28 '18 at 19:28
• @moewe ;-). But urlraw was my suggestion ... github.com/plk/biber/issues/159 – Ulrike Fischer Jul 28 '18 at 19:29
• Come to think of it I like your solution slightly better than mine, it would be even better with \printfield[url]{urlraw} instead of just \printfield{urlraw}. – moewe Jul 28 '18 at 19:48
• @moewe if one wants a link (I personally avoid to many links normally) one should probably do \DeclareFieldFormat{urlraw}{\mkbibacro{URL}\addcolon\space\href{\thefield{url}}{\nolinkurl{\thefield{urlraw}}}} so that the encoded url is used for the link. – Ulrike Fischer Jul 28 '18 at 19:53
• Then your biblatex is perhaps outdated. urlraw is rather new. – Ulrike Fischer Jul 28 '18 at 19:56

A file path can't be a valid URL. So, in your bib entry, don't use the url field to store a file path!

# First solution (using eprint and eprinttype fields)

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@misc{mean_well_rcp-1600_2018,
langid = {Englisch},
title = {RCP-1600 series},
eprint = {C:/Test Folder/file},
eprinttype= {raw},
shorttitle = {RCP-1600},
date = {2018-01-15},
author = {MEAN\textasciitilde{}WELL}
}
\end{filecontents*}

\usepackage[backend=biber,sorting=nyt,style=alphabetic]{biblatex}
\usepackage{hyperref}

\DeclareFieldFormat{eprint:raw}{%
}

\begin{document}
\cite{mean_well_rcp-1600_2018}

\printbibliography
\end{document}


# Second Solution (using file field)

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@misc{mean_well_rcp-1600_2018,
langid = {Englisch},
title = {RCP-1600 series},
file = {C:/Test Folder/file},
shorttitle = {RCP-1600},
date = {2018-01-15},
author = {MEAN\textasciitilde{}WELL}
}
\end{filecontents*}

\pagestyle{empty}

\usepackage[backend=biber,sorting=nyt,style=alphabetic]{biblatex}
\usepackage{hyperref}

\DeclareFieldFormat{file}{%
}
\renewbibmacro{finentry}{%
\printfield{file}%
}

\begin{document}
\cite{mean_well_rcp-1600_2018}

\printbibliography
\end{document}

• But then I would go all the way and use the semantically more apt file field, eprint does not seem to be much better than url in terms of abuse. – moewe Jul 29 '18 at 6:40
• @moewe Done... ! – Paul Gaborit Jul 29 '18 at 8:33

C:/Test Folder/file is quite an unusual URL for a bibliography, but of course that may just be for the example. If it is not, though, you may want to look into the file field, it is not used by any of the standard styles, but it would be the semantically sound decision.

Biber escapes URLs into percent encoding. If you don't want that you can show the urlraw field instead, see How to disable percent-encoding in URLs?.

\documentclass{article}
\usepackage[backend=biber,sorting=nyt,style=alphabetic]{biblatex}
\usepackage{hyperref}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{mean_well_rcp-1600_2018,
langid     = {english},
title      = {RCP-1600 series},
url        = {C:/Test Filder/file},
shorttitle = {RCP-1600},
date       = {2018-01-15},
author     = {MEAN\textasciitilde{}WELL}
}
\end{filecontents}

\begin{document}
\cite{mean_well_rcp-1600_2018}
\url{C:/Test Folder/file}
\raggedright
\printbibliography
\end{document}


You can be a bit safer and link to the encoded version while showing the unencoded version with

\DeclareFieldFormat{url}{%
\ifhyperref
{\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter
{\thefield{urlraw}}}}


Note that the langid field should contain a language name known to babel or polyglossia. Englisch is not a valid language name in that context, you probably want english.

• follow up question, I decided to use \DeclareFieldFormat{file}{\mkbibacro{file:}\addcolon\space#1} \renewbibmacro{finentry}{% \finentry\addspace \printfield{file}% } but now all my umlauts are missing. (I also added \usepackage[utf8]{inputenc}) to my MWE – Jannis.D Jul 28 '18 at 22:52
• @Jannis.D That is ... odd. Can you ask a new question about that, please. Include the .log file (you can upload it to a text-sharing website such as GitLab Snippes, GitHub Gists, pastebin, ... if it is too long to be included here) and a screenshot of the output you get. – moewe Jul 29 '18 at 4:41
• I will ask a new question. I got it so far that it displays strange looking characters. Thanks for so much help! – Jannis.D Jul 29 '18 at 4:46