3

I'm trying to put an url in the title of a subsection in a report. I am using the package hyperref. What I am doing is:

\documentclass{report}
\usepackage[english]{babel}
\usepackage{hyperref}

\begin{document}

\section{Matlab code}
\subsection{\nolinkurl{file1.m}}

\end{document}

This won't compile as I get the following error:

! File ended while scanning use of \@@BOOKMARK.<inserted text>\par\begin{document}

Actually, when I compile for the first time, it usually works. But when I try another time, I get that error...

I am using Texmaker and MiKTeX.

Thanks for your help !

  • 2
    Welcome to TeX.SE. Try \subsection{\texorpdfstring{\nolinkurl{file1.m}}{file1.m}} which prevents content not allowed for PDF strings (as in bookmarks) – user31729 Aug 17 '17 at 22:26
  • 1
    @ChristianHupfer Perhaps you could post an answer with that and Rudy could mark it correct? This is a common issue, that could benefit from a clearly-marked answer. – Coby Viner Aug 18 '17 at 1:46
4

Use \texorpdfstring{tex content}{pdf string content} in order to prevent errors since not any content is allowed in bookmarks (this must be PDF strings)

\documentclass{report}
\usepackage[english]{babel}
\usepackage{hyperref}

\begin{document}

\section{Matlab code}
\subsection{\texorpdfstring{\nolinkurl{file1.m}}{file1.m}}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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