6

I tried to use the command \href{url}{anchor text} to link a page, but encountered the issue Illegal parameter number in definition of \test.

The error is likely caused by # in url. Here is a MWE.

\documentclass{beamer}
\usetheme{Warsaw}

\usepackage{hyperref}
\hypersetup{
     urlcolor    = blue
}
\usepackage{color}
\urlstyle{same}


\begin{document}

\begin{frame}{Illegal parameter number in definition of \textbackslash test}

This works (without hash): \href{http://example.com/en/revision-control-software-managed-code-smartgit/131_Git}{Text 1}

This doesn't work (with hash): %\href{http://example.com/en/revision-control-software-managed-code-smartgit/#131_Git}{Text 1}

Error case 2: %\href{https://example.com/search?q=user%3A3067748+github}{Text 2}
\end{frame}

\end{document}

How do I slove this problem?

  • 4
    You can use \# instead of # in the url. If you have several urls with a # in it and you want a more automated solution, you might find some inspiration here: https://tex.stackexchange.com/q/35310/134144 – leandriis Nov 17 '17 at 08:54

1 Answers1

10

You are using the commands in a frame. As they do catcode magic you must use the option fragile:

\documentclass{beamer}
\usetheme{Warsaw}

\usepackage{hyperref}
\hypersetup{
     urlcolor    = blue
}
\usepackage{color}
\urlstyle{same}


\begin{document}

\begin{frame}[fragile]{Illegal parameter number in definition of \textbackslash test}

This works (without hash): \href{http://example.com/en/revision-control-software-managed-code-smartgit/131_Git}{Text 1}

This works (with hash): \href{http://example.com/en/revision-control-software-managed-code-smartgit/#131_Git}{Text 1}

This works: \href{https://example.com/search?q=user%3A3067748+github}{Text 2}
\end{frame}

\end{document}

enter image description here

Ulrike Fischer
  • 327,261