0

I want to use hyperlinks in math mode without changing the spacing or kerning. I.e., I want to define a command \mathhyperref similar to Correct kerning of hyperlinks in math mode but more flexible (I don't want to use different commands depending on if there is a subscript or not and so on). I managed to deal with subscripts (based on \colorlet{saved}{.} inside caption produces error by David Carlisle), but I am still struggeling with \tilde{}:

MWE

\documentclass{article}
\usepackage{amsthm,xcolor,mathtools}
\usepackage[colorlinks]{hyperref}
\newtheorem{definition}{Definition}

\colorlet{linkcolor}{red!70} \hypersetup{linkcolor=linkcolor} \newcommand{\mathlinkcolor}[1]{\mathcolor{linkcolor}{#1}}

\newcommand{\mathhyperref}[2]{\mathrlap{\hyperref[#1]{\phantom{\ensuremath{#2}}}}\mathlinkcolor{#2}}

\newcommand{\linkedtheta}{\mathhyperref{def:theta}{\theta}} %\newcommand{\linkedtheta}{\mathrlap{\hyperref[def:theta]{\phantom{\ensuremath{\theta}}}}\mathlinkcolor{\theta}} % I would like the command to work as similar to theata in terms of spacing as possible, but it should be linked and colored

\begin{document} $\tilde{\theta}$ %correct

$\tilde{\linkedtheta}$ %wrong (the tilde is too far left)

$M_{\theta}$ % correct

$M_{\linkedtheta}$ % correct I think

$\linkedtheta_a^b$ % correct I think

$\theta_a^b$ % correct

\begin{definition}\label{def:theta} $\linkedtheta$ \end{definition} \end{document}

enter image description here

Do you have any idea how to fix this?

Jakob
  • 993
  • \skew{3}\tilde{\linkedtheta}? It might be possible to patch \tilde but I don't think it would be worth it... – campa Nov 16 '23 at 15:50

1 Answers1

2

Personally I don't like it at all if everything is made a link. It make navigating a pdf difficult if you jump around as soon as you touch something. But if you really want you could try lualatex and the (highly experimental) lua-links package from https://github.com/zauguin/lua-links

\DocumentMetadata{}
\documentclass{article}
\usepackage{luacolor}
\usepackage[discard,tightH,tightV,unbox]{lua-links}
\usepackage{amsthm,xcolor,mathtools}
\usepackage[colorlinks]{hyperref}
\newtheorem{definition}{Definition}

\colorlet{linkcolor}{red!70} \hypersetup{linkcolor=linkcolor}

\newcommand{\mathhyperref}[2]{\hyperref[#1]{#2}} \newcommand{\linkedtheta}{\mathhyperref{def:theta}{\theta}}

\begin{document} $\tilde{\theta}$ %correct

$\tilde{\linkedtheta}$ %wrong (the tilde is too far left)

$M_{\theta}$ % correct

$M_{\linkedtheta}$ % correct I think

$\linkedtheta_a^b$ % correct I think

$\theta_a^b$ % correct

\begin{definition}\label{def:theta} $\linkedtheta$ \end{definition} \end{document}

enter image description here

Ulrike Fischer
  • 327,261