When I create a pdf file containing English text using pdflatex, I can copy text from it and get a reasonably fair text when pasted in a text editor. But when I do the same with a pdf of Malayalam text created using xelatex, the pasted text has several gaps and often wrong characters too. I was under the impression that the pdf created with xelatex will also have Unicode text, which then can be searched, indexed and copied. At least, that is the impression I got from reading about xelatex. On the other hand, I found that Malayalam text can be clearly copied from a pdf created from Libre Office Writer. Is my impression about XeLaTeX wrong, or my understanding of the pdf format wrong? Or am I mistaken somewhere else? I would be very grateful if someone knowledgeable about this can give a reply.
-
Could you please provide an MWE?– Cyriac AntonyJul 5, 2019 at 11:14
-
An MWE from tex.stackexchange.com/q/89118/157031: \documentclass{article} \usepackage{fontspec} \setmainfont[Script=Malayalam]{Rachana} \begin{document} മലയാളം \TeX ഉപയോഗിച്ച് ടൈപ്പ്സെറ്റ് ചെയ്തത് \end{document}– Cyriac AntonyJul 5, 2019 at 13:02
2 Answers
Malayalam is a script related to Sanskrit, and the single characters undergo considerable changes from the input to the output. In particular, some vowels are placed before the corresponding consonant, and glyphs are put together into compounds, so called ligatures. See https://en.wikipedia.org/wiki/Malayalam_script for examples of ligatures and vowel placements (and much more!).
On the font side, these compounds of consonants are usually precomposed, that is, drawn separately to make them look right. During the typesetting, the characters are replaced with the pre-composed codepoints in the fonts, but those often don't have a textual representation.
There are ways around is, and the font can declare a mapping from code points to character sequences, but this is often not available.
-
What about PDF/A support? AFAIK, this format mandates that the Unicode input strings are preserved, thus bypassing the problematic
input string→glyph→input-like string
conversion. With proper language tagging I can imagine that this works– lemzwergNov 5, 2019 at 7:41 -
I agree that PDF/A can help here, but this is probably not what xelatex produces.– norbertNov 5, 2019 at 8:31
This seems to be a technical limitation of the XeLaTeX engine. The issue is incomplete CMAP (character map) of the font embedded in PDF. Recent versions of luahbtex
can generate PDF containing complex script texts which can be copy pasted back to a text editor properly. Here is one example of such a document: http://books.sayahna.org/ml/pdf/bbh-web.pdf
-
This also doesn't seem to solve that problem. When I copy and paste one paragraph from the above link into a text editor, the symbols for the vowel 'എ' joined to consonants is replaced by something else. Perhaps, might lualatex solve the problem?– SasiMay 4, 2020 at 6:54