Generaltoc of equations

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
moniquisma
Posts: 2
Joined: Wed Apr 16, 2008 9:59 am

toc of equations

Post by moniquisma »

Dear LaTex community:

I would like to create a toc with the equations I am using in the text in order to copy all of them into few pages and see if I am consistent with the notation throug all the document.

For example, if my document is like this

...text...
\begin{equation}
E=m \cdot c^2
\end{equation}
...text...
...text...
...text...
...text...
...pages...
...pages...
\begin{equation}
F=m \cdot a^2
\end{equation}
...text...

Then in my dvi, I would like to have an extra page at the beginning of my document just with

\begin{equation}
E=m \cdot c^2
\end{equation}

\begin{equation}
F=m \cdot a^2
\end{equation}

in order to compare them.

Thanks in advance.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

T3.
Posts: 208
Joined: Fri Mar 14, 2008 12:58 pm

toc of equations

Post by T3. »

This is quite unusual requirement, so I'm not sure if there is a package that will do exactly what you want.

Here are a few pointers that might give you some ideas:
  • Write a simple parser (in whatever programming language you know) that will extract all display math into a separate file and then compile that file with latex.
  • Look at preview-latex package. It should allow you to output only your math as one equation per page. It should be then straightforward to auto-generate latex file that will further condense this output, e.g.

    Code: Select all

    \includegraphics[page=1]{previewfile.pdf}
    \includegraphics[page=2]{previewfile.pdf}
    ...
    
Cheers,

Tomek
balf
Posts: 158
Joined: Sat Jan 12, 2008 1:11 am

Re: toc of equations

Post by balf »

The tocloft package might help: it allows to define new lists of...., with a system of matks, which could be the content of the equation itself The main difficulty I see would be the case of equations embedded in other equations.

B.A.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

toc of equations

Post by Stefan Kottwitz »

Hi moniquisma,

welcome to the LaTeX Community board!
Concerning tocloft and list of equations we had a discussion here. gmedina gave an example there. Its a list without the math content though.

Stefan
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

toc of equations

Post by Juanjo »

I propose a solution exemplified in the following code:

Code: Select all

\documentclass{article}

\usepackage{amsmath}
\usepackage{lipsum}

% --------------------------------------------
% --------------------------------------------
% Load fancyvrb
\usepackage{fancyvrb}

% Name of a scratch file
\newcommand{\TempFile}{extractedcode.tmp}

% Name of the tex file with the extracted code
\newcommand{\LaTeXFile}{extractedcodee.tex}

% Command \AppendTempFile.
% Appends the contents of the temp file to those
% of the tex file. Choose the right definition
% depending on your system
% For Unix/Linux/Mac OS X
%\newcommand{\AppendTempFile}{%
%   \immediate\write18{cat \TempFile >> \LaTeXFile}}
% For Windows
\newcommand{\AppendTempFile}{%
   \immediate\write18{type \TempFile >> \LaTeXFile}}

% New environment ExtractCode.
% It extracts all the code that lies inside.
% The definition is a bit tricky. It is not
% done through \newenvironment
\newcommand{\ExtractCode}%
  {\VerbatimEnvironment
   \begin{VerbatimOut}{\TempFile}}
\def\endExtractCode{%
   \end{VerbatimOut}
   \input{\TempFile}
   \AppendTempFile}
% --------------------------------------------
% --------------------------------------------

\begin{document}

% --------------------------------------
% Put the following lines whenever you want
% to start extracting code. Write inside
% VerbatimOut a suitable preamble for the tex
% file which will contain that code
\begin{VerbatimOut}{\LaTeXFile}
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\end{VerbatimOut}
% --------------------------------------

% --------------------------------------
\begin{ExtractCode}
\title{A test}
\author{by Myself}
\date{\today}
\maketitle

\section{First section}
\end{ExtractCode}
% --------------------------------------

\lipsum[1-2]

% --------------------------------------
\begin{ExtractCode}
Here we have some equations
\begin{align}
    x + y + u^2 - v &= -1, \\
    2x^2 - 3y + 4z + u^3 &= 9,  \\
    2y^3 - z^2 + u - v &= -4.
\end{align}
\end{ExtractCode}
% --------------------------------------

\lipsum[3]

% --------------------------------------
\begin{ExtractCode}

\section{Second section}
\end{ExtractCode}
% --------------------------------------

\lipsum[4]

% --------------------------------------
\begin{ExtractCode}
Let $f(x,y)=2x-y+xy$. Then we have
\begin{equation}
    \nabla f(x,y)=\mathbf{0}\Longrightarrow
    \left.
    \begin{alignedat}{2}
      f_x(x,y)&={} &  2 &+y=0 \\
      f_y(x,y)&={} & -1 &+x=0
    \end{alignedat}
    \right\}\Longrightarrow (x,y)=(1,-2)
\end{equation}
\end{ExtractCode}
% --------------------------------------

\lipsum[5]

% --------------------------------------
% Put the following lines whenever you want
% to stop extracting code. 
\begin{VerbatimOut}{\TempFile}
\end{document}
\end{VerbatimOut}
\AppendTempFile
% --------------------------------------

Here we have the last equation, not included in the separate document:
\begin{equation}
  E=m c^2
\end{equation}

\end{document}
I define an environment called ExtractCode. Everything inside it is processed as usual by LaTeX. But, in addition, that code is written to an external file, called, by default, extractedcode.tex. You can rename this file by redefining the \LaTeXFile macro. The ExtractCode environment is based on the VerbatimOut environment defined in fancyvrb, so this package must be loaded.
Every piece of extracted code is temporarily saved in a file whose name is given by the \TempFile macro and then appended to \LaTeXFile. To this end, I use a command from the operating system: type in Windows or cat in Unix-like systems. To be able to call this commands, it is necessary to enable the shell-escape feature in your TeX distribution.

In the above code, I propose to add to \LaTeXFile two pieces of code, at the beginning and at the end, so this file can be compiled separately. After running the above code, I get the file extractedcode.tex which has the following lines:

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\title{A test}
\author{by Myself}
\date{\today}
\maketitle

\section{First section}
Here we have some equations
\begin{align}
    x + y + u^2 - v &= -1, \\
    2x^2 - 3y + 4z + u^3 &= 9,  \\
    2y^3 - z^2 + u - v &= -4.
\end{align}

\section{Second section}
Let $f(x,y)=2x-y+xy$. Then we have
\begin{equation}
    \nabla f(x,y)=\mathbf{0}\Longrightarrow
    \left.
    \begin{alignedat}{2}
      f_x(x,y)&={} &  2 &+y=0 \\
      f_y(x,y)&={} & -1 &+x=0
    \end{alignedat}
    \right\}\Longrightarrow (x,y)=(1,-2)
\end{equation}
\end{document}
I attach the pdf files corresponding to the main code and to extractedcode.tex once compiled. I've tested this solution in Mac OS X and Windows XP with success in both cases.
I hope it may help. Of course, you can extract not only equations but any piece of code.
Attachments
testextract.pdf
(45.68 KiB) Downloaded 264 times
extractedcode.pdf
(37.15 KiB) Downloaded 268 times
moniquisma
Posts: 2
Joined: Wed Apr 16, 2008 9:59 am

Re: toc of equations

Post by moniquisma »

Dear Juanjo,

thank you very much for your idea. After one problem with my Latex environment I made it
successfully work. In this post I would like to explain the solution to the problem I found in
order to help other people.

The problem is related on how to enable the shell-escape option in the Latex environment.
The correct way of doing it is to type
Latex --shell-escape -interaction=nonstopmode '%source'
My problem was that I first tried to type the --enable-escape after -interaction flag and it did
not work!!!

Thank you very much for everything,

Monica.
Post Reply