Making symbols clickable

195 views
Skip to first unread message

anders...@gmail.com

unread,
Mar 23, 2012, 11:31:22 AM3/23/12
to mathja...@googlegroups.com
Hi, I have searched a lot about this topic, but haven't found anything useful yet. I hope you can help me.

I am using MathJax to display equations on the web. I want to be able to click a generated symbol and retrieve the contents of that symbol (okey pure javascript...) but also the position and the code which the symbol was generated from. With this information, my goal is to implement a cursor which can be used to insert more mathjax objects.

I do not have any code to show you since my intention is to see if it is even possible using mathjax.

Any ideas?


/ Anders

Thomas Leathrum

unread,
Mar 23, 2012, 3:10:20 PM3/23/12
to mathja...@googlegroups.com
The particular interface you describe might be a bit much for HTML to handle in general, but I think I can get you pretty close with a couple of the MathJax extensions in the Contributed Extensions Repository (https://github.com/leathrum/mathjax-ext-contrib) -- look in particular at the extensions for "knowl" and "forminput", documentation and examples are provided in the repository.  If these provide anything close to the interface you have in mind, then yes, it should be possible to get your ideas working.

anders...@gmail.com

unread,
Mar 24, 2012, 2:02:49 PM3/24/12
to mathja...@googlegroups.com
Thank you for your reply.

I am not quite sure how those would work with my interface. The knowl is interesting since you can hide information in a single element and the forminput may be good if you could insert it dynamically.

I think I should describe my project a little bit further. It is kind of a WYSIWYG LaTeX editor. I have a model with an expression represented by a list of symbols or sub expressions. Every symbol or expression have zones around them (for sub- and superscript etc.). The model generates LaTeX which I want to display visually by MathJax. To be able to edit an expression I want to put a cursor to the left of a symbol when it is clicked (both visually and in my model). But since my model and MathJax are logically separated I need to insert some logic to be able to change the position of the cursor in my model.

I started digging in MathJax and found a macro called cssId, which inserts an ID to a symbol or a whole expression. I could probably insert some info in the ID and analyze it later, but in my opinion this is a hacky solution. So I'm looking for alternatives.

I hope that gives you clarity. Do you still think I can work with those extensions, or is cssId best for me? Anything even better?


/ Anders

Davide P. Cervone

unread,
Mar 26, 2012, 9:11:16 AM3/26/12
to mathja...@googlegroups.com
See my post at

https://groups.google.com/d/msg/mathjax-users/fRGv6pcCXiA/-ZBPBOVcbjMJ

and the rest of that discussion for some ideas about getting mouse
clicks from MathJax. There is also a discussion at

https://groups.google.com/d/topic/mathjax-dev/4W4Gp6x2w2M/discussion

about some of the difficulties of trying to map back to original TeX
code.

Davide

On Mar 23, 2012, at 11:31 AM, <anders...@gmail.com> <anders...@gmail.com

Davide P. Cervone

unread,
Mar 26, 2012, 10:17:42 AM3/26/12
to mathja...@googlegroups.com
> I started digging in MathJax and found a macro called cssId, which
> inserts an ID to a symbol or a whole expression. I could probably
> insert some info in the ID and analyze it later, but in my opinion
> this is a hacky solution. So I'm looking for alternatives.

I think this is probably the best approach. What sort of alternative
did you have in mind?

Currently there is no API to subexpressions, only to the equation as a
whole. So there is no direct way to get information about the sizes
of subexpressions, for example. Note that (in the HTML-CSS output)
the elements are stored in span's so their offsetWidth values will be
correct, but their heights may not correspond to the actual heights of
the contents (and indeed, MathJax uses zero-height boxes in some
places to make alignment to the baseline possible). So it is not easy
to get the actual bounding box of the subexpressions.

Davide

Andreya Piplica

unread,
Sep 11, 2014, 1:20:33 PM9/11/14
to mathja...@googlegroups.com
I am working on a project with similar needs; I want a user to select part of a math expression, either by clicking on it or highlighting it the way you would select text. Once they've made their selection, I want to identify which subexpression(s) they have selected. My input to MathJax is MathML annotated with attributes about subexpressions I'm interested in. Currently, I'm storing the subexpression attributes in MathML's other attribute. I'd like to associate these subexpression attributes on the MathML with the parts of the rendered MathJax that the user can select so I can identify the subexpressions.

I've looked at the example on getting span ids from clicking on math. Unfortunately, I can't store the attributes I need as CSS ids because they won't necessarily be unique on the page. I've observed that MathJax also preserves the CSS class attribute, but they're not really classes. I've also noticed that all attributes from the original MathML are stored in the root property of the element jax. However, as Davide mentioned, there is no API for accessing these subexpression properties, so I don't really want to go digging in the element jax root property.

Is there another way to associate arbitrary attributes from the MathML with the rendered spans? Or is the class attribute my best bet here?

Does the MathJax team plan to create an API for accessing subexpressions? If not, is this worth writing some kind of extension for?

Thanks for your help,
Andreya.

Peter Krautzberger

unread,
Sep 20, 2014, 9:27:50 AM9/20/14
to mathja...@googlegroups.com
Hi Andreya,

Creating an API for subexpressions is in our backlog but it is quite a bit of work. The main problem is that the output does not always correspond to the internal MathML structure (since it's not always possible).

However, if you want to hack into MathJax's internals, you can force MathJax to expose more structure -- that's how ChromeVox does it thanks to Davide's help. I'll try to find some notes from our conversations back then (or you could look into the ChromeVox code).

In the mean time, the next release will pass more attributes from the source MathML to the output (see this issue). Perhaps that helps with your use case? If not, let us know what you're working with (and it would generally help to know what kind of project your working on, on- or off- list)

Best regards,
Peter.


--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages