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"

Carucel
  • 1,035
  • If the eventual goal were to display a unique explanatory textbox (in the vicinity of the click) depending on what item is clicked, there are answers on this site that achieve that. Maybe you could explain what you will end up doing with the coordinates. – Steven B. Segletes Sep 13 '14 at 14:57
  • Part of the problem is that LaTeX doesn't decide where everything will go until the page ships out. Tikz overcomes this by writing origin locations to the aux file. – John Kormylo Sep 13 '14 at 14:58
  • 1
    @StevenB.Segletes: The eventual goal of my program is that when the user clicks an element of the formula, the definition of this piece is displayed, so I think this is what you meant by displaying a unique explanatory textbox, could you show me where those answers are? – Carucel Sep 13 '14 at 15:17
  • 1
    These are maybe related to what you seek... the pdfcomment package seems to be relevant here: http://tex.stackexchange.com/questions/6306/how-to-annotate-pdf-files-generated-by-pdflatex, http://tex.stackexchange.com/questions/81846/dynamic-picture-in-beamer-presentation, http://tex.stackexchange.com/questions/14842/creating-fillable-pdfs, http://tex.stackexchange.com/questions/57657/how-to-create-page-with-non-printing-annotation ... These still aren't the one I vividly recall, but I will keep looking. – Steven B. Segletes Sep 13 '14 at 18:00
  • In addition to pdfcomment, other relevant packages might be ocgtools, fancytooltips and cooltooltips. – Steven B. Segletes Sep 13 '14 at 18:07
  • 1
    Aha. I think this answer by diabonas is exactly what you want: http://tex.stackexchange.com/questions/34698/strange-appearance-of-tooltips-produced-by-pdfcomment – Steven B. Segletes Sep 13 '14 at 21:14
  • Wow thank you for searching! I think I will indeed use the tooltip method instead. Since the original question was about how to retrieve the coordinates, I will keep this question open, as somebody might find a way to do so. – Carucel Sep 13 '14 at 21:25
  • Do you want the coordinates relative to the paper, or relative to some other reference, for example, the lower left of the equation in question? I am also presuming you want both horizontal and vertical coordinates – Steven B. Segletes Sep 21 '17 at 12:41
  • @StevenB.Segletes, Yes, I would like to have both x and y coordinates with respect to either the lower left of the equation or of the page (that doesn't really matter, since I use the standalone class) – Carucel Sep 23 '17 at 11:15

1 Answers1

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