This code generates output that shows contents of excerpt1.tex
\documentclass{article}
\usepackage{filecontents}
\begin{document}
Pragraph is starting.
\begin{filecontents}{excerpt1.tex}
Part that must be in two documents.
\end{filecontents}
\input{excerpt1.tex}
Paragraph ends.
\end{document}
This code does not generate output that shows contents of excerpt1.tex
\documentclass{article}
\usepackage{filecontents}
\begin{document}
Pragraph is starting.
\begin{filecontents}{excerpt1.tex}
Part that must be in two documents.
\end{filecontents}\input{excerpt1.tex}
Paragraph ends.
\end{document}
I wonder the reason behind this situation. I have encountered this anomaly in a very important document. Is there a list of such caveats that must be taken into account before any irrecoverable errors happen?
filecontentsis implemented, but some environments are defined to ignore what follows (on the same line)\begin{...}(one example would belstlisting) and/or\end{...}. It's both safer and preferable (from a code-formatting standpoint) to put\input{...}on the next line rather than stick it on the same line as\end{filecontents}. Is there a specific reason why you want to have them on the same line? – jub0bs Mar 23 '14 at 06:56The begin and end tags should each be on a line by itself.(texdoc filecontents), and also a warning is written to the.logfile:LaTeX Warning: Ignoring text '\input{excerpt1.tex}' after \end{filecontents} on input line 8.This behavior is from the originalfilecontentsenvironment as provided by theLaTeXkernel in fileltclass.dtx; packagefilecontentsextensions have not changed that aspect. – Mar 23 '14 at 07:16