我创建了自己的\href
定义,因为它必须满足文档中的一些特定样式要求。现在我发现可选的显示文本不能再像普通文本一样格式化了。例如,空格被删除了。为了最初让它工作,我从其他地方获取了一个解决方案(不知道在哪里,抱歉)。这是 MWE:
\documentclass{article}
\usepackage{xcolor}
\usepackage[hidelinks]{hyperref}
\hypersetup{colorlinks=true, citecolor=, linkcolor=, urlcolor=blue}
\renewcommand\UrlFont{\color{blue}\rmfamily\itshape} % still needs \nolinkurl
\newcommand{\changeurlcolor}[1]{\hypersetup{urlcolor=#1}}
\makeatletter
\def\myhref{\@ifnextchar[{\@with}{\@without}}
\def\@with[#1]#2{\href{#2}{\nolinkurl{#1}}}
\def\@without#1{\href{#1}{\nolinkurl{#1}}}
\makeatother
\begin{document}
\noindent
% works as expected
\href{https://tex.stackexchange.com/}{Tex Stack Exchange}
\newline
% does not work as expected
\myhref[Tex Stack Exchange]{https://tex.stackexchange.com/}
\end{document}