6

I noticed recently that changing the size of parentheses in LaTeX results in a different encoding of the text in the pdf (as determined using the copy/paste functionality in my pdf viewer). For instance, in the command

$\sin(x) + \sin\bigl(x\bigr)$

the first term is encoded as s i n ( x ) whereas the second term is encoded as s i n <CR> <LF> <U+FFFD> <CR> <LF> x <CR> <LF> <U+FFFD>. (Here <CR> is carriage return, <LF> is line feed, and <U+FFFD> is the unicode symbol for an unknown, unrecognised, or unrepresentable character).

This behavior is undesirable because it makes it impossible to find all instance of "sin(x)" by searching the file. As a mathematician who exclusively reads papers and books on the computer, I find it very important that pdf documents be easily searchable. This is also critical from an accessibility perspective.

Question: Is there any easy way to improve the encoding of the pdf file so that (for instance) the two terms above are encoded in the same way?

This site has a related problem that was solved using the accsupp package, but in my case that method results in the text string \sin (x) + \sin \big (x\big ), which is not so desirable either and is a hassle to make work in the LaTeX file. [Random question: do some visually impaired users prefer that the size of delimiters be recorded, as this output suggests?]

1
  • 2
    It depends on the font and on engine what happens here so you shouldn't show only snippets but a complete example and also mention which engine you use. Aug 13, 2023 at 14:26

1 Answer 1

6

How glyphs are copied and pasted depends on the ToUnicode values of the font. Setting them is not trivial with the old type1 fonts. The easiest way to improve copy&paste and accessibility of math is to use lualatex and the unicode-math package and so an open-type math font:

\documentclass{article}
\usepackage{unicode-math}

\begin{document}

$\sin(x) + \sin\bigl(x\bigr)$

\end{document}

The formula is then copied as

sin(𝑥) + sin(𝑥)

But you can't search for sin(x) as the real text is sin(𝑥) unless your pdf viewer uses some heuristic to map the two x.

With pdflatex and the standard fonts you can try the mmap package:

\documentclass{article}
\usepackage{mmap}
\begin{document}

$\sin(x) + \sin\bigl(x\bigr)$

\end{document}

This then copies as

sin(x) + sin
\bigl( 
x
\bigr) 
1
  • Neither of these solutions is entirely ideal for me, but given the difficulties of mixing LaTeX and pdfs (e.g. making tagged pdfs) this is probably the best I can get right now. Thank you!
    – user134824
    Aug 16, 2023 at 15:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .