5

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}
4

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

  • 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

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.