0

I have the following code:

\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}

that produces

enter image description here

What I need is: adapt the code in way that \eq gives (produces) "Gauss's Law" instead of "eq (1)". Comment: \tag may not be the solution I'm looking for because I want a number for the equation. I want to be able to refer to that equation by it's number (1) or by it's name (Gauss's Law) I hope I have explained myself. Please tell me if more information is needed. Thanks for reading.

Peluche
  • 613

1 Answers1

5

You can define \@currentlabelname and then use \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}

enter image description here

Ulrike Fischer
  • 327,261