13

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)?

6
  • 3
    You are probably out of luck: see tex.stackexchange.com/questions/8503/…. Your question will probably be closed as a duplicate. Dec 11, 2012 at 18:32
  • Are you interested in getting useful symbols or do you really want the complete LaTeX code back? Dec 11, 2012 at 18:40
  • 2
    For instance, if I add \input{glyphtounicode} \pdfgentounicode=1 to the preamble of the document, I get f : R → R. Dec 11, 2012 at 18:46
  • @EthanBolker I just found out how to make it paste back as TeX code ;-) Dec 11, 2012 at 19:40
  • 1
    @hmmmm could you disambiguate whether you want to copy LaTeX from any PDF document or want to be able to make a PDF from which LaTeX can be copied? Dec 11, 2012 at 21:41

1 Answer 1

17

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}
11
  • To be clear, can you confirm that this only works if the person who compiled the PDF used this method? I guess that without that there's no way to do this, isn't there? Dec 11, 2012 at 19:57
  • @AndrewStacey Not sure what you mean. It's a method to make PDF paste back LaTeX code. Dec 11, 2012 at 19:59
  • I mean that if you give me a PDF without the source code then I can't use your method to recover that source code. But if I as an author want to be kind to readers (assuming that there are some) then I can use this to make my PDF so that copying gives the LaTeX code. Dec 11, 2012 at 20:05
  • Exactly. It has to be used when compiling the LaTeX to PDF. Dec 11, 2012 at 20:05
  • 4
    Is there a way to make all the document pasteable?
    – Manuel
    Dec 11, 2012 at 20:23

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.