4

How to automatically number an equation like this: enter image description here

  • 7
    Apparently, this is subequations environment – user31729 Jul 3 '17 at 16:35
  • @ChristianHupfer... can I add regular equation between subequations? Sorry if the answer is easy... but did not found it yet... – koleygr Jul 3 '17 at 17:47
9

Not fundamentally different from GuM's answer, but some improvements to ease typing partial derivatives with esdiff and cross-referencing with cleveref (to be loaded after hyperref, if you use it):

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{esdiff}
\usepackage{cleveref}
\setcounter{chapter}{2}

\begin{document}

To find $g$, we know that
\begin{subequations}
  \begin{align}
    \diffp{g}{x} & = 3x^2y^2 + x^2, \label{eq:1} \\%
    \diffp{g}{y} & = 2x^3y + y^2.\label{eq:2}
  \end{align}
\end{subequations}
Integrating \Cref{eq:1} with respect to $x$ gives us
\begin{equation}\label{eq:3}
  g = x^3y^2 + \frac{x^3}{3} + h(x)
\end{equation}

\end{document} 

enter image description here

|improve this answer|||||
8

You are worrying without reason: the coding is absolutely straightforward. For example (see also Christian Hupfer’s comment:

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

\usepackage{amsmath}

\numberwithin{equation}{section}



\begin{document}

\setcounter{section}{2} % pretend we are in section two

By theorem~\ldots, \( \omega = dg \) for some~$g$.  To find~$g$, we know that
\begin{subequations}
    \label{eq:both}
    \begin{align}
        \frac{\partial g}{\partial x} &= 3x^{2}y^{2}+x^{2} \mbox{,}
                \label{eq:first} \\
        \frac{\partial g}{\partial y} &= 2x^{3}y+y^{2} \mbox{.}
                \label{eq:second}
    \end{align}
\end{subequations}
Integrating~\eqref{eq:first} with respect to~$x$ gives
\begin{equation}
    g = x^{3}y^{2} + \frac{x^{3}}{3} + h(y) \mbox{,}
\end{equation}
etc.  etc.  Note that you can also reference equation~\eqref{eq:both} as a
whole.

\end{document}

The corresponding output is

Output of the code

|improve this answer|||||
  • Good answer. Years ago I had an agreement with a colleague: I typed her papers in TeX, but was free to change all her “w.r.t.” and “w.l.o.g.” into the proper “with respect to” and “without loss of generality”. ;-) – egreg Jul 3 '17 at 19:34
  • @egreg \newcommand{\wrt}{with respect to~} ;-) – sk8forether Jul 3 '17 at 21:38
  • 1
    @sk8forether: … but do not try something similar with \wlog… ;-) – GuM Jul 3 '17 at 21:54
  • @egreg: Thank you for your remark! Edited. :-) – GuM Jul 3 '17 at 22:04
3

I created a way for something similar a few days before. Here it is.

Just dont forget to usepackage 'amsmath'

You can change it a little bit like this (not-tested):

\makeatletter
\newcommand*\ifcounter[1]{%
  \ifcsname c@#1\endcsname%
    \expandafter\@firstoftwo%
  \else%
    \expandafter\@secondoftwo%
  \fi%
}%
\makeatother


\makeatletter
\newcommand\EqFamTag[2][alph]{%
\ifcounter{#2}{%
\expandafter\addtocounter{#2}{1}%
\xdef\temp{\csname #2 Eq\endcsname\csname #1\endcsname{#2}}%
\global\expandafter\let\csname #2\arabic{#2}\endcsname\temp%
\tag{\temp}%
}{%
\global\expandafter\newcounter{#2}%
\expandafter\addtocounter{#2}{1}%
\xdef\temp{\theequation\csname #1\endcsname{#2}}%
\xdef\eqonfamily{\theequation}%
\global\expandafter\let\csname #2 Eq\endcsname\eqonfamily%
\global\expandafter\let\csname #2\arabic{#2}\endcsname\temp%
\tag{\temp}%
\expandafter\addtocounter{equation}{1}
}%
}%
\makeatother

Then you can write your equation like:

\begin{equation}
 x^2=3\EqFamTag{MyEquatioFamily}
\end{equation}

And the next equation with the same '\EqFamTag{}' will give you the next numbered equation in the same Family... you can add labels if needed or not (check the above post to see how can refer to them without labels)

|improve this answer|||||
2

When you are using plain TeX (it is not clear from your question) then you can use OPmac and you can define a variant to \eqmark macro called \eqmarkx with one parameter: the letter which must be appended.

\input opmac

\def\pdiff#1\over#2{{\partial#1\over\partial#2}}
\def\thednum{(\the\secnum.\the\dnum)}
\def\eqmarkx#1{\ifx a#1\global\advance\dnum by1 \fi
   \def\thednum{(\the\secnum.\the\dnum#1)}%
   \ifinner\else\eqno \fi 
   \wlabel\thednum \rm\thednum
}

\sec Test

To find $g$, we know that
$$ 
  \eqalignno{
     \pdiff g\over x &= 3x^2 y^2 + x^2, & \label[eq-a]\eqmarkx a \cr
     \pdiff g\over y &= 2x^3 y + y^2.   & \label[eq-b]\eqmarkx b \cr
   } 
$$
Integrating Equation \ref[eq-a] with respect to $x$ gives us
$$
  g = x^3 y^2 + {x^3 \over 3} + h(x) \eqmark
$$

\bye
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.