[Tex/LaTex] Copying LaTeX from a PDF

conversioncopy/pastepdf

Is there a way to copy from a PDF to a LaTeX document? Whenever I do it, it copies in with weird symbols in the place of LaTeX commands for example:

$$f:\mathbb{R}\rightarrow \mathbb{R}$$

copies in as

f : R ! R;

I did a quick search and I couldn't really find anything (some sort of PDF to LaTeX converter that worked well)

Am I missing something obvious or can this not be done (for some reason)?

Best Answer

Try this:

\documentclass{article}
\usepackage{amssymb}
\input{glyphtounicode}
  \pdfgentounicode=1
\usepackage{accsupp}

\newcommand\pasteablelatex[1]
{%
  \edef\next
  {%
    \noexpand\BeginAccSupp{method=escape,ActualText=\detokenize{#1}}%
  }%
  \next#1\EndAccSupp{}%
}

\begin{document}

foo

\pasteablelatex{$$f:\mathbb{R}\rightarrow \mathbb{R}$$}

bar

\end{document}