1

I have a long document that I wanted to insert a bit of text into; correcting an erratum. However, I don't want the equation (and other) numbers to change in the rest of the text. So if I insert equations between eq. (4) and eq. (5), I want them to be numbered e.q. 4a, 4b, 4c or 4 bis, 4 ter, 4 quater.

The solution that I came up with is the following:

\newcounter{equationbis} \newcommand{\tagbis}{\stepcounter{equationbis}\tag{\arabic{equation}\alph{equationbis}}} 

Now when I insert an equation, I can do it this way:

\begin{equation} 4 = 5 \tagbis \end{equation} 

However, this only works for equations, and the counter has to be manually reset. (Defining the counter using \newcounter{equationbis}[equation] causes it to be reset after every equation.)

A more practical solution would be that I can write something like:

\startinsertion{about-four-and-five} \section{About four and five} Some rambling about four and five \begin{equation} 4 = 5 \end{equation} \endinsertion{about-four-and-five} 

and automatically have the section numbered 3.7a (if the previous one was numbered 3.7) and the equation (4a) (if the previous one was numbered (4)).

Does there exist a feature like this?

4
  • Please make this into a full minimal example instead of sniplets. For example, what is \startinsertion and \endinsertion? Commented Nov 9, 2017 at 10:29
  • That's precisely the question. I want to be able to delimit the inserted text that wasn't there in the original document and have latex figure out the new section and equation numbers. So these are pseudo-commands that are the feature that I'm looking for. Commented Nov 9, 2017 at 11:08
  • Still it is very hard to understand your question as it is worded now. Commented Nov 9, 2017 at 11:12
  • 1
    Use subequations. Commented Nov 9, 2017 at 12:27

1 Answer 1

3

Here I implemented an environment addendum, in which equations and optionally sections or subsection are numbered the way you want. It has an optional argument, which may be section or subsection and a mandatory one for some text to describe the inserted part.

So if you want to add a section, write

\begin{addendum}[section]{...} \section{...} text and equations here \end{addendum} 

For a subsection write

\begin{addendum}[subsection]{...} \subsection{...} text and equations here \end{addendum} 

And if you only want some text and equations

\begin{addendum}{...} text and equations here \end{addendum} 

Note that addendum environments cannot be nested in one another. This is because LaTeX counters, which are used for saving the originals, are always global.

In the example, the Addendum line, the rules and the blue color are just there to better see the added parts. You can change that to your needs (see comments in code).

enter image description here

The code:

\documentclass{book} \usepackage{xcolor} \makeatletter % counters to store the original ones \newcounter{orig@section} \newcounter{orig@subsection} \newcounter{orig@equation} \newenvironment{addendum}[2][]{% \begingroup % save current counters \setcounter{orig@section}{\value{section}}% \setcounter{orig@subsection}{\value{subsection}}% \setcounter{orig@equation}{\value{equation}}% % \def\@tempa{#1}\def\@tempb{section}% \ifx\@tempa\@tempb % reset counter \setcounter{section}{0}% % macro to print original counter \def\theorig@section{\thechapter.\arabic{orig@section}}% % redefine \the... to print the original counter first \def\thesection{\theorig@section\alph{section}}% \else \def\@tempb{subsection}% \ifx\@tempa\@tempb \setcounter{subsection}{0}% \def\theorig@subsection{\thesection.\arabic{orig@subsection}}% \def\thesubsection{\theorig@subsection\alph{subsection}}% \fi \fi % \setcounter{equation}{0}% \def\theorig@equation{\thechapter.\arabic{orig@equation}}% \def\theequation{\theorig@equation\alph{equation}}% % optional \color{blue}% just for testing \noindent\textbf{Addendum: #2}\par \medskip\hrule\medskip\par\noindent \ignorespaces% needed to get rid of the space introduced by \begin{addendum}{...} }{% % optional \par\medskip\hrule\medskip\par % restore counters \setcounter{section}{\value{orig@section}}% \setcounter{subsection}{\value{orig@subsection}}% \setcounter{equation}{\value{orig@equation}}% \endgroup } \makeatother \begin{document} \chapter{Some Chapter} \section{About some Numbers} Some rambling about numbers. \begin{equation} 4 \ne 5 \end{equation} \begin{addendum}[section]{as sections} \section{Section about four and five} Some rambling about four and five \begin{equation} 4 = 5 \end{equation} \subsection{Subsection about four and five} Some rambling about four and five \begin{equation} 4 = 5 \end{equation} \subsection{Another subsection about four and five} Some rambling about four and five \begin{equation} 4 = 5 \end{equation} \section{Another section about four and five} Some rambling about four and five \begin{equation} 4 = 5 \end{equation} \end{addendum} \section{About something else} Some rambling about other things. \begin{equation} 8 \ne 9 \end{equation} \subsection{More on something else} More rambling about other things. \begin{equation} 12 \ne 15 \end{equation} \begin{addendum}[subsection]{as subsections} \subsection{Subsection about twelve and fivteen} More rambling about other things. \begin{equation} 12 = 15 \end{equation} \subsection{Another subsection about twelve and fivteen} More rambling about other things. \begin{equation} 12 = 15 \end{equation} \end{addendum} \subsection{Even more on something else} Even more rambling about other things. \begin{equation} 20 \ne 21 \end{equation} \begin{addendum}{just new equations} Rambling about these numbers. \begin{equation} 20 = 21 \end{equation} \begin{equation} 20 = 21 \end{equation} \end{addendum} Another equation for other things. \begin{equation} 30 \ne 31 \end{equation} \end{document} 

The code works by saving the original counters, resetting them and changing the macros to print them (\the...). The counters are restored at the end of the environment. For sectioning commands, care must be taken to only redefine the counter for the highest sectioning level to be inserted. For this the optional argument is used.

Additional counters can be implemented in a similar way. But be careful to not change a counter resetted by another one to be changed. For example, if support for chapters is added, take care not to change the equation counter for an inserted chapter.

The addendum environment works for the book class. For other classes you may have to adapt it.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.