1

I'm using biblatex and hyperref. If I type \href{<url>}{<name>} where the url contains a #, I get the desired result, but if I type \cite[\href{<url>}{<name>}]{<label>} (again with #<url>) I get an error. What's happening? Here's a MWE:

\usepackage{filecontents}
\usepackage{hyperref}
\usepackage[style=alphabetic,sorting=nty]{biblatex}

\begin{filecontents}{bibliography.bib}
@book{qui,
    author = {Cervantes, Miguel de},
    title = {Don Quijote de la Mancha},
    publisher = {Ediciones Bruguera},
    year = {2001}
}
\end{filecontents}

\addbibresource{bibliography.bib}

\begin{document}

\cite[\href{https://es.wikipedia.org/wiki/Don_Quijote_de_la_Mancha#El_lugar_de_La_Mancha}{wiki}]{qui}

\printbibliography

\end{document}

2 Answers 2

0

Okay, if one adds \ before # in the url everything works fine, as in \cite[\href{https://es.wikipedia.org/wiki/Don_Quijote_de_la_Mancha\#El_lugar_de_La_Mancha}{wiki}]{qui}.

0

I think you're better off pursuing a different approach than the one given in your own answer: (a) provide an url field inside the bibliographic entry, (b) load the xurl package to allow linebreaks at arbitrary points in a long URL string, and (c) use an ordinary \cite directive, i.e., one without an optional argument that contains an \href directive. That way, you never have to concern yourself with having to escape various TeX-special characters such as #.

enter image description here

Obviously, you're free to make different color choices for citecolor and urlcolor than the ones made in the example code presented below.

\documentclass{article}
\begin{filecontents}[overwrite]{bibliography.bib}
@book{qui,
    author = {Miguel de Cervantes},
    title  = {Don Quijote de la Mancha},
    publisher = {Ediciones Bruguera},
    year   = {2001},
    url    = {https://es.wikipedia.org/wiki/Don_Quijote_de_la_Mancha#El_lugar_de_La_Mancha}
}
\end{filecontents}

\usepackage[T1]{fontenc}
\usepackage{xurl}
\usepackage[colorlinks,citecolor=red,urlcolor=blue]{hyperref}
\usepackage[style=alphabetic,sorting=nty]{biblatex}
\addbibresource{bibliography.bib}

\begin{document}
\noindent
\cite{qui}
\printbibliography
\end{document}
1
  • I actually needed to get the url inside the \cite (the Quijote example was made up), but thank you anyway ^^. Commented Oct 17, 2023 at 8:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .