[texhax] filecontents in own environment

Arno Trautmann Arno.Trautmann at gmx.de
Wed May 25 13:06:52 CEST 2011


Hi,

Susan Dittmar wrote:
> Dear Arno,
> 
> I do not understand what exactly you want to archieve. Perhaps you could
> elaborate a bit upon that?

I want to include a LaTeX example that is generated on-the-fly, called
from another document. I.e. the source code is located in the main file,
written into the external file via filecontents, then compiled with a
\write18 and the resulting pdf is included.

> What you did, as far as I understand your code snippet, cannot work.
> You cannot mix the filecontents environment and an \include command.

Sorry, that should have been an \includegraphics …

> That's
> impossible, because the filecontents environment *must* be in the preamble,

Nop, must not – the filecontents package allows to use it anywhere, and
that works fine so far.

The code attached below does what I want, but I'd like to have a
shorthand for it, so I can collapse the code between the —¹— and —²— into

\begin{mycontent}{tmptest.tex}
hello world
\end{mycontent}

Sorry for being not so clear …

cheers
Arno


\documentclass{scrartcl}

\usepackage{
  filecontents,
  graphics
}

\begin{document}
main text
%%—²—
\begin{filecontents}{tmptest.tex}
\documentclass{minimal}
\begin{document}
hello world
\end{document}
\end{filecontents}

\immediate\write18{lualatex tmptest.tex}
\begin{figure}
\center
\includegraphics{tmptest.pdf}
\end{figure}
%%—²—
\end{document}



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
URL: <http://tug.org/pipermail/texhax/attachments/20110525/8f7afe09/attachment.bin>


More information about the texhax mailing list