# How to deal with % sign in url when using hyperref and bibentry

In few of my citations I have a % sign in the url, which gives a problem when I use the bibentry environment (Paragraph ended before \BR@c@bibitem was complete). How can I deal with the % sign? Without the reference containing the % in the url everything works fine. Also without using the bibentry the % gives no problem. the % sign gives also no problem using a different bibliography stile as unsrt, which is not using the url information (which I don't want to do). (The bibliography style statto can be found here, same problem occurs using plainnat). Not using \begin{NoHyper}\bibentry{goossens93}\end{NoHyper} would be preferred to hyperlink the reference to the website, but I don't know if this would be possible at all.

    \begin{filecontents}{mytestbib.bib}
@book{goossens93,
author = "Frank Mittelbach and Michel Goossens  and Johannes Braams and David Carlisle  and Chris Rowley",
title = "The {LaTeX} Companion",
year = "1993",
}

@BOOK{Kymissis__2009,
title = {Organic Field Effect Transistors - Theory, Fabrication and Characterization},
publisher = {Springer},
year = {2009},
author = {Kymissis, Ioannis},
abstract = {Organic Field Effect Transistors discusses the fundamental mechanisms
that apply to {OFETs} fabrication, operation, and characterization.
This unique book presents the state-of-the-art in organic field effect
transistors ({OFETs)} with ...},
isbn = {9780387921341},
keywords = {Circuits and Systems, Fabrication and Characterization, Organic Chemistry,
Organic Field Effect Transistors - Theory, Technology \& Engineering
/ Engineering (General)},
language = {English},
shorttitle = {Organic Field Effect Transistors},
timestamp = {2013.10.07},
url = {http://www.springer.com/engineering/circuits+%26+systems/book/978-0-387-92133-4}
}

\end{filecontents}
\documentclass{article}
\usepackage[pdftex]{hyperref}
\usepackage{filecontents}
\usepackage{natbib}
\usepackage{bibentry}
\nobibliography*

\begin{document}

A full in-text cite of
\begin{NoHyper}\bibentry{goossens93}\end{NoHyper}.

A regular citation of \cite{goossens93}.

Problematic cite \cite{Kymissis__2009}

\bibliographystyle{statto}
\bibliography{mytestbib}

\end{document}

• escaping gives still the same problem. So it could be, that the problem is elsewhere. This is however one of 4 citations which gives problems and all hat % signs in the url – Tanja Oct 29 '13 at 9:44

This seems to work: the \BR@c@bibitem macro is patched to change the category code of % before grabbing its argument.

\begin{filecontents}{mytestbib.bib}

@book{goossens93,
author = {Frank Mittelbach and Michel Goossens and Johannes Braams
and David Carlisle and Chris Rowley},
title = {The {LaTeX} Companion},
year = {1993},
}

@BOOK{Kymissis__2009,
title = {Organic Field Effect Transistors - Theory, Fabrication and Characterization},
publisher = {Springer},
year = {2009},
author = {Kymissis, Ioannis},
abstract = {Organic Field Effect Transistors discusses the fundamental mechanisms
that apply to {OFETs} fabrication, operation, and characterization.
This unique book presents the state-of-the-art in organic field effect
transistors ({OFETs)} with ...},
file = {Snapshot:C:\Documents and Settings\haehlen_t\My Documents\Papers\Zotero\storage\KV3VMKEJ\978-0-387-92133-4.html:text/html},
isbn = {9780387921341},
keywords = {Circuits and Systems, Fabrication and Characterization, Organic Chemistry,
Organic Field Effect Transistors - Theory, Technology \& Engineering
/ Engineering (General)},
language = {English},
owner = {haehlen_t},
shorttitle = {Organic Field Effect Transistors},
timestamp = {2013.10.07},
url = {http://www.springer.com/engineering/circuits+%26+systems/book/978-0-387-92133-4}
}

\end{filecontents}
\documentclass{article}
\usepackage{hyperref}
\usepackage{natbib}
\usepackage{bibentry}
\usepackage{etoolbox}
\makeatletter
\let\ORIG@BR@c@bibitem\BR@c@bibitem
\apptocmd\ORIG@BR@c@bibitem{\endgroup}{}{}
\def\BR@c@bibitem{\begingroup\catcode\%=12 \ORIG@BR@c@bibitem}
\makeatother
\nobibliography*

\begin{document}

A full in-text cite of
\begin{NoHyper}\bibentry{goossens93}\end{NoHyper}.

A regular citation of \cite{goossens93}.

Problematic cite \cite{Kymissis__2009}

\begin{NoHyper}\bibentry{Kymissis__2009}\end{NoHyper}

\bibliographystyle{plainnat}
\bibliography{mytestbib}

\end{document}


The bibentry package redefines \bibitem to use the internal macro \BR@c@bibitem which basically grabs the argument of \bibitem and then all that comes up to the first blank line as its second argument. The presence of % in the argument of \url confuses the parser which is unable to see the closing brace, which is behind the %.

Thus we redefine the macro to do the work in two stages:

1. it opens a group;

2. inside this group it sets the category code of % to 12, making it a printable character;

3. calls \ORIG@BR@c@bibitem

The final macro is basically a copy of the original \BR@c@bibitem, with the only change that at the end of its work it issues the \endgroup that balances the \begingroup issued by (the new) \BR@c@bibitem.

• Could you explain what the following part exactly does? \usepackage{etoolbox} \makeatletter \let\ORIG@BR@c@bibitem\BR@c@bibitem \apptocmd\ORIG@BR@c@bibitem{\endgroup}{}{} \def\BR@c@bibitem{\begingroup\catcode\%=12 \ORIG@BR@c@bibitem} \makeatother – Tanja Oct 29 '13 at 10:01
• Thanks. I guess altering in a similar way to not need the \begin{NoHyper}....\end{NoHyper} in order to have the hyperlink in the bibentry is not possible? Or is it worth posting a separate question with this? – Tanja Oct 29 '13 at 10:16
• @user2758804 If I remove the NoHyper` environment, I get a duplicate entry warning. – egreg Oct 29 '13 at 10:29
• Yes this is the problem. I found just this solution and was wondering if it can be avoided without excluding the hyperlink completely – Tanja Oct 29 '13 at 10:37
• @user2758804 We need Heiko for this. ;-) – egreg Oct 29 '13 at 11:36