11

I'm writing up my textbook notes in LateX. As I am writing paragraphs, I am inserting equations while I'm writing.

I want to somehow display all of my numbered equations at the end of my document in the same order that they were numbered. Is there a way to easily do this in LaTex with an unknown command that I might not know???

egreg
  • 1,121,712
LaTexGal
  • 111

1 Answers1

8

This solution borrows very heavily from David Carlisle's solution to Write content of box to a file

The idea is to renew the equation environment so that it not only outputs to the page, but its contents are also written to a vbox that is outputted at the end of the document.

You can extend the idea easily to other environments (such as align, for example).

\documentclass{article}
\usepackage{amsmath}
\usepackage{lipsum}

% to store the contents of a SINGLE equation
\newsavebox{\mybox}

% to store the contents of ALL of the equations
\newbox\savedqns
\setbox\savedqns\vbox{}

% we're going to renew the equation environment
% using the original definition as a base
\let\oldeqn\equation
\let\oldendeqn\endequation

% renew the equation environment
\renewenvironment{equation}{%
  \begin{lrbox}{\mybox}%
  \begin{minipage}{\linewidth}%
    \oldeqn%\begin{equation*}
}
{%
  \oldendeqn%\end{equation*}
  \end{minipage}%
  \end{lrbox}%
  % output the box to the page
  \vspace{\abovedisplayskip}%
  \noindent\usebox{\mybox}%
  \vspace{\belowdisplayskip}%
  % save the equations for later
  \global\setbox\savedqns\vbox{%
  \unvbox\savedqns
  \bigskip
  \filbreak
  \noindent\usebox{\mybox}}
  }


\begin{document}

\lipsum[1]
\begin{equation}
  y=mx+b
\end{equation}
\lipsum[2]
\begin{equation}
  y=ax^2+bx+c
\end{equation}
\lipsum[1]
\begin{equation*}
  y=mx+b
\end{equation*}
\lipsum[1]

\section*{Copied equations}
\unvbox\savedqns

\end{document}
cmhughes
  • 100,947