0

I am trying to use a code compile-able by both by biblatex (biber) and bibtex but it contains this link in the bibliography:

https://web.archive.org/web/20110412120322/http://www.allheadlinenews.com/briefs/articles/90043651?After%20hesitation%2C%20Jordan%20joins%20in%20Libya%20no-fly%20campaign

The problem is that web.archive redirects to something that backslashed % characters are becoming /% instead of just %.

MWE:

main.tex :

\documentclass{article}
\usepackage{array}
\usepackage{longtable}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}

\xdef\UseBibLaTeX{1} \usepackage[hyphens]{url}

\ifnum\UseBibLaTeX>0 \usepackage[ backend=biber, style=alphabetic, citestyle=authoryear, natbib=true, ]{biblatex} \addbibresource{References.bib} \else \usepackage{natbib} \renewcommand\harvardurl[1]{\textbf{URL:} \url{#1}} \fi

\usepackage[colorlinks]{hyperref}

\begin{document} Test \cite{cite01}

\begin{sloppypar} \ifnum\UseBibLaTeX>0 \printbibliography \else \bibliographystyle{agsm} \bibliography{References} \fi \end{sloppypar}

\end{document}

References.bib:

@article{cite01,
        title ={After hesitation, {Jordan} joins in {Libya} no-fly campaign},
        url ={https://web.archive.org/web/20110412120322/http://www.allheadlinenews.com/briefs/articles/90043651?After\%20hesitation\%2C\%20Jordan\%20joins\%20in\%20Libya\%20no-fly\%20campaign},
        urldate ={2020-08-04},
        month =Apr,
        author={{TML Staff}},
        journal={{All Headline News (AHN)}},
        year ={2011},
        day={06}
}
koleygr
  • 20,105
  • 2
    why are you escaping the % in the bib-file? – Ulrike Fischer Aug 10 '20 at 14:32
  • I had some issues without escaping when using bibtex (let me check and reproduce) – koleygr Aug 10 '20 at 14:36
  • 1
    With biblatex you should definitely not escape any US-ASCII chars (that includes %) in URLs. Most BibTeX styles that properly support URL will also have no problem with unescaped %s (at least when url or hyperref is loaded). If there is a BibTeX style that has a url field yet does not support %, then I would call that a deficiency of that style. – moewe Aug 10 '20 at 14:37
  • 1
    I see the problem. Define \harvardurl as \renewcommand\harvardurl{\textbf{URL:} \url} and not as *\renewcommand\harvardurl[1]{\textbf{URL:} \url{#1}} – moewe Aug 10 '20 at 14:40
  • 1
    as moewe writes your harvardurl command is wrong. – Ulrike Fischer Aug 10 '20 at 14:41
  • @moewe ... I got that command from you some ages before ... Please correct the thread ... https://tex.stackexchange.com/a/455700/120578 – koleygr Aug 10 '20 at 14:43
  • It was throuing the error `Runaway argument? {https://web.archive.org/web/20110412120322/http://www.allheadlinenew\ETC. ! File ended while scanning use of \harvardurl. \par l.3259 \bibliography{References}` – koleygr Aug 10 '20 at 14:44
  • 1
    Well, you live and learn. Corrected. – moewe Aug 10 '20 at 14:45
  • You may add an answer too here with your solution @moewe ... May be will be helpful for future visitors... – koleygr Aug 10 '20 at 14:47

1 Answers1

1

For biblatex you should not (LaTeX-)escape any US-ASCII chars in the url field. That means that % should remain % and should not be escaped as \%.

With BibTeX the situation is not as uniform. The original standard BibTeX styles date back to the eighties before URLs were standardised and therefore don't have a dedicated url field. Later BibTeX styles have URL support, but the exact implementation varies. Most BibTeX styles interface with the url or hyperref package and thus support unescaped URL input. This may, however, not be the case for all styles. But I wouldn't use that as an excuse to insist on escaping %s in URLs, instead I would say that this is a deficiency of those styles.

In this case the solution is simple. Instead of

\renewcommand\harvardurl[1]{\textbf{URL:} \url{#1}}

use

\renewcommand\harvardurl{\textbf{URL:} \url}

The way TeX reads arguments makes \url's tricks to handle special characters break down when it is used in the argument of another command. (This is the same phenomenon you can observe with macros like \verb or \lstinline. See for example http://www.texfaq.org/FAQ-verbwithin, How to pass use lstlisting or lstinline in a command, How to put \verb command inside of \textbf{} block?) In the new definition we cunningly avoid explicitly giving \url's argument and thus allow \url's magic to continue to work.

\documentclass{article}
\usepackage{array}
\usepackage{longtable}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}

\xdef\UseBibLaTeX{0} \usepackage[hyphens]{url}

\ifnum\UseBibLaTeX>0 \usepackage[ backend=biber, style=alphabetic, citestyle=authoryear, natbib=true, ]{biblatex} \addbibresource{\jobname.bib} \else \usepackage{natbib} \renewcommand\harvardurl{\textbf{URL:} \url} \fi

\usepackage[colorlinks]{hyperref}

\begin{filecontents}{\jobname.bib} @article{cite01, title = {After hesitation, {Jordan} joins in {Libya} no-fly campaign}, url = {https://web.archive.org/web/20110412120322/http://www.allheadlinenews.com/briefs/articles/90043651?After%20hesitation%2C%20Jordan%20joins%20in%20Libya%20no-fly%20campaign}, urldate = {2020-08-04}, month = Apr, author = {{TML Staff}}, journal = {All Headline News (AHN)}, year = {2011}, } \end{filecontents}

\begin{document} Test \cite{cite01}

\begin{sloppypar} \ifnum\UseBibLaTeX>0 \printbibliography \else \bibliographystyle{agsm} \bibliography{\jobname} \fi \end{sloppypar}

\end{document}

Correctly displayed URL 'https://web.archive.org/web/20110412120322/http://www.allheadlinenews.com/briefs/articles/90043651?After%20hesitation2C%20Jordan%20joins%20in%20Libya%20no-fly%20campaign'

moewe
  • 175,683