You can use the accsupp
package to provide the actual text.
\documentclass{article}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{Linux Libertine O}
\def\mystigma{\symbol{"03DB}} % hex code of some symbol
\ifdefined\directlua % = if we are using LuaTeX
\protected\def\pdfliteral{\pdfextension literal }
\fi
\usepackage{accsupp,etoolbox}
\newcommand\actualtext[2]{%
\preto#1{\BeginAccSupp{ActualText=#2}}%
\appto#1{\EndAccSupp{}}%
\robustify#1
}
\actualtext\int{integral}
\actualtext\mystigma{stigma}
\begin{document}
Some pages...
$\int_1^ x (t +1) dt=\frac{1}{2}(x^2+2x-3)$. This is the greek stigma: \mystigma.
More pages follows..
\end{document}
The output doesn't change, but pdftotext
now reports
Some
integral x pages… 1 2
1 (t + 1)dt = 2 (x + 2x − 3). This is the greek stigma: stigma.
More pages follows..
1
If you don't use ConTeXt you can ignore this part.
\definetypeface[main][rm][serif][libertine][default]
\definetypeface[main][ss][sans] [modern] [default]
\definetypeface[main][tt][mono] [modern] [none]
\definetypeface[main][mm][math] [modern] [default]
\setupbodyfont[main]
\chardef\mystigma="03DB
\define[2]\actualtext{%
\expandafter\let\csname saved_\string#1\endcsname=#1
\define#1{\pdfactualtext{\csname saved_\string#1\endcsname\relax}{#2}}
}
\actualtext\int{integral}
\actualtext\mystigma{stigma}
\starttext
Some pages...
$\int_1^ x (t +1) dt=\frac{1}{2}(x^2+2x-3)$. This is the greek stigma: \mystigma.
More pages follows..
\stoptext
pdftotext
reports
1
Some pages…
integral 𝑥1 (𝑡 + 1)𝑑𝑡 = 12 (𝑥2 + 2𝑥 − 3). This is the greek stigma: stigma.
More pages follows..