# Placing the un-ligatured text in the OCR layer

I was reading Why can't "fi" be separated when being copied from a compiled pdf? and had a thought:

I know that v1.4 and up PDF documents have an OCR layer. Would it be possible to have PDFTeX or luaTeX place the un-ligatured text into the OCR layer, so that you don't have inconstant or odd behaviour when copying ligatures?

It also occurs to me that this also be a workaround for my troubles copying mathmode greek characters, discussed in Proper way to use greek letters in an English document . This also seemed like an ideal way to provide more accessible code for equations, as trying to copy them right now is not exactly useful.

-
I would rather use some technique as shown in Is it possible to provide alternative text to use when copying text from the PDF?. This should result in a much smaller file size than having all text twice in different layers. Also the OCR layer might not be accessible from LaTeX because of the lack of support. –  Martin Scharrer Nov 2 '11 at 20:12
I don't see any way of doing that for my whole document though- I would have to do that for every ligature, wouldn't I? (I did look at that question as I posted this, but dismissed it) Also I don't worry about text file size- One image, even a small one, will increase my file size by more then the entire text of the document. You can fit the entire text contained in the library of congress on 1 CD-ROM. –  Canageek Nov 2 '11 at 20:20
I don't see any way to put all text of the whole document in the normal and the OCR layer. AFAIK you need to connect both layers, i.e. every character in the OCR layer to every character in the normal layer. This requires some PDF formatting code which takes far more space than the character itself. –  Martin Scharrer Nov 2 '11 at 20:24
@MartinScharrer I regularly download scientific journals that are OCRed images, and these are not totally insane files sizes, so yes, there would be a hit, but in some cases it might be worth it. Too bad, it would be something I'd like to experiment with. –  Canageek Nov 3 '11 at 18:13

Two possible tools you can use to achieve what you are after:

The first one is calibre-ebook, which can do pdf to pdf conversions, plus a tonne of other formats.

The second is Heiko Oberdiek's experimental package accsupp. This enables you to map alternatives to characters and text for accessibility purposes, but will achieve what you want as well. At the end of the day I think it is high time we stop using ligatures. They don't offer much in terms of improving typography on a screen.

The below example is from the package. You need to adapt to suit.

\documentclass{article}
\usepackage[unicode]{hyperref}
\usepackage{accsupp}[2007/11/14]
\begin{document}
$$\BeginAccSupp{ method=pdfstringdef, unicode, ActualText={% a\texttwosuperior +b\texttwosuperior =c\texttwosuperior } } a^2 + b^2 = c^2 \EndAccSupp{}$$
\end{document}


Your suggestion to map it to the OCR layer is not an option unless you scan the PDF and OCR it. To summarize start with calibre-ebook and if it cannot offer you what you want explore the other options.

-
I strongly disagree that we need to stop using ligatures: Once you start to notice them reading text without them becomes more and more painful. –  Canageek Mar 10 '12 at 22:41
@Canageek Most of our documents are now in electronic form. Text with ligatures gives problems with search. Put this dœs through a spell checker. –  Yiannis Lazarides Mar 11 '12 at 2:12
Which is why documents & search algorithms should be adapted to deal with this automatically. –  Canageek Mar 12 '12 at 16:01
Additionally, this is not only a problem with ligatures, you will have issues when using "OldStyle" numbering as well. So there is a real issue here. –  Dan Jun 1 '12 at 10:16