1

I have a tex file which compiles fine and generates PDF without any problem. I need to include text (contents of a text file) from another .txt file at the end of tex file so that generated PDF would have this text in it.

In other words, How can I call another file (text file) to include its contents in a tex file before generating PDF?

Please advise, Thanks a lot!!

  • 1
    You can use \input{}. Look for more on it. – Sigur Nov 13 '13 at 22:20
  • If you want to print file.txt verbatim, then put \usepackage{verbatim} in the preamble and \verbatiminput{file.txt} where you want the contents of file.txt to appear. – Dan Nov 14 '13 at 19:58
4

It is not obvious if you want to merge your text file or reproduce it as it is. Hence there are both solutions:

\documentclass{article}

\begin{document}

A beginning.

\input{aaa.txt} % your text file


\textbf{But if you want to reproduce your text as it is:}
{\obeylines\obeyspaces
\texttt{
\input{aaa.txt}
}}

\end{document}

enter image description here

  • Thank you the reply. But I have "#" symbols in my text files which causing an error while compiling and the error is "! You can't use `macro parameter character #' in horizontal mode." How can I solve this problem? Please advise!! – user41006 Nov 13 '13 at 23:23
  • @user41006 Maybe my answer to this question tex.stackexchange.com/questions/142006/… would be useful? – Przemysław Scherwentke Nov 14 '13 at 0:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.