# Append text to equation tags

I want to append the current section to equation tags, even if I use the \tag command to override it. I would guess this entails creating some custom command like \appendtag.

I know I can use \numberwithin{equation}{section} to add the section number to the tags. I actually use \renewcommand{\theequation}{\arabic{section}--\arabic{equation}}, because I prefer a dash over the dot. However, if I use the \tag command, I override the whole tag (as in equation (Ex) below). What I wish to do is just append some text, so that the equation tag reads (1-Ex).

\documentclass{article}
\usepackage{amsmath}
\renewcommand{\theequation}{\arabic{section}--\arabic{equation}}

\begin{document}

\section{First}

We have an untagged equation like
$$y = X\beta + \varepsilon,$$
with a second untagged equation like
$$E(\varepsilon_i | X) = 0. \tag{Ex}$$

\end{document}


• In (1-Ex), the number would be the section number? And is it always the same text that would be appended? Apr 15 '19 at 23:12

\documentclass{article}
\usepackage{amsmath}
\renewcommand{\theequation}{\arabic{equation}}
\makeatletter
\def\tagform@#1{\maketag@@@{(\arabic{section}--\ignorespaces#1\unskip\@@italiccorr)}}
\makeatother
\begin{document}

\section{First}

We have an untagged equation like
$$y = X\beta + \varepsilon,$$
with a second untagged equation like
$$E(\varepsilon_i | X) = 0. \tag{Ex}$$

\end{document}


You can use \tag to achieve any format, and \label and \ref will reproduce them. The only difference is that \tag turns off the automatic \stepcounter{equation}.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\section{First}

We have an untagged equation like
$$\stepcounter{equation} y = X\beta + \varepsilon, \tag{\thesection-\theequation}$$
with a second untagged equation like
$$\stepcounter{equation} E(\varepsilon_i | X) = 0. \tag{\theequation-Ex}$$

\end{document}