1

Currently, I have the following setup wich works to return the LaTeX source code on selection/copy in the PDF output.

I am wondering if it is possible to redefine mathmode or $ to wrap its contents in the \copyable command.

The result I am hoping for is that all text typeset in mathmode can easily be copied from the generated PDF without the person typesetting the document to have to do more work.

\documentclass{report}

\RequirePackage{accsupp}

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

\begin{document}

\copyable{\( a-b \ne c+1\)}

\end{document}

EDIT after comment - I came up with this for now as a workaround for inline math and display math.

\cf for "copyable formula".

\protected\def\cf{\@ifnextchar[\@copymathDisplay\@copymathInline}
\def\@copymathDisplay[#1\]{\copyable{\[#1\]}}
\def\@copymathInline(#1\){\copyable{\(#1\)}}

However, I would like to have it take effect everywhere in the document where math mode is used. Such that also takes effect when used in environments like for example eqnarray.

  • 1
    If you are using \( .. \) you can probably use etoolbox package and do \preto\({\BeginAccSupp{..}} and \appto\){\endAccSupp{}}. – Manuel Sep 4 '16 at 21:17
  • I am looking to redefine the internal mathmode in such a way that this takes effect on all environments which use it too. Updated my answer to reflect this. – Alexed Sep 6 '16 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.