href: \test 定义中的参数编号非法

href: \test 定义中的参数编号非法

我尝试使用命令\href{url}{anchor text}链接页面,但遇到了问题\test 定义中的参数编号非法

该错误可能是由#URL 引起的。以下是 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}

我该如何解决这个问题?

答案1

您正在框架中使用命令。由于它们具有 catcode magic,因此您必须使用以下选项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}

在此处输入图片描述

相关内容