[Tex/LaTex] ny way to include the literal text of another file

includeinput

From what I have read, input processes text and includes commands found, and include can't be used in the preamble for some reason (correct me if I'm wrong). I just want a command that replaces itself with the literal text of the referenced file, and does absolutely nothing else. Is there a way to do that?

Best Answer

You can't use \include in the preamble since it always issues a \clearpage -- which is 'typesetting' effectively.

\input{} is possible for literal text content in the document body without formatting, but the usual empty lines etc. are regarded as start of new paragraphs.

Another way is \lstinputlisting{filename} from listings package.

\documentclass{article}

\usepackage{listings}


\begin{document}
\InputIfFileExists{literalinput.txt}{}{}%

Or

\lstinputlisting{literalinput.txt} % Verbatim loading of text.
\end{document}

The file literalinput.txt just contains

This is meant

for

the literal input of text.

enter image description here