2

I use l e t t e r s p a c i n g provided by soul/soulutf8 to emphasize words. But

  • If I try to copy a spaced word from the pdf-file, then I get "w o r d" instead of "word".

  • Also the search for "word" in pdf-file does not return the spaced word.

Is there a trick to fix this problem?

7

2 Answers 2

3

You've already found a satisfactory solution by (1) using accsupp and also (2) reducing the tracking (=intraword spacing) from a whopping 0.25em (\textso's default) to 0.1em. (In my experience, no. (2) by itself can solve the search and copy issue with most PDF readers.)

In addition, I would like to suggest abandoning soul(utf8) in favor of the superior letterspacing tool from pkg microtype (available separately as pkg letterspace). Particularly if you have to deal with long portions of text, indexing commands, or the like.

soulutf8, despite the recent updates and the Unicode compatibility, still suffers from some limitations of the old soul package. \textso interacts poorly with some other macros. Of the more common ones, using \index or \cite in the argument aborts compilation, while using \mbox or math mode breaks the letterspacing functionality (examples below). There are workarounds, but they can get pretty ugly: in the last example, you'd need to "close" and "reopen" \textso every time, which in turn makes for too short interword spaces.

letterspace handles these cases easily, besides being more flexible in choosing the amount of letterspacing (case by case or globally). And of course, it can be combined with accsupp as in Steven Segletes' and your approach.

letterspacing examples

\documentclass{article}

\usepackage{letterspace}                % or microtype
\usepackage{soulutf8}

\begin{document}

\textso{triangle $ABC$} (\verb|\textlso|)   

\textls[250]{triangle $ABC$} (\verb|\textls|)

\bigskip

\textls{foo \mbox{bar} \index{baz}baz (\cite{mybook})} 
(\verb|\textls|, mbox index and cite succeed)

\textls[250]{foo bar baz} (\verb|\textls|)

%\textso{foo bar \index{baz}baz} (\verb|\textlso|)          % doesn't compile!
%\textso{foo bar baz \cite{mybook}} (\verb|\textlso|)       % doesn't compile!

\textso{foo \mbox{bar} \protect\index{baz}baz (\protect\cite{mybook})} 
(\verb|\textlso|, mbox index and cite prevent letterspacing)

\textso{foo} \mbox{\textso{bar}} \index{baz}\textso{baz} (\cite{mybook}) 
(\verb|\textlso|, requires some contorsions, messes up interword spaces)

\end{document}
3

The problem is solved, thanks to Steven B. Segletes:

\documentclass{article}
\usepackage{accsupp}
\usepackage{soulutf8}

\newcommand\an[1]{%
    \BeginAccSupp{method=escape,ActualText={\detokenize{#1}}}%
      \so{#1}%
    \EndAccSupp{}%
}

\def\emph{\an}

\begin{document}
Try to copy this \emph{word} --- you will see ``word'', but not ``\emph{word}''. 
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .