1

I don't know how to properly ask this question nor if the term encoding is appropriate for this issue, so I'll start with an example. Say I define a new command \R for the set of real numbers as follows

\newcommand\R{{\rm I\!R}}

so that the output will be something like Custom Reals symbol.

Basically I merge capital letters "I" and "R" to produce something in between a plain-text and a blackboard-bold R. When I select and copy the symbol on the pdf output, the copied text is reasonably the string "IR" rather than just "R".

My question is, is there any way to define what plain text should be copied (and matched using pdf reader find tool) in the pdf text selection? In the example above I would like the output of \R to be copied as "R" only, for instance.

More generally, is it possible to define the wanted behavior on arbitrary (more complex) commands? For instance, something like

\EncodeAs{plain-text-string}{TeX-command}

so that in the example above I could define

\newcommand\R{\EncodeAs{R}{{\rm I\!R}}}
AndreasT
  • 815
  • 1
    The accsupp package is what you want. Here is one of my answers using it to produce different output in PDF visual versus PDF copy/paste: http://tex.stackexchange.com/questions/198516/is-there-such-thing-as-visual-only-whitespace/198519#198519. – Steven B. Segletes Nov 11 '16 at 15:22
  • 1
    \documentclass{article} \usepackage{accsupp} \newcommand\R{{\rm I\!R}} \begin{document} \BeginAccSupp{method=escape,ActualText=R}% $\R$% \EndAccSupp{}% \end{document} – Steven B. Segletes Nov 11 '16 at 15:26
  • @StevenB.Segletes That is exactly what I was looking for, thank you! Why don't you post your comment as an answer so that I can accept that? – AndreasT Nov 11 '16 at 16:10

1 Answers1

1

The accsupp package allows the pdf display text to be set differently from the corresponding PDF copy/paste text. Here is an example.

\documentclass{article}
\usepackage{accsupp}
\newcommand\R{{\rm I\!R}}
\begin{document}
\BeginAccSupp{method=escape,ActualText=R}%
    $\R$%
  \EndAccSupp{}%
\end{document}

The above code will place this

enter image description here

in the document, while the copy/paste of the PDF will produce an "R". One can set these in macros, depending on the use case.