14

In the following example, I can't manage to make accsupp store the unicode alternative text. The resulting PDF looks as expected but the copyable text is not the correct one. I tried this with different accsupp options: method=plain,...=escape, ...=pdfstringdef, and unicode. (accsupp manual is here). I tried with Acrobat 9.4.1 (Linux) and Evince. I am using LuaLaTeX to compile.

The idea is that when I select the equation in the next document the text ⅆa is copied. (In most cases only a gets copied.)

\documentclass{article}
\usepackage{fontspec}
\usepackage{accsupp}

\begin{document}

\BeginAccSupp{unicode,ActualText=ⅆa} %method=plain, ...=escape, ...=pdfstringdef
$da$
\EndAccSupp{}

\end{document}
alfC
  • 14,350

1 Answers1

12

Big chars (characters with more than 8 bits) of LuaTeX/XeTeX are not yet fully supported. Workaround:

\documentclass{article}
\usepackage{fontspec}
\usepackage{accsupp}
% \usepackage{luatex85} % might be needed as a workaround https://github.com/ho-tex/oberdiek/issues/36

\usepackage{tikz}%\usepackage{pgfmath}
\usepackage{stringenc}
\usepackage{pdfescape}

\makeatletter
\newcommand*{\BeginAccSuppUnicode}[1]{%
  \EdefSanitize\asu@str{#1}%
  \edef\asu@str{%
    \expandafter\expandafter\expandafter\asu@ToSpaceOther
    \expandafter\asu@str\space\@nil
  }%
  \expandafter\let\expandafter\asu@str\expandafter\@empty
  \expandafter\asu@ToHexUC\asu@str\relax
  \EdefUnescapeHex{\asu@str}{\asu@str}%
  \StringEncodingConvert{\asu@str}{\asu@str}{utf32be}{utf16be}%
  \EdefEscapeHex{\asu@str}{\asu@str}%
  \BeginAccSupp{%
    unicode,%
    method=hex,%
    ActualText=\asu@str
  }%
}
\begingroup
  \lccode`\9=`\ %
\lowercase{\endgroup
  \def\asu@SpaceOther{9}%
}
\def\asu@ToSpaceOther#1 #2\@nil{%
  #1%
  \ifx\\#2\\%
    \expandafter\@gobble
  \else
    \asu@SpaceOther
    \expandafter\@firstofone
  \fi
  {\asu@ToSpaceOther#2\@nil}%
}
\def\asu@ToHexUC#1{%
  \ifx#1\relax
  \else
    \pgfmathHex{\the\numexpr`#1+"10000000\relax}%
    \edef\asu@str{%
      \asu@str
      0\expandafter\@gobble\pgfmathresult
    }%
    \expandafter\asu@ToHexUC
  \fi
}
\makeatother

\begin{document}

\BeginAccSuppUnicode{ⅆa}
$da$
\EndAccSupp{}

\end{document}
alfC
  • 14,350
Heiko Oberdiek
  • 271,626
  • mmm, I get this ! Undefined control sequence. // l.108 \pgfkeys with LuaLatex Version beta-0.76.0-2013122811 (TeX Live 2014/dev) (rev 4627). – alfC Apr 14 '14 at 05:38
  • ".. are not fully supported yet" by who? by accsupp or by xe/lualatex? – alfC Apr 14 '14 at 05:40
  • 1
    @alfC: Try with \usepackge{tikz}. There might be an issue with missing module dependencies of pgf/TIkZ, because the code only uses \pgfmathHex. – Heiko Oberdiek Apr 14 '14 at 05:46
  • 1
    @alfC: For example, packages stringenc and pdfescape, accsupp could be updated to support "big chars". A clear and unambiguous specification for the support of "big chars" is probably the most difficult part. – Heiko Oberdiek Apr 14 '14 at 05:50
  • ok, that works!, (I corrected it in your answer). Now Acrobat copied correctly ⅆa. Unfortunately Evince copies da (it really convert into d, I don't know how), but I guess that is beyond the scope of this question. A question by the way, why did you choose the syntax \BeginAccSupp{option} ...\EndAccSupp{} instead of \accsupp[options]{...}? Is there a techical reason for that. Can one make use of the last syntax by defining a new command? – alfC Apr 14 '14 at 05:59
  • 2
    @alfC: For example, you can't use \verb inside an argument. The package just provides the basics, but onthe other hand, it supports different formats including plain TeX. Thus, just make a nice cozy command. e.g. something like \newcommmand{\accsupp}[2]{\BeginAccSupp{<options>,ActualText={#1}}#2\EndAccSupp{}} which hides the option settings from the user interface. – Heiko Oberdiek Apr 14 '14 at 10:31
  • Can this technique be used to allow "tab" characters in accsup? (it is for this http://tex.stackexchange.com/questions/194505/techniques-to-make-tabular-contents-copyable) – alfC Aug 11 '14 at 16:35
  • @alfC I have written an answer there, which shows, how the horizontal tabulator and the line feed characters can be used with accsupp. – Heiko Oberdiek Aug 11 '14 at 20:30
  • In Lualatex 1.0.4 (TeX Live 2017) this needs \usepackage{lautex85} to workaround a bug https://github.com/ho-tex/oberdiek/issues/36. – alfC Aug 29 '18 at 18:59
  • @alfC Thanks for adding the workaround with \usepackage{luatex85}. – Heiko Oberdiek Aug 29 '18 at 19:04