0

I'm writing a long document in which the key pieces of information are in environments (itemize, for the things to do, equation, lemma, theorems for the other) separated by text and proofs.

To ease the communication with the co-authors I'd like to produce a shorter version of my document containing only the structure (section, subsection,...) and some environments (all but the proof really).

For example:

\documentclass{amsart}
\newtheorem{theorem}{Theorem}

\begin{document}
\section{Intro}
\begin{itemize}
\item todo 1
\item todo 2
\end{itemize}
bla bla bla
\section{First result}
\begin{theorem}
(hopefully) nice thing
\end{theorem}
\begin{proof}
bla bla bla
\begin{equation}
E=mc^2
\end{equation}
\end{proof}
\end{document}

should be compiled as if it where

\documentclass{amsart}
\newtheorem{theorem}{Theorem}

\begin{document}
\section{Intro}
\begin{itemize}
\item todo 1
\item todo 2
\end{itemize}
\section{First result}
\begin{theorem}
(hopefully) nice thing
\end{theorem}
\end{document}

This is doable by hand, but I aim for a more efficient solution. Could you please find one?

2 Answers2

1

I wrote the following python code which seems to work just fine.

"""
Created on Tue Feb 25 12:38:06 2020

@author: benoit
inspired by CommentIO.py of Martin Larsson, to.martin.larsson@gmail.com
"""

import sys
import os
import os.path

def printHelpMessage(error):
    print("\nError: " + error )
    sys.exit()


# Check if the input file exists.
inputFilename="Draft.tex";
outputFilename = "miniSkeleton.tex";
envinclude=["theorem", "lemma","itemize","subequations","equation","prop","align", "remark"]
envexclude=["proof"] 
includesections= True



if not (os.path.isfile(inputFilename) and os.access(inputFilename, os.R_OK)):
    printHelpMessage("Input file is either missing or is not readable.")


def issection(l):
    return ("\\section{" in l) or ("\\subsection{" in l) or ("\\subsubsection{" in l)

def modifydepth(envlist,line):
    for i,j in enumerate(envlist):
        if ("\\begin{"+j) in line:
            return 1
        else:
            if("\\end{"+j) in line:
                return -1
    return 0

started=False
ended=False
includedepth=0
excludedepth=0
outputcontent = []
# Read the file into a list.
with open(inputFilename) as f:
    content = f.readlines()

# Go through each line in the list.
for i, checkLine in enumerate(content):
    if "\\begin{document}" in checkLine:
        started=True;
        outputcontent.append(checkLine);
    if started and not(ended):
        excludedepth=excludedepth+modifydepth(envexclude,checkLine)
        if (excludedepth==0):
            mincludedepth=modifydepth(envinclude,checkLine)
            if (includedepth>0) or (mincludedepth==1):
                outputcontent.append(checkLine);
            else:
                if issection(checkLine):
                    outputcontent.append(checkLine);
            includedepth=includedepth+mincludedepth
    else:
        outputcontent.append(checkLine);
    if "\\end{document}" in checkLine:
        ended=True;
        outputcontent.append(checkLine);
# Write the list to a new file.
output = open(outputFilename, "w")
output.writelines(outputcontent)
output.close()
0

As you want to hide proofs but also plain text and maybe other parts, I would simply mark this parts as conditionals to a \showtrue in the preamble:

\documentclass{amsart}
\newif\ifshow
% \showtrue %%%% uncomment to show all 
\newtheorem{theorem}{Theorem}
\begin{document}
\section{Intro}
\begin{itemize}
\item todo 1
\item todo 2
\end{itemize}
\ifshow
bla bla bla
\fi
\section{First result}
\begin{theorem}
(hopefully) nice thing
\end{theorem}
\ifshow
\begin{proof}
bla bla bla
\begin{equation}
E=mc^2
\end{equation}
\end{proof}
\fi
\end{document}
Fran
  • 80,769