2

I would like to use \usepackage{filecontents} to write another version of my document to a file later with \write18 and compile it.

My question is: How do I create a custom \begin{document} to handle the writing of the file in my template1.tex and including it later?

I would like to have something like this:

\documentclass{beamer}
\begin{customdocument}
//frames
\end{customdocument}

Intention: My custom document environment writes the content of customdocument into a second tex file and compile it with different options.

Output: Two files (one with notes and one without) but ONE working file.

I tried creating a new environment but then got the error of missing \begin{document}


Minimal example:

\documentclass{beamer}
    \usepackage{filecontents}
    \usepackage{docmute}
\begin{filecontents*}{template1.tex}
\documentclass{beamer}
\begin{document}
\begin{frame}{A frame}
    Foo
\end{frame}
\end{document}
\end{filecontents*}
\immediate\write18{pdflatex -jobname=\jobname _notes\space template1}
\begin{document}
\input{template1}
\end{document}
Orri
  • 121
  • 5
  • 1
    Welcome to TeX.SX! Thank you for posting a working example! At the same time, much of your code does not seem to be relevant to the question you're asking here. Please limit the example to only the code required for your issue to appear. You can have a look at this guide for how to prune your code for this purpose. – ebosi Apr 08 '16 at 10:29
  • May be this can help: http://tex.stackexchange.com/questions/101479/how-to-build-two-different-tex-files-from-same-tex-file – Ignasi Apr 08 '16 at 10:36
  • I don't understand what you want. From your example I suppose you have some complete document which you want later on include in another one. If it's like this, you can include first document with pdfpages. If not, please explain it better. – Ignasi Apr 08 '16 at 10:46

1 Answers1

3

It is not clear to me, what is the purpose of the file template1.tex. But the syntax can be fixed. Package filecontents can be loaded before \documentclass via \RequirePackage:

\RequirePackage{filecontents}
\begin{filecontents*}{template1.tex}
\documentclass{beamer}
\begin{document}
\begin{frame}{A frame}
    Foo
\end{frame}
\end{document}
\end{filecontents*}
\immediate\write18{pdflatex -jobname=\jobname _notes\space template1}
\input{template1}

A redefinition of environment document is then not needed.

Heiko Oberdiek
  • 271,626