3

I have a Knitr document where I sometimes have to escape underscores. The underscores are actually part of the original data, get loaded in R, and at some point knitted into the LaTeX code, so detokenize seemed like the best way to escape them.

But after escaping, what I get does not look like underscores. The funny thing is that, if I copy the characters out of the PDF and paste them somewhere else, I get underscores.

\documentclass{report}
\usepackage[utf8x]{inputenc}

\begin{document}
    Lorem ipsum 

    This should be a row of underscores: \detokenize{______}

\end{document}

enter image description here

What is happening here, and how do I get my underscores?

  • You can get away without loading T1 fonts if you do \texttt{\detokenize{_____}} – egreg Jan 3 '17 at 15:53
6

OT1 encoded fonts do not have underscore, if you use T1 then things work as expected:

If you copy the OT1 character then you will get character 95 which in any ascii or unicode based encoding will be a _ so if you paste it into an application using such a font encoding the character will appear as an underscore.

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\begin{document}
    Lorem ipsum 

    This should be a row of underscores: \detokenize{______}

\end{document}
  • Oh! I thought of simply trying another font before posting, but it must have been another OT1 font, never thought as far as font encoding. Thanks, I'll give you the checkmark as soon as the system lets me. – rumtscho Jan 3 '17 at 14:44

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.