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 want to read a underscore character from a file with \readline and print it as an underscore in the resulting pdf. But the result is a high point. I've read quite a lot about category/character codes but it is still quite confusing.

I've found this related question: \chardef and underscore, but I would prefer not changing the font.

Here the minimal working example:

\documentclass[12pt]{article}
\usepackage{xstring}
\usepackage{filecontents}
\begin{filecontents*}{data.txt}
_
\end{filecontents*}

\begin{document}
\newread\myread
\openin\myread=data.txt
\readline\myread to\line
\StrLeft{\line}{1}[\firstletter]

The content of firstletter should be printed here: \firstletter

But it should be displayed as: \_
\end{document}
share|improve this question

1 Answer 1

up vote 4 down vote accepted

You can use the Cork (T1) encoding:

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{xstring}
\usepackage{filecontents}
\begin{filecontents*}{data.txt}
_
\end{filecontents*}

\begin{document}
\newread\myread
\openin\myread=data.txt
\readline\myread to\line
\StrLeft{\line}{1}[\firstletter]

The content of firstletter should be printed here: \firstletter

It is displayed as: \_
\end{document}

enter image description here

share|improve this answer
1  
Thanks! (and shame on me, I know this command, but I haven't thought of that) :) –  Thomas Rebele Jul 31 '12 at 9:25

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.