我想在数学模式下使用超链接而不更改间距或字距。即,我想定义一个\mathhyperref
类似于数学模式下超链接的正确字距调整但更灵活(我不想根据是否有下标等使用不同的命令)。我设法处理下标(基于标题内的 \colorlet{saved}{.} 产生错误经过大卫·卡莱尔),但我仍然在努力\tilde{}
:
平均能量损失
\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}
您知道如何修复这个问题吗?
答案1
我个人不喜欢把所有东西都做成链接。如果你一碰东西就跳来跳去,浏览 pdf 会很困难。但如果你真的想要,你可以试试 lualatex 和(高度实验性的)lua-links 包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}