Fonts & Character SetsUnderscore (_) symbol as "space" in the generated PDF

Information and discussion about fonts and character sets (e.g. how to use language specific characters)
Post Reply
kulakov
Posts: 2
Joined: Sat May 22, 2010 6:49 pm

Underscore (_) symbol as "space" in the generated PDF

Post by kulakov »

Hello LaTex experts,

I am new at LaTeX community and at LaTeX in general too, so please do not be hard when judging my post. I hope, the part of the forum I am pasting this question to is proper.

I am currently struggling with underscores in my generated pdf file. I have a lot of underscores in my text and I use the backslash "\" to avoid errors, which is the genral recomendation in all tutorial on how to work with underscores and other special characters. The underscores appear correctly in the generated PDF, however, the problem is that when I want to copy/paste the text with the underscores, I get spaces instead of underscores. For example, if I have the following text:
This_is_a_text_with_underscores
it appears OK in the PDF, but when I copy and paste it to a different file, I get the text as "This is a text with underscores", but not as "This_is_a_text_with_underscores" which is what I need.

I also noticed that if I search the PDF for the text "This_is_", I find no results, however if I search for "This is ", I find my text with underscores. It seems to me that the PDF file that is generated just displays the underscores, however, has spaces in the core of the document.

Can someone please tell me if this behaviour is expected? Or is this specific to the PDF generator? I am using TeXnicCenter tool.

I tried to use \textunderscore instead of \_ or even tried the behaviour when using package "underscore.sty", but I still have the same problem! Does anyone have an idea? I've already search the whole internet and the LaTeX community, but did not find anything with this problem.

Any help will be highly appreciated!

Thank you in advance.
Regards,
Maxim
Last edited by kulakov on Sat May 22, 2010 8:40 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Underscore (_) symbol as "space" in the generated PDF

Post by localghost »

The code below works for me as expected. Copying and pasting parts of text yields the desired result as well as searching the PDF file. Perhaps a matter of the viewer.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}

\begin{document}
  This\_is\_text\_with\_underscores.
\end{document}

Best regards and welcome to the board
Thorsten
kulakov
Posts: 2
Joined: Sat May 22, 2010 6:49 pm

Re: Underscore (_) symbol as "space" in the generated PDF

Post by kulakov »

Thorsten! You are the man! Thanks for your quick help! :)

This line made a difference:
\usepackage[T1]{fontenc}

If I change T1 to OT1 the old problem occurs, even with your simple example. I guess there is something wrong with the encoding OT1.

After I entered this line in my document it now works as expected! I got some issue with the text getting thinner and duller, but I was able to quickly solve it with the package "lmodern" as suggested in this post: http://mrunix.de/forums/showthread.php?t=57130.

Danke viel Mals!
Schöne Grüße aus Wien!
Maxim
Post Reply