171

The PDF format supports a feature "ActualText" that is used for copy-paste instead of the actual typeset text. However, it is not supported by all PDF viewers, but Acrobat Reader does support it. \documentclass{article} \usepackage{accsupp} \newcommand*{\copyable}[1]{% \BeginAccSupp{% ActualText=\detokenize{#1},% method=escape, }% #1% \...


60

This solution is very similar to that contained in How to make text copy in PDF previewers ignore lineno line numbers? \protecting the accsupp is the only requirement, perhaps due to the nature in which listings treats everything: \documentclass{article} \usepackage{xcolor}% http://ctan.org/pkg/xcolor \usepackage{listings}% http://ctan.org/pkg/listings \...


52

Do you Know the package cmap (look at CTAN:cmap)? It does this for you. Load it with \usepackage{cmap} as first package. Update: I did a little research and found some hints how to use cmap or mmap. Result: cmap and mmap can't handle fonts based on virtual fonts (files *.vf or *.vpl in the font directory). So if your used font needs virtual fonts cmap or ...


43

The PDF format knows a feature "ActualText" that allows to specify a replacement string for copy/paste: \documentclass{article} \usepackage{accsupp} \newcommand*{\Csharp}{% C% \BeginAccSupp{ method=hex, unicode=false, ActualText=23, }% $^\sharp$% \EndAccSupp{}% } \begin{document} \Csharp \end{document} The feature is supported by ...


32

Based on this answer, you could use accsupp to define a \squelch command: \documentclass{article} \usepackage{accsupp} \DeclareRobustCommand\squelch[1]{% \BeginAccSupp{method=plain,ActualText={}}#1\EndAccSupp{}} \begin{document} This text is selectable \squelch{but this text isn't}. \end{document} The squelched text cannot be highlighted in Acrobat, ...


31

Due to problems that came to light in the first answer when loading also the hyperref package, a related question was asked (How do I prevent conflicts between accsupp and hyperref?). The following solution is based on Ulrike Fischer's answer to that question, and illustrates one other advantage of this solution (as pointed out by Heiko Oberdiek) even if ...


27

Luatex allows manipulating fonts in the define_font callback. Luaotfload facilitates this even more with an extra hook it installs right after the font loader has finished its job: the luaotfload.patch_font callback. Normally it is used for serious and constructive tasks like setting a couple font dimensions or ensuring backward compatibility in the data ...


26

Using a method similar to that proposed in How to make listings code correct copyable from PDF and with hyperlink, the following works (at least in Adobe Reader). The accsupp package provides accessibility support for PDFs. By using the \BeginAccSupp and \EndAccSupp group, the line numbers can be typeset in the PDF, but actually replaced by an empty space {}...


23

Here is a hack that uses \ooalign and tikz: \documentclass{article} \usepackage{tikz} \newcommand{\Chash}{\ooalign{\hidewidth\tikz\node[inner sep=0pt,opacity=0]{C\#};\cr C$^\sharp$ \cr}} \begin{document} I know \Chash and else. \end{document} Explain: \ooalign put a transparent C\# over C$^\sharp$ such that you can find it in the PDF. I believe this one ...


21

The PDF specification allows for this - displaying something different from what is retrievable. The randtext package is perhaps a prime example of this. It provides \randomize{<text>} which (from the package documentation) ...typesets a box that looks, on paper, like <text>, but whose letters have in fact been placed in random order so that ...


21

Unicode mapping based on font encoding Packages cmap or mmap add information about glyph to Unicode conversions into the PDF file based on the used TeX encoding. The hooks into the font loading mechanism of LaTeX and should be used as early as possible, e.g.: \RequirePackage{mmap}% (\usepackage does not work before \documentclass) \documentclass{article} ...


20

Remarks I use a little script, which converts all my fonts to paths. The script uses the first parameter as input of a .pdf-file and writes the output to a file with the same name and the extension-rst.pdf You need Ghostscript for my script to run. Implementation Runs on bash #!/bin/sh GS=/usr/bin/gs $GS -sDEVICE=pswrite -dNOCACHE -sOutputFile=-...


17

The listings package also allows for setting content verbatim. Here's an example, using language=TeX (which should be fine if you have plain text): \documentclass{article} \usepackage{listings}% http://ctan.org/pkg/listings \begin{document} \begin{lstlisting}[language=TeX] Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce pulvinar risus eu ...


16

As you don't provide a minimal example, I am not sure if this really addresses your problem. Have you tried loading glyphtounicode.tex? \documentclass{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \input glyphtounicode \pdfgentounicode=1 \begin{document} ff ffi ffl ä ü ö ß auffallen \end{document} However, even without using ...


16

Summary The correct answer is indeed the solution of Gernsheim with \RequirePackage{pdf14} right at the beginning before \documentclass. Details The minor version of the PDF file is set by \pdfminorversion in pdfTeX (Older versions are using \pdfoptionpdfminorversion). The version number is written in the very beginning of the PDF file: %!PDF-1.4 The ...


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 \...


16

The problem with spaces in the pasted text is in the fact that listings adds spaces between letters, unless the option columns=fullflexible is used. \documentclass[letterpaper]{article} \usepackage{amsmath} \usepackage{graphicx} \usepackage{fancyhdr} \usepackage{amsfonts} \usepackage{amssymb} \usepackage[lmargin=2.5cm,rmargin=2.5cm,tmargin=1.5cm,bmargin=3....


15

In general, to enable copy/paste from pdftex-generated PDF, \input{glyphtounicode} \pdfgentounicode=1 should be used.


15

(it seems this works everywhere apart from acrobat reader) This is based on the example by @DavidCarlisle. The cmtt visible space character seems to be labelled differently in different cmtt variants. For cm-super (which is loaded here when I use \usepackage[T1]{fontenc}), the respective character is named uni2423 which seems to cause problems with evince ...


14

If you want it very short, try the plain-TeX \obeylines. It should be used in a group, however. Also, TeX starts a new paragraph after each line in obeylines-mode, which might result in indentation. So you probably want to change indentation (third example below). Try it like this (with default for comparison): \documentclass{article} \begin{document} ...


14

Putting a \RequirePackage{pdf14} in the preamble, just before the \documentclass worked for me.


14

Solution via packages accsupp/soul The following method uses package soul to split the text into tokens. Then the tokens are examined and if a lowercase letter is found, it is set using package accsupp. If the PDF viewer supports the ActualText feature, then you can copy and paste parts of the words. See documentation of package soul for its limitations. ...


13

Use the verbatim environment. \documentclass{article} \begin{document} \begin{verbatim} Do not format this text. \end{verbatim} \end{document} If you need more sophisticated features, take a look at the fancyvrb package.


13

The fatal error you get is ! pdfTeX error (setup): \pdfminorversion cannot be changed after data is writte n to the PDF file. <to be read again> \edef l.6 \begin{document} Using \tracingall, this can be tracked down a bit more to the \AtBeginDocument hook. What it looks like is that hyperref wants to set some PDF settings at the ...


13

You can add your own definitions. Eg. here an example how to copy an "a" as "A": \documentclass[a4paper,12pt]{article} \usepackage[ansinew]{inputenc} \usepackage[T1]{fontenc} \input{glyphtounicode} \pdfglyphtounicode{a}{0041} %0041=A \pdfgentounicode=1 \begin{document} aaaaa \end{document} The main problem is naturally to find the names of the glyphs ...


13

Word auto corrects input ' to the typographically correct ’. LaTeX does this, too. You can try to search-and-replace all ’ to ' in Word itself or Use another input encoding, for example UTF8: \usepackage[utf8]{inputenc}


13

I can help with the line numbers, but not with the indenting. I am not sure it is possible to specify in the PDF (at least in a viewer-independent way) that the indentation should be copied too. You might consider instead attaching the source code file to the PDF (see eg the attachfile, attachfile2 and embedfile packages for that). The line numbers are ...


13

glyphtounicode and cmap The X and Y are probably not the problems. With reference to page 7 in the MinioPro-manual, to make figures and ligatures searchable, you need to enable glyphtounicode translation and load the default mapping table: \input{glyphtounicode} \pdfgentounicode=1 glyphtounicode was included in my MikTeX-distribution, but if it is not ...


12

The following doesn't work in evince, see the discussion in comments below As noted in comments I suspect using colour is the most reliable way: \documentclass{article} \usepackage[T1]{fontenc} \usepackage{color} \begin{document}\showoutput \makeatletter \def\@xobeysp{\textcolor{white}{\char32}} \makeatother \begin{verbatim} def myfunction(x): return x ...


12

Big chars (characters with more than 8 bits) of LuaTeX/XeTeX are not yet fully supported. Workaround: \documentclass{article} \usepackage{fontspec} \usepackage{accsupp} % \usepackage{luatex85} % might be needed as a workaround https://github.com/ho-tex/oberdiek/issues/36 \usepackage{tikz}%\usepackage{pgfmath} \usepackage{stringenc} \usepackage{pdfescape} \...


Only top voted, non community-wiki answers of a minimum length are eligible