1

I'm using align extensively as my display math environment and I'd like for the selectable text in the pdf for math equations to be the latex code used to generate it. Ideally, I'd redefine the align environment to do it automatically, but I'm only testing for now.

Using the answer to this question, I managed to make something semi-working using.

\usepackage{accsupp}
\newcommand\copypaste[1]{%
    \BeginAccSupp{method=escape,ActualText={\detokenize{#1}}}%
      #1%
    \EndAccSupp{}%
}

I can make simple equations source-copyable this way

\begin{align}
  \copypaste{
     \frac14&=(\frac12)^2
            &=(\frac12)^{1+1}
  }
\end{align}

Copying this from the PDF yields \frac 14&=(\frac 12)^2 \\ &=(\frac 12)^{1+1}, which is basically want I want.

However, this approach has a major and a minor issue.

  • The major issue is that it doesn't work if there's a page break in the environment; e.g. for long development. It compiles, but the math isn't selectable. Actually, nothing is selectable between the start and the end of the displayed equation, not even page numbers or footnotes.
  • The minor issue is that only the first line of the environment is selectable, containing all the code in the environment. That's unconvenient, but not a deal breaker. I can wrap each line with it's own \copypaste call, but it would be tedious to redefine the align environment to do this automatically. I also had some weird error when doing so with long environment.

Any pointers as to how to work around those issues, implement it properly or reference to packages that'd already do this properly would be greatly appreciated.

I'm using pdfTex 3.14159265-2.6-1.40.20 (TeX Live 2019).

  • accsupp can not be used across page breaks. This inserts markers in the pdf which must be properly nested on one page. And while putting larger text in it more or less work, you are actually misusing /ActualText which is meant for short texts or single chars. – Ulrike Fischer Apr 18 '20 at 17:16
  • Is there a workaround? I don't care if the whole code is inserted only at the beginning of the first line before the page break. Or maybe there's a proper way to wrap each line in it's own copypaste command so that there would be no pagebreak within? – JeanOlivier Apr 18 '20 at 17:20

0 Answers0