0

In order to be able to reference the equations in my thesis in the format like "Equation (2.2.3)" using the \autoref command I added the following lines in my preamble:

\makeatletter
\let\oldtheequation\theequation
\renewcommand\tagform@[1]{\maketag@@@{\ignorespaces#1\unskip\@@italiccorr}}
\renewcommand\theequation{(\oldtheequation)}
\makeatother

as suggested in Mico's answer in this post: autoref and braces around equation number.

This works perfectly for most of the equations but changes the format of the subequations from the standard format like "(2.3.1a)" to "(2.3.1)a". I want to keep to original format for such subequations. Namely, I want the letter to be inside the parentheses. How can I achieve this?

MWE:

\documentclass[12pt]{report}
\usepackage{amsmath}
\usepackage{hyperref}
\numberwithin{equation}{section}

\makeatletter \let\oldtheequation\theequation \renewcommand\tagform@[1]{\maketag@@@{\ignorespaces#1\unskip@@italiccorr}} \renewcommand\theequation{(\oldtheequation)} \makeatother

\begin{document}

\chapter{Test Chapter}

\section{Test Section}

This is a test equation two including subequations: \begin{subequations} \label{Eq:MainEquation} \begin{equation} \label{Eq:SubEquation1} E = mc^2 \end{equation} \begin{equation} \label{Eq:SubEquation2} c^2 = a^2 + b^2 \end{equation} \end{subequations}

As seen in \autoref{Eq:MainEquation} the labels for \autoref{Eq:SubEquation1} and \autoref{Eq:SubEquation2} are in the wrong format. The letters for the subequations should be inside the parentheses.

\end{document}

Screenshot illustrating the problem:Screenshot

  • 1
    don't show only snippets. Always show a small but complete example. That makes it much easier to test solutions. – Ulrike Fischer Jun 09 '21 at 08:34
  • @UlrikeFischer Thank you for your feedback! I have now added a MWE and a screenshot illustrating the problem to the original question. – thisismetrying Jun 09 '21 at 09:49
  • 1
    The "dirty hack" second answer in the linked question worked for me: \def\equationautorefname#1#2\null{Equation#1(#2\null)}, but I'm not sure the limitations of the hack. – jessexknight Jun 09 '21 at 12:14
  • @jessexknight Yes it did! Doesn't seem to have any unwanted bieffects so far. Should have noticed this earlier... However, thank you! – thisismetrying Jun 09 '21 at 12:29
  • @jessexknight You can provide your comment as an answer and I can award you the bounty! – thisismetrying Jun 10 '21 at 14:38
  • 1
    Sure, but let me try to understand the limitations first. I've asked "Bart" in the other question to clarify. – jessexknight Jun 10 '21 at 18:10

1 Answers1

0

A workaround by redefining the subequations environment from amsmath.

\documentclass[12pt]{report}
\usepackage{amsmath}
\usepackage{hyperref}
\numberwithin{equation}{section}

\makeatletter \let\oldtheequation\theequation \renewcommand\tagform@[1]{\maketag@@@{\ignorespaces#1\unskip@@italiccorr}} \renewcommand\theequation{(\oldtheequation)}

\renewenvironment{subequations}{% \refstepcounter{equation}% % old % \protected@edef\theparentequation{\theequation}% \protected@edef\theparentequation{\oldtheequation}% \setcounter{parentequation}{\value{equation}}% \setcounter{equation}{0}% % old % \def\theequation{\theparentequation\alph{equation}}% \def\theequation{(\theparentequation\alph{equation})}% \ignorespaces }{% \setcounter{equation}{\value{parentequation}}% \ignorespacesafterend } \makeatother

\begin{document}

\chapter{Test Chapter}

\section{Test Section}

\makeatletter

This is a test equation two including subequations: \begin{subequations} \label{Eq:MainEquation} \begin{equation} \label{Eq:SubEquation1} E = mc^2 \end{equation} \begin{equation} \label{Eq:SubEquation2} c^2 = a^2 + b^2 \end{equation} \end{subequations}

As seen in \autoref{Eq:MainEquation} the labels for \autoref{Eq:SubEquation1} and \autoref{Eq:SubEquation2} are in the wrong format. The letters for the subequations should be inside the parentheses.

\end{document}

enter image description here

muzimuzhi Z
  • 26,474