According to filecontents' manual
(version number v1.3, last revised 2011/10/08, p.1) :
(The comment about filecontents being valid only before \documentclass is, in fact, untrue. filecontents is allowed anywhere in the document’s preamble.)
The filecontents package provides a hacked-up version of the filecontents and filecontents* environments that lifts the two restrictions stated above, namely that existing files are never overwritten and that filecontents must be used before the \documentclass declaration (really, the \begin{document}). filecontents is therefore a more convenient way to write external files from within a LaTeX document than is provided by default by the LaTeX 2ε kernel.
However, the following code :
\begin{filecontents}{a}
a
\end{filecontents}
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{b}
b
\end{filecontents}
\begin{document}
\begin{filecontents}{c}
c
\end{filecontents}
This is a test.
\end{document}
\begin{filecontents}{d}
d
\end{filecontents}
will produce only three files and three warnings:
LaTeX Warning: Writing file `./a'.
LaTeX Warning: Writing file `./b'.
LaTeX Warning: Writing file `./c'.
Is everything after the \end{document} discarded? Is there any way to bypass this limitation? Shouldn't the documentation of filecontents be more specific?
\end{document}is discarded, because\@@end(the primitive\end) command is executed. Nothing to do about it, sorry. – egreg May 19 '15 at 23:55\end{document}stops the job and causes the final statistics to be printed and the pdf to be finalised – David Carlisle May 19 '15 at 23:55filecontentsdocumentation should indeed be revised for this technical note. I have to ask, though: why would you want this? – Sean Allred May 20 '15 at 01:36texdocument into one single file, to ease upload, sharing, storage and deposit on e-print services (see http://tex.stackexchange.com/q/184152/34551). I enclose thebibfile into atexfile thanks tofilecontents. The trick is that if thatfilecontentsis at the beginning on the file, arXiv assume the document is abibfile and refuse to compile it. One obvious alternative would have been to concatenate thebibfile at the end, rather than at the beginning. – Clément May 20 '15 at 07:44\end{document}was corresponding to a strict "stop reading the source file". And apart fromfilecontents, I never saw any command pretending that they were working anywhere in the source file. So it might be more like "I found a very special case that interest me". – Clément May 20 '15 at 12:42