59

I’m using XeLaTeX within MiKTeX and have the following problem.

Let there be some acronym, e.g. USA. I would like to write it in real small caps using \textsc{usa} but these are, of course, lower-case when copied from the PDF and pasting it, e.g. into a plain text file.

Is it possible to provide an alternative text that is the ‘actual’ text that is represented by these small caps and that is used when copying and pasting?

I mean something like when I have:

In the \textsc{usa} of 1980s there was ...

I would like it to be copied when hitting Ctrl+C as In the USA of 1980s there was ..., not as In the usa of 1980s there was ...


After an answer has been given:

Now there is only a problem that I can’t use this in the definition of acronym with the glossaries package. Minimum working example:

\documentclass[11pt]{article}

\usepackage{xunicode}
\usepackage{xltxtra}
\usepackage{accsupp}
\usepackage{glossaries}
\makeglossaries

\def \acUSA {\BeginAccSupp{method=plain,ActualText=USA}\textsc{usa}\EndAccSupp{}}
\newacronym{USA}{\acUSA}{United States of America}

\begin{document}
In the \gls{USA} of 1980s\ldots
\end{document}

It says this and doesn’t get through:

! Incomplete \iffalse; all text was ignored after line 10.
<inserted text> 
                \fi 

Thanks for further help.

josefec
  • 1,772

1 Answers1

50

See package accsupp:

\documentclass{article}
\usepackage{accsupp}
\begin{document}
In the
\textsc{%
 \BeginAccSupp{method=escape,ActualText=USA}%
  usa%
 \EndAccSupp{}}%

of 1980s there was...
\end{document}
alfC
  • 14,350
Ulrike Fischer
  • 327,261
  • Great. That’s the answer. Now I have only a problem that it gives me an error when I use it inside a definition of an acronym using the glossaries package. – josefec May 18 '11 at 09:55
  • Make an small, complete example for tests. – Ulrike Fischer May 18 '11 at 10:40
  • OK, done. I’ve put it into the original question. – josefec May 18 '11 at 10:55
  • 8
    Try \DeclareRobustCommand\acUSA .... And always load xunicode after xltxtra - if you load it at all which is unneeded as xltxtra will load it anyway. Actually nowadays also xltxtra is no longer really needed. fontspec should be enough. – Ulrike Fischer May 18 '11 at 11:03
  • 1
    Great, great, great, the greatest of all times. I sincerely thank you for your help. Now everything works like in a dream. :) – josefec May 18 '11 at 11:08
  • Just figured out that pdftotext supports this accsupp feature and prints the ActualText. Nice! – Martin Scharrer May 18 '11 at 21:25
  • I’ve come to yet another thing. Would it be possible to declare some sort of command that would take its parameter character by character and put it between the \BeginAccSupp and \EndAccSupp character by character? It would be better because in my case if I do what is recommended in the answer, the whole text ‘USA’ is then one entity and not individual characters and also for some longer ones like ‘OECD’ the text when selected is shorter than how long it is visible. E.g. OECD, that means only OE represents the text OECD and CD cannot ever be selected at all. – josefec May 19 '11 at 05:54
  • I’ve found something like this: \makeatletter \DeclareRobustCommand{\PDFreplace}[1]{% \@tfor \next@letter:=#1\do {\BeginAccSupp{method=escape,ActualText=\next@letter}\next@letter\EndAccSupp{}}}% \makeatother But now if I put as the paramater another defined variable, such as \USA, it does the same as before. When I put there directly text, it works as I expect… – josefec May 19 '11 at 07:10
  • 1
    I guess you are looking for \expandafter\PDFreplace\expandafter{\USA}. I wouldn't bother to much that only a part of "OECD" can be selected. How often will someone try to do this? A user will probably always mark larger parts of the document. – Ulrike Fischer May 19 '11 at 07:30
  • Thanks another time. :) Now I have it as I wanted, selectable character by character and all characters copyable and searchable as they should be. :) – josefec May 19 '11 at 07:44