如何给方程式命名(而不仅仅是标签)

如何给方程式命名(而不仅仅是标签)

我有以下代码:

\documentclass{article}

\usepackage[top = 2cm, bottom = 1cm, left = 1.5cm, right = 1.5cm, includefoot]{geometry}

\usepackage[italic = true]{derivative}
\usepackage{physics}

\usepackage{tcolorbox}
\definecolor{blizzardblue}{rgb}{0.4, 0.6, 0.8} 
\definecolor{bleudefrance}{rgb}{0.19, 0.55, 0.91}

\newcommand{\Emph}[1]{{\bfseries #1}}

\NewDocumentCommand{\bline}{somo}{%
\IfBooleanTF{#1}{
    \begin{tcolorbox}[
    colback = blizzardblue!30!white,
    colframe = blizzardblue!30!white,
    ]
    \setlength{\abovedisplayskip}{0pt}
    \begin{flalign*}
        \IfValueT{#2}{\text{\Emph{#2}}} && #3 &&
    \end{flalign*}
    \IfValueT{#4}{\emph{#4}}
    \end{tcolorbox}\noindent%
}{
    \begin{tcolorbox}[
        colback = blizzardblue!30!white,
        colframe = blizzardblue!30!white,
    ]
    \setlength{\abovedisplayskip}{0pt}
    \begin{flalign}
        \IfValueT{#2}{\text{\Emph{#2}}} && #3 &&
    \end{flalign}
    \IfValueT{#4}{\emph{#4}}
    \end{tcolorbox}\noindent%
}}

\usepackage{hyperref}
\newcommand{\eq}[1]{{\hyperref[#1]{eq. ({\color{bleudefrance}\ref*{#1}})}}}

\begin{document}

\bline[Gauss's Law]{
    \label{gaussLaw}
    \nabla\vdot\vb{E} = \frac{\rho}{\epsilon_0}
}
As you can see in \eq{gaussLaw}, it says "1" instead of "Gauss's Law".
\end{document}

产生

在此处输入图片描述

我需要的是:调整代码,使其\eq给出(产生)“高斯定律”而不是“eq (1)”。注释:\tag可能不是我要找的解决方案,因为我想要一个等式的数字。我希望能够通过其数字(1)或名称(高斯定律)来引用该等式。我希望我已经解释清楚了。如果需要更多信息,请告诉我。谢谢阅读。

答案1

您可以定义\@currentlabelname然后使用\nameref

\documentclass{article}

\usepackage[top = 2cm, bottom = 1cm, left = 1.5cm, right = 1.5cm, includefoot]{geometry}

\usepackage[italic = true]{derivative}
\usepackage{physics}

\usepackage{tcolorbox}
\definecolor{blizzardblue}{rgb}{0.4, 0.6, 0.8} 
\definecolor{bleudefrance}{rgb}{0.19, 0.55, 0.91}

\newcommand{\Emph}[1]{{\bfseries #1}}

\makeatletter
\NewDocumentCommand{\bline}{somo}{%
\def\@currentlabelname{#2}%
\IfBooleanTF{#1}{
    \begin{tcolorbox}[
    colback = blizzardblue!30!white,
    colframe = blizzardblue!30!white,
    ]
    \setlength{\abovedisplayskip}{0pt}
    \begin{flalign*}
        \IfValueT{#2}{\text{\Emph{#2}}} && #3 &&
    \end{flalign*}
    \IfValueT{#4}{\emph{#4}}
    \end{tcolorbox}\noindent%
}{
    \begin{tcolorbox}[
        colback = blizzardblue!30!white,
        colframe = blizzardblue!30!white,
    ]
    \setlength{\abovedisplayskip}{0pt}
    \begin{flalign}
        \IfValueT{#2}{\text{\Emph{#2}}} && #3 &&
    \end{flalign}
    \IfValueT{#4}{\emph{#4}}
    \end{tcolorbox}\noindent%
}}

\usepackage{hyperref}
\newcommand{\eq}[1]{{\hyperref[#1]{eq. ({\color{bleudefrance}\ref*{#1}})}}}

\begin{document}

\bline[Gauss's Law]{
    \label{gaussLaw}
    \nabla\vdot\vb{E} = \frac{\rho}{\epsilon_0}
}
As you can see in \eq{gaussLaw}, it says "1" instead of "Gauss's Law".
\nameref{gaussLaw}
\end{document}

在此处输入图片描述

相关内容