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?

1
  • 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: tex.stackexchange.com/q/35310/134144
    – leandriis
    Nov 17, 2017 at 8:54

1 Answer 1

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

You must log in to answer this question.

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