175

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


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


29

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


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


23

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


22

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

(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

It is also possible to use the Mathpix desktop app (for Mac and PC(beta)) to take a screenshot of the PDF and it will render the LaTeX instantly (and already have it copied to your clipboard, all you have to do is paste into your editor of choice). Here is a brief demo using Mathpix to extract LaTeX from a PDF and pasting into Overleaf:


12

If content can be viewed, it can be copied. No matter what encryption and restrictions are used, at some point the content must be put out in plain view in order for it to be of any use. This is probably true of all digital content and most physical content larger than the nanoscale... For example, a PDF: Rasterisation: Printscreen => OCR Any protection: ...


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


11

accsupp does allow for this: \documentclass{article} \usepackage{accsupp}% http://ctan.org/pkg/accsupp \begin{document} \BeginAccSupp{ActualText=Eyjafjallajokull} Eyja$\cdot$fjalla$\cdot\cdot$j{\"o}k$\vert$ull \EndAccSupp{} \end{document} While the selection might not be as expected, the search works (in Adobe Reader, at least).


11

Very naive, but easy to generalize. Final definition should have two parameters and take maximum of two lengths. \documentclass[11pt]{article} \usepackage{color} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \begin{document} \newlength\eyja \settowidth{\eyja}{Eyjafjallajökull} In a dictionary a headword can consist of special characters ...


11

Unfortunately, space characters cannot reliably be copied from a PDF. This answer on Superuser is bang on: The problem with PDF is that it doesn't really encode text. All it does is pretty much saying "Put those glyphs there, and those glyphs there". It's a format intended for print and high-fidelity document preview on screen but not so much to ...


11

If you compile with pdflatex you can do this: \documentclass{article} \usepackage{Alegreya} \input glyphtounicode \pdfgentounicode=1 \pdfglyphtounicode{fj}{0066 006A}% f j \begin{document} fb ffb ff fh ffh fi ffi fj ffj fk ffk fl ffl ft fft \end{document}


10

Maybe something like this: \documentclass[12pt]{article} \parindent 0pt \usepackage[T1]{fontenc} \usepackage{accsupp} \let\ORIGlatex\LaTeX \renewcommand{\LaTeX}{% \BeginAccSupp{method=plain, ActualText=LaTeX}% \ORIGlatex \EndAccSupp{}} \begin{document} \ORIGlatex \LaTeX \end{document} Note that the status of the package accsupp is still said to be ...


10

The Unicode symbol is U+00BA (MASCULINE ORDINAL INDICATOR). It is available in encoding TS1 as provided by package textcomp: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{textcomp} \begin{document} º = \textordmasculine \end{document}


10

\documentclass{article} \usepackage{accsupp} \newcommand\pdfminus{\BeginAccSupp{method=escape,ActualText=-}-\EndAccSupp{}} \begin{document} $\pdfminus A \pdfminus B = C$ $-A - B = C$ \end{document} Copy/paste yields: -A - B = C 􀀀A 􀀀 B = C SUPPLEMENT The OP comments on how it would be nice to have it done automatically. Unfortunately, redefining - as ...


9

The problem is fragility: \documentclass{article} \usepackage{accsupp} \renewcommand{\thefootnote}{% \protect\BeginAccSupp{ActualText={}}\arabic{footnote}\protect\EndAccSupp{}% } \begin{document} This is a test\footnote{This is a footnote} \end{document}


9

There is currently no font encoding fully supporting Romanian, I'm afraid. New fonts should be created: not from scratch, but it would be a big job and you'd not have many of them available anyway. The problem is that in the standard encoding OT1, no accented letter is present; with T1 the situation is slightly better because ÂâÎîĂă are present as ...


8

Good question, which includes a thorough analyis! I did not find any official documentation of XeTeX for the equivalent for pdfTeX's \pdfliteral direct. The manual of dvipdfm, some predecessor of XeTeX describes \special{pdf:content ...}. Nothing in xetex-reference.pdf or XeTeX-notes.pdf. In file pgfsys-dvipdfm.def the following "ugly hack" can be found: \...


8

You have one obvious problem in your code: You set numberstyle to make it non-copyable and then you reset it with fancy font stuff. Any option is overwritten at a later use. The effects do not add up. So you need that one line: numberstyle=\tiny\color{codegray}\noncopynumber. A true MWE showing how to apply your macro would be \documentclass{article} \...


7

I found a solution to the leading whitespace! Edit: Actually, it doesn't work in Adobe reader. It works in SumatraPDF. Thanks to Daniel and cgnieder for their comments above. As described by Martin Monperrus you can use the accsupp package to differentiate text that you copy-paste from the type-set text. Note that the linked page is not usable out of the ...


7

This is what I get when compiling your example (by the way, loading xunicode is not required), copying from the PDF viewer and pasting here fi ff tt The Minion Pro font I'm using is the one in Adobe Reader. Here's a picture where the characters have been selected: The viewer is Skim, but also Adobe Reader gives the expected result. Here's an example of ...


7

The indentation of the first line for all paragraphs in scope can be set by (see Menke's answer): \setlength{\parindent}{0pt} \hangindent has to be repeated for each paragraph. \everypar helps: \everypar{\setlength{\hangindent}{2.5em}} But caution is needed, because LaTeX uses \everypar quite often itself, e.g. in \section and friends. An alternative is ...


7

I'm using glyphtounicode support file (even with Czech/Slovak related IL2 font encoding) from TeX Live for some time now, I cannot test it with MiKTeX, unfortunately. We run: pdflatex mal-sk.tex pdftotext -enc UTF-8 mal-sk.pdf The result is: 1 ľščťžýáíéäúôň, it shows the page number and the document content. I enclose the code. Please, try it if it fits ...


7

First, I fully agree with Jesse Knight: Whoever made this requirement at your faculty is a sadist But if you use LuaTeX you can destroy the glyph to unicode mapping in the PDF file by creating a special font feature: % lualatex -shell-escape minted.tex \begin{filecontents*}{test.rb} # this should not be copyable def hello "world" end \end{...


6

As requested, an example using package accsupp that works for pdfTeX, the dvipdfm family (dvipdfm, dvipdfmx, XeTeX). In principle it could work for dvips, but from the documentation of accsupp: 1.3.3 Option dvips Package option dvips and its alias dvipsone write pdfmark specials in the output. Unhappily these pdfmark operators are ignored by ...


6

I suggest you to add the following lines to your preamble: \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} It worked perfectly with me. I am on mac OS (Texmaker also) and I couldn't try on windows. Edit: As suggested by @egreg , adding \usepackage{lmodern} might help.


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