I got some text file (logs) that I want to import

I saw this post: How do I import a text file so that it becomes the body text of my LaTeX document? which work, but all the special chars (UTF-8) are dropped and the reserved chars (eg:\, %) are interpreted.


ó(%n*\r\ vir\róecu rdOhO {j I iT( J t-y g

The verbatim package solution


work fine with %, but not with UTF-8

any clue what can I do about it?


You need to use a LaTeX flavor which supports unicode. Use either lualatex or xelatex instead of (pdf)latex or try to load \usepackage[utf8]{inputenc}.

The special characters like % can be temporary disabled using \catcode`\%=12 or easier \@makeother\%. All special characters can be changed at once using \dospecial if \do is changed to use \@makeother.

You need a modern font including the correct encoding so that special characters are correctly shown. Otherwise you will get a " instead of \, etc.


    \obeyspaces% To get normal spaces not a symbol






This works fine for me with pdflatex and gives:

ó(%n*\r\ vir\róecu rdOhO {j I iT( J t-y g
  • the inputenc was what I needed. \usepackage{verbatim} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage[applemac]{inputenc} \verbatiminput{a.txt}. and my file was in a mac format. not utf-8... using pdflatex. Thanks Martin !
    – Loda
    Dec 20 '11 at 13:59

If you happen to know which characters they are and want to be a bit more lazy, you can change their category code to normal text using \catcode.


With 11 the code for a normal symbol, mind that symbol needs to be replaced by the LaTeX format of the symbol (# would be \# or é would be \'e). Here is a list for the number codes.

You have to be careful though, changing important characters (like \) can make your whole program fail. You can revert it by typing exactly the same but with the appropriate number code found in the link.

I've only used this with hash (#), which had no problems so far.

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.