![如何给方程式命名(而不仅仅是标签)](https://linux22.com/image/466375/%E5%A6%82%E4%BD%95%E7%BB%99%E6%96%B9%E7%A8%8B%E5%BC%8F%E5%91%BD%E5%90%8D%EF%BC%88%E8%80%8C%E4%B8%8D%E4%BB%85%E4%BB%85%E6%98%AF%E6%A0%87%E7%AD%BE%EF%BC%89.png)
我有以下代码:
\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}