Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

eg.:

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

The verbatim package solution

  \usepackage{verbatim}
  \verbatiminput{a.txt}

work fine with %, but not with UTF-8

any clue what can I do about it?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

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.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}

\makeatletter
\newcommand*{\inputverbatim}[1]{%
    \begingroup
    \let\do\@makeother
    \dospecials
    \obeyspaces% To get normal spaces not a symbol
    \input{#1}%
    \endgroup
}
\makeatother


\begin{document}

...

\inputverbatim{somefile}

...

\end{document}

This works fine for me with pdflatex and gives:

...
ó(%n*\r\ vir\róecu rdOhO {j I iT( J t-y g
...
share|improve this answer
    
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.

\catcode`<symbol>=11

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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