使用 optidef 進行引用不起作用

使用 optidef 進行引用不起作用

我自己的標籤 (P) 有最佳化問題。但是,\ref{e}指的是最佳化問題而不是方程式。沒有 \tag(P) 一切正常。有什麼辦法可以解決這個問題嗎?

\documentclass[11pt,a4paper]{scrreprt}

\usepackage{amsmath}
\usepackage{optidef}
\usepackage{hyperref}

\begin{document}
    
\begin{mini}|s|
    {}{c^\top x}
    {\tag{P}\label{P}}
    {}
    \addConstraint{Ax}{=b}
    \addConstraint{x}{\geq 0}.
\end{mini}

\begin{align}
    1+e^{i \pi} = 0 \label{e}
\end{align} 

Reference to \ref{P}

Reference to \ref{e}
    
\end{document}

答案1

您可以在環境\theHequation內部進行修復mini

\documentclass[11pt,a4paper]{scrreprt}

\usepackage{amsmath}
\usepackage{optidef}
\usepackage{hyperref}

\newcommand{\ui}{\mathrm{i}}% if you really want upright

\AddToHook{env/mini/begin}{%
  \edef\theHequation{mini\unexpanded\expandafter{\theequation}}%
}

\begin{document}

\begin{mini}|s|
    {}{c^\top x}
    {\tag{P}\label{P}}
    {}
    \addConstraint{Ax}{=b}
    \addConstraint{x}{\geq 0}.
\end{mini}

\begin{align}
    1+\exp(\ui \pi) = 0 \label{e}
\end{align} 

Reference to \ref{P}

Reference to \ref{e}
    
\end{document}

這些連結將指向正確的位置。

旁白:\i在數學模式下不起作用(無論如何都會產生無點 i )。如果您要\i在真實文件中重新定義,請不要這樣做。

在此輸入影像描述

相關內容