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.

Is there a way to create a horizontal space in LaTeX that is visible to the reader but invisible to the computer when selecting and copying text (using PDFLaTeX)?

An example of the problem: When I read a PDF that has a bank account number in it and I want to manually type/write it into a banking form, it helps a lot to have regular spacing in the number, e.g. "Bank Account no. 123 456 789". However, when I use online banking, the form field does not expect spaces in the number and additionally has a limited length. So when I copy&paste the number from the PDF, all I get in the form field is "123 456 7", because it's limited to 9 characters and it copied the spaces.

So the question is: Can I get LaTeX to show spaces that help readability but that are not selected/copied when copying the text? I still want to read "123 456 789", but when I select and copy that text, I want "123456789" in my clipboard.

I searched for spacing-related topics and tutorials, but only found the usual commands (such as \hspace or \hskip). Using tables or arrays does not help either, there's always a selectable space or even a newline.

Thanks a lot in advance for any help!

share|improve this question
3  
You can use the accsupp package to provide alternative text: tex.stackexchange.com/a/18509/2388 –  Ulrike Fischer Feb 6 at 10:18
    
Thank You very much! –  Fred Feb 6 at 17:57

1 Answer 1

up vote 18 down vote accepted

You can use the accsupp package to specify which text should be copied:

\documentclass{article}
\usepackage{accsupp}

\begin{document}
Account number: \BeginAccSupp{ActualText=123456789}%
123 456 789%
\EndAccSupp{}%
\end{document}

A quick test suggests that this works with pdflatex and lualatex, but not with xelatex.

share|improve this answer
3  
Does it work with PdfLaTeX, XeLaTeX, LuaLaTeX or all of them? I'm just asking since this information might turn out helpful. –  tohecz Feb 6 at 10:21
    
@tohecz: Good point. I've edited my answer. –  Jake Feb 6 at 10:28
    
Also, does this work with all PDF viewers or only some? I guess you can't know that, but which did you test? I know they often behave different with respect to what is copied. –  cfr Feb 6 at 17:15
1  
Thanks a lot! This solution is perfect! I tested it with evince, okular and Adobe Reader on Linux and it works with all of them (though okular swallows a space sometimes, apparently). –  Fred Feb 6 at 17:57

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.