3

I'm writing a program that uses LaTeX to display formula's. The user must be allowed to click on different parts of the formula, and the program should know on which part the user clicked.

Is there a way to retrieve the coordinates of all characters in a formula? I would like to output these coordinates with LaTeX to a file and then read this file with the external program.

Perhaps there is some LaTeX command that can be used like this:

$a=\sqrt{b^2+c^{\getcoords{2}}}$

which saves the coordinates of the digit 2 in a variable, which I can then write to an output file.

Does anybody know anyway to achieve this?


OP's comment transcribed from comment section below:

"The eventual goal of my program is that when the user clicks an element of the formula, the definition of this piece is displayed"

1

I go right to the OP's comment, "The eventual goal of my program is that when the user clicks an element of the formula, the definition of this piece is displayed" and employ a completely different approach to achieve it, using pdfcomment, rather than a routine to retrieve coordinates.

This approach had been mentioned by myself in the comments (4 years ago), but the OP still wanted to see if anyone put forward an approach of coordinate retrieval.

\documentclass{article}
\usepackage{pdfcomment}
\begin{document}
$a\pdftooltip{=}{What follows the = sign is a  square-root expression}
  \sqrt{\pdftooltip{b}{This is a variable named b}^
    {\pdftooltip{2}{this notation indicates that b is sqared}}+c^3}$
\end{document}

enter image description here

Holding the cursor over the = yields

enter image description here

Holding the cursor over the b yields

enter image description here

Holding the cursor over the 2 superscript yields

enter image description here

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.