11

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

  • 3
    You are probably out of luck: see tex.stackexchange.com/questions/8503/…. Your question will probably be closed as a duplicate. – Ethan Bolker Dec 11 '12 at 18:32
  • Are you interested in getting useful symbols or do you really want the complete LaTeX code back? – Stephan Lehmke Dec 11 '12 at 18:40
  • 2
    For instance, if I add \input{glyphtounicode} \pdfgentounicode=1 to the preamble of the document, I get f : R → R. – Stephan Lehmke Dec 11 '12 at 18:46
  • @EthanBolker I just found out how to make it paste back as TeX code ;-) – Stephan Lehmke Dec 11 '12 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? – Stephan Lehmke Dec 11 '12 at 21:41
16

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}
  • 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? – Loop Space Dec 11 '12 at 19:57
  • @AndrewStacey Not sure what you mean. It's a method to make PDF paste back LaTeX code. – Stephan Lehmke Dec 11 '12 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. – Loop Space Dec 11 '12 at 20:05
  • Exactly. It has to be used when compiling the LaTeX to PDF. – Stephan Lehmke Dec 11 '12 at 20:05
  • 4
    Is there a way to make all the document pasteable? – Manuel Dec 11 '12 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.