# Url in section title

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}

\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.

• 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
• @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

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}