3

Is there is a way to enrich the generated pdf output from any tex source so that it contains the names of (some of) the symbols used? For example, let's us suppose that we have the following minimal example:

\documentclass[11pt]{article}
\usepackage{amssymb,amsmath}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{Linux Libertine O}
\def\mystigma{\symbol{"03DB}} % hex code of some symbol
\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}

How we could redefine \int and \mystigma commands so that one could be able to search the pdf for the words integral, stigma or mystigma?

7

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.