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 inthe environment; e.g. for long development. It compiles, but themath 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 isselectable, containing all the code in the environment. That'sunconvenient, but not a deal breaker. I can wrap each line with it'sown
\copypaste
call, but it would be tedious to redefine the alignenvironment to do this automatically. I also had some weird errorwhen 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)
.