html link in align* environment

122 views
Skip to first unread message

David Farmer

unread,
Nov 1, 2011, 10:33:59 PM11/1/11
to MathJax Users
I am using align* to present a multiline proof, and I put the
"reason" for each step
in the right column.

When the "reason" is plain text, everything works fine. But when I
try to
make the reason be an html link, MathJax will not even typeset the
equations.

This works:

\begin{align*}
(RS)^{-1} C (RS)&=S^{-1}{R^{-1} C R}{S}&&\text{theorem SS}\\
&=S^{-1}{\left(R^{-1} C R\right)}{S}&&\text{theorem MMA}\\
&=S^{-1} B S&&\text{definition SIM}\\
&=A
\end{align*}

and this doesn't:

\begin{align*}
(RS)^{-1} C (RS)&=S^{-1}{R^{-1} C R}{S}&&\text{theorem SS}\\
&=S^{-1}{\left(R^{-1} C R\right)}{S}&&\text{theorem MMA}\\
&=S^{-1} B S&&\text{<a href="definitionSIM.html">definition SIM</a>}\\
&=A
\end{align*}

(and this second example only appears as raw LaTeX in the browser)

Also, if I delete the \text{} wrapper around the html link in the
second
example, again I only see the LaTeX source in the browser.

Is there any way to put such a link in an aligned equation?

Regards,

David

David Farmer

unread,
Nov 1, 2011, 10:41:06 PM11/1/11
to MathJax Users
I should have mentioned that what I really want is "knowl=" in the
<a> tag,
not "href=". That is why I didn't use \href.

See

http://www.aimath.org/knowlepedia/

for information about knowls, which I hope makes it clear why I want
to
insert the html, and have CSS govern how it appears.

Regards,

David

Davide P. Cervone

unread,
Nov 2, 2011, 5:24:30 PM11/2/11
to mathja...@googlegroups.com
The tex2jax preprocessor will only locate mathematics when it is
completely textual; that is, it cannot be broken up by HTML tags
(other than <br>). The embedded anchor tag will prevent the tex2jax
processor from finding a closing \end{align*} for the \begin{align*},
since the math is not allowed to cross element boundaries. That is
why your second example shows as text rather than typeset math.

Since the mathematics is converted to MathML internally, it can't
include arbitrary HTML like this, since there is no mechanism for
including HTML for display within MathML. Since the mathematics could
be displayed as MathML (for those who have the MathML output jax
specified), everything that the TeX input jax produces must be able to
be rendered as MathML.

I was going to recommend that you use

\href{definitionSIM.html}{\text{definition SIM}}

instead, but your next message indicated why you didn't do that.

Because MathML has a means of including hypertext references (via the
href attribute on any MathML element), the \href macro can be
implemented in MathJax. But then "knowl" anchor is non-standard and
there is no corresponding mechanism in MathML, so MathJax will not be
able to produce it.

While it would be possible, I suppose, to have MathJax add a non-
standard "knowl" attribute to its internal MathML elements, but even
it these were copied to the output MathML or HTML-CSS elements, I
don't think that would work with your knowl.js implementation, for
several reasons. I don't use jQuery, so I'm not up on all its
details, but it looks like the knowl's are located and modified when
the page first becomes ready. Since MathJax doesn't typeset the
contents until after that, even if the knowls were inserted, they
would not get modified by the knowls script and so would not operate
properly. Second, the knowl code assumes that the anchor is within a
<div> or a <p> (and only does a special case for a table), but you are
asking that the anchor be part of some very complicated output
generated by MathJax. So even if the knowl was active, it would try
to insert its text into the middle of the equation, which would
probably cause havoc with the layout (both in HTML-CSS and NativeMML
output).

The upshot is, I don't think you are going to get this to work as you
would like. I still have more to do in terms of being able to add
customized interactivity to the mathematics, I'm afraid.

Davide

PS, I know you have asked me privately to look at the knowl approach,
and I haven't forgotten about that; I just haven't gotten to it yet.

David Farmer

unread,
Nov 2, 2011, 8:33:40 PM11/2/11
to MathJax Users
Having those links as knowls will be very useful, so I will stay
hopeful
that a solution will eventually be found.

I don't think the placement of the anchor within the equation should
cause so much difficulty. The knowl should appear after the equation,
as a new paragraph. So there is no need to modify the equation which
was already displayed. (And any new math in the knowl is rendered by
MathJax before being displayed.)

The knowl.js code may need to be modified to put the content of
the knowl in the appropriate place. This just makes use of the tree
structure of the web page, moving up the appropriate amount and
then adding a new node

Regards,

David

leathrum

unread,
Nov 3, 2011, 3:35:00 PM11/3/11
to MathJax Users
I don't think it would be a particularly good idea to include code for
knowls in the MathJax libraries. It can probably be done with a bit
of extra JavaScript to define a new command for MathJax (I don't think
\newcommand could handle this, but I may be wrong about that) similar
to the \href command, so something like "\knowl{definitionSIM.html}
{\text{definition SIM}}". You might need to switch over to the
Development group to find someone interested in doing this. I can't
picture it being too terribly difficult, if you use the code for \href
as a model. It would require some familiarity with the source and
API, though.

Davide P. Cervone

unread,
Nov 5, 2011, 3:01:41 PM11/5/11
to mathja...@googlegroups.com
You will not be able to model this on \href, since what \href does is
apply the an href attribute to the internal MathML element that the
\href applies to. Since MathML understands href, this is no problem
(and the HTML-CSS output jax knows how to convert that to an anchor in
its output). You could certainly make a \knowl that attaches a knowl
atribute to the internal MathML, but because knowl is not a valid
MathML attribute, MathJax will not know what to do with it, and it
will not be passed on to the NativeMML output or to the HTML-CSS
output. That would require changes to those output jax, not just a
new TeX macro. That is a bit more challenging.

And this doesn't address the problem that the knowl.js code currently
runs before MathJax produces its output, and so the code that attaches
the event handles for knowls will have already run by the time any
knowls produced by MathJax show up. So knowl.js would also need
modification, and synchronization with MathJax. There is also the
modifications needed to locate the correct place for the knowl to
appear so that it is not inside the mathematical equation itself,
which requires a knowledge of the results of MathJax's HTML-CSS output
jax. Those changes are certainly possible, but it is not a trivial
job, and there are a number of issues that have to be carefully handled.

Davide

leathrum

unread,
Nov 17, 2011, 10:56:24 PM11/17/11
to MathJax Users
Something about Davide's answer on this one kept bugging me, so I
decided to try a few experiments, and I have met with substantial
success. Don't get me wrong, I don't have a complete solution yet,
but I think I have a feasibility proof. Here is the URL for my test:

http://cs.jsu.edu/~leathrum/knowl/knowl-test.html

You can view page source to see what I did -- it's all in the one
file, using the online versions of knowl.js, knowlstyle.css, jquery,
and MathJax.js. This implements a \knowl macro which gives everything
about the knowl interface *except* the unique-ID mechanism in
knowl.js. That is admittedly a pretty big gap -- without it, you can
only use the \knowl macro once. I'm still working on fixing that.

leathrum

unread,
Nov 18, 2011, 1:44:48 PM11/18/11
to MathJax Users
OK, I got the unique-ID mechanism working. This part did require
writing a MathJax extension, just to manage the counter which
guarantees uniqueness. (Davide: any hope of implementing
\newcounter, \value, etc., in MathJax2? Would've made this a lot
easier...) Anyway, demo page at same URL:

http://cs.jsu.edu/~leathrum/knowl/knowl-test.html

The MathJax extension is the only part that isn't in the HTML page.
It implements macros \advance (to increment the counter), \uid (to
assign a unique ID to the element based on the counter), \jsurl (to
turn the URL into a JavaScript call that sets up and displays the
knowl -- this was actually the key to the whole mechanism, hard part
was working out how to get the unique ID number from the MathJax
extension into the jquery-based knowl display method), and \value (to
display the value of the counter in the TeX -- I used this mostly for
debugging). It was not difficult overall, and if anyone is
interested, I will post the extension source.

leathrum

unread,
Nov 18, 2011, 6:19:05 PM11/18/11
to MathJax Users
In HTML-CSS rendering mode, the knowl is not showing the dotted
underline when inside a MathJax expression -- this seems to be because
the HTML-CSS mode is pretty aggressive with clipping rectangles, and
the dotted underline (which is actually a dotted bottom border) is
being deleted. Other styling is working fine, though.

Davide P. Cervone

unread,
Nov 18, 2011, 7:41:02 PM11/18/11
to mathja...@googlegroups.com
> Something about Davide's answer on this one kept bugging me, so I
> decided to try a few experiments, and I have met with substantial
> success. Don't get me wrong, I don't have a complete solution yet,
> but I think I have a feasibility proof. Here is the URL for my test:
>
> http://cs.jsu.edu/~leathrum/knowl/knowl-test.html

That is a clever approach, and I would not have thought of using the
javascript URL (though it seems obvious now that you have done it).
Kudos.

> any hope of implementing \newcounter, \value, etc., in MathJax2?
> Would've made this a lot easier...

No, I do not expect to implement those control sequences. You are
actually working much harder than necessary here, because you are
thinking in TeX rather than Javascript. I have attached my own
version of an extension that implements your approach, but doesn't
require all the extra macros. It also puts it into the MathJax object
so that it doesn't pollute the global namespace, and doesn't rely on
the HTML.js extension being loaded (GetArgumentMML is part of that
extension, so your code relies on that; fortunately it gets loaded
automatically by \class and \cssID, but the timing of their use is
crucial to making your code work). My code also handles setting up
the styles automatically, and signaling that the knowl extension is
loaded.

Not all CSS styling can be effectively applied to MathJax output. In
particular, borders and padding need to be handled carefully.
Currently, they only work if they are applied explicitly via a style
attribute of the underlying MathML (and even that is not currently in
the v1.1 code, if I remember properly, so only works properly in
v2.0). My code uses this approach to do the underline dots. Note,
however, that this might not look all that great on some mathematics
(e.g., fractions, for example). The hover background change will have
problems with some math as well, as the HTML bounding boxes are not
the same as the TeX bounding boxes. For example, fractions will not
have their backgrounds cover the whole fraction (only a line-sized
part around the fraction line). There is no easy work around for this
at the moment.

Anyway, if you want to try out this file, you will need to put it
someplace where you can load it, and then change the loadComplete()
line at the bottom so that its URL is the one where the file is loaded
from, and then use "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML,url
" to load MathJax (where "url" is replaced by the URL of the location
of this file).

I have put a copy of Tom's sample file (but using my modifications) at

http://devel.mathjax.org/mathjax/dpvc/test/knowl/knowl.html

for you to try out. This uses the CDN version of MathJax (so the
underlining isn't performed). There is a copy at

http://devel.mathjax.org/mathjax/dpvc/test/knowl/knowl2.html

that uses the v2.0-candidate, so the underline is performed. That is
the only change in the file.

Davide


knowl.js.zip

leathrum

unread,
Nov 18, 2011, 8:30:15 PM11/18/11
to MathJax Users
> That is a clever approach, and I would not have thought of using the
> javascript URL (though it seems obvious now that you have done it).
> Kudos.

It seemed a pretty obvious approach to me, once I accepted that MathML
elements wouldn't support onclick attributes.

> > any hope of implementing \newcounter, \value, etc., in MathJax2?
> > Would've made this a lot easier...
>
> No, I do not expect to implement those control sequences.

Not surprised, thought I should ask though.

> You are
> actually working much harder than necessary here, because you are
> thinking in TeX rather than Javascript.

Fair enough. My first attempt (the one that didn't have the unique-ID
mechanism yet) was purely a TeX macro, just chaining together \href,
\class, and \cssId. The \href used a javascript: URL to call the
showKnowl() method, basically the same idea as what I used in my final
version. I thought the business of getting the counter value out to
the showKnowl() method was a kludge, but it worked.

> I have attached my own
> version of an extension that implements your approach, but doesn't
> require all the extra macros.  It also puts it into the MathJax object
> so that it doesn't pollute the global namespace, and doesn't rely on
> the HTML.js extension being loaded (GetArgumentMML is part of that
> extension, so your code relies on that; fortunately it gets loaded
> automatically by \class and \cssID, but the timing of their use is
> crucial to making your code work).  My code also handles setting up
> the styles automatically, and signaling that the knowl extension is
> loaded.

Yay! My "feasibility proof" had exactly the desired effect -- getting
the discussion started again and getting a real solution. I wasn't
sure how to translate some of the jquery tricks into calls in the
MathJax API, though, so I did the best I could with calling back to
the jquery showKnowl() method.

> Not all CSS styling can be effectively applied to MathJax output.
[...]
> There is no easy work around for this
> at the moment.

I did the best I could, working with the CDN version. I thought it
was workable, if not perfect. I see what you are doing in the code to
spruce up the styles. I wasn't aware you could do that sort of thing
inside an extension -- it opens up a host of possibilities (says the
man at the keyboard, grinning evilly).

> I have put a copy of Tom's sample file (but using my modifications) at

Very nice output, and certainly an improvement on my work.

I still don't think (as I said earlier in the thread) that this should
be included in the main MathJax distro. The other thing I think I
have demonstrated here is the viability of third-party extensions.
The extensions don't have to be in the [MathJax]/extensions/TeX/
folder, you can fetch them in the config using a full URL. Maybe I
can put together a third-party extension implementing \newcounter,
etc., now that I am more familiar with the innards of the API.

Are there any plans for some sort of repository of third-party
extensions?

Davide P. Cervone

unread,
Nov 18, 2011, 9:24:42 PM11/18/11
to mathja...@googlegroups.com
>> That is a clever approach, and I would not have thought of using the
>> javascript URL (though it seems obvious now that you have done it).
>> Kudos.
>
> It seemed a pretty obvious approach to me, once I accepted that MathML
> elements wouldn't support onclick attributes.

I think MathML element DO support it; only there is no mechanism in
the HTML-CSS output to attach them. So it is theoretically possible,
but not yet implemented.

>> You are
>> actually working much harder than necessary here, because you are
>> thinking in TeX rather than Javascript.
>
> Fair enough. My first attempt (the one that didn't have the unique-ID
> mechanism yet) was purely a TeX macro, just chaining together \href,
> \class, and \cssId. The \href used a javascript: URL to call the
> showKnowl() method, basically the same idea as what I used in my final
> version. I thought the business of getting the counter value out to
> the showKnowl() method was a kludge, but it worked.

Indeed, I didn't mean to be dismissive. Only to point out that there
was a simpler way to accomplish your goal than to implement a lot of
new control sequences.

>> I have attached my own version of an extension ...


>
> Yay! My "feasibility proof" had exactly the desired effect -- getting
> the discussion started again and getting a real solution.

Glad you got what you wanted. :-)

It was the javascript URL that sparked my interest again.

>> Not all CSS styling can be effectively applied to MathJax output.
> [...]
>> There is no easy work around for this
>> at the moment.
>
> I did the best I could, working with the CDN version.

This was not meant as criticism, but just information.

> I see what you are doing in the code to
> spruce up the styles. I wasn't aware you could do that sort of thing
> inside an extension -- it opens up a host of possibilities (says the
> man at the keyboard, grinning evilly).

There are some severe limitations to the number of stylesheets that IE
will allow (only 32 total) and currently MathJax does not try to
conserve these, so there is a real chance of overflowing the IE limit
if there are too many stylesheets added in this way. But it does
work well in most browsers. It is on my list of improvements to use
only one stylesheet and simply add rules to it rather than make new
ones each time (as is currently done). But there have been more
pressing matters.

>> I have put a copy of Tom's sample file (but using my modifications)
>> at
>
> Very nice output, and certainly an improvement on my work.
>
> I still don't think (as I said earlier in the thread) that this should
> be included in the main MathJax distro.

I agree with you, and don't plan to include it (since it relies on
jQuery and the knowl library, which are not part of MathJax). But it
is good that it can be loaded separately as an extension (or
configuration file).

> The other thing I think I
> have demonstrated here is the viability of third-party extensions.

Sure, there is no reason that you can't make your own and host your
own extensions. This is a nice example of that, as you say.

> Maybe I can put together a third-party extension implementing
> \newcounter,
> etc., now that I am more familiar with the innards of the API.

No reason why you can't. MathJax 2.0 includes some features that
allow localized macro definitions (in its new begingroup extension),
so you might want to tie into that if you are doing counters and such,
since it would be nice to be able to have localized counters.

> Are there any plans for some sort of repository of third-party
> extensions?

We have kicked around the idea, but haven't got anything in place. It
is one of those things that tends not to get done until there is
something to put into it. So perhaps yours can be the ones that get
that project moving. It is also something that could be taken on by
the user community rather than through MathJax directly. We have our
plate pretty full at the moment, and this is something that would be
of real benefit that someone in the community could foster.

Anyway, keep up the good work.

Davide

Davide P. Cervone

unread,
Nov 18, 2011, 10:29:19 PM11/18/11
to mathja...@googlegroups.com
My knowl.js file had a missing "var" which makes one of the variables
global. You should change

id = KNOWL.GetID();

to

var id = KNOWL.GetID();

Sorry about that.

Davide

leathrum

unread,
Nov 19, 2011, 12:57:40 PM11/19/11
to MathJax Users
> >> That is a clever approach, and I would not have thought of using the
> >> javascript URL (though it seems obvious now that you have done it).
> >> Kudos.
>
> > It seemed a pretty obvious approach to me, once I accepted that MathML
> > elements wouldn't support onclick attributes.
>
> I think MathML element DO support it; only there is no mechanism in
> the HTML-CSS output to attach them.  So it is theoretically possible,
> but not yet implemented.

Implementation in MathJax is one thing, but I checked some of the
relevant specs on this point when I started thinking about how to
proceed, and I'm not convinced that MathML elements would necessarily
support event attributes, even in an HTML5 context. The MathML spec
doesn't mention event attributes at all (as well it shouldn't, they
would be quite beside the point for that spec), so it comes down to
how MathML embeds in HTML5. The HTML5 spec says that all HTML5
elements should support all event attributes (except of course for the
attributes that are specific to particular elements, like onload), but
in the section about embedding MathML in HTML5, it scrupulously says
that MathML is outside the HTML5 namespace. This is open to some
interpretation, so different browsers may do different things here,
but I read this as saying in particular that the event attributes need
not be supported by the MathML elements. (David Carlisle may have a
different take on this, but this is how I read it.) For cross-browser
implementations, I usually figure that it is best to stick with
conservative interpretations of the specs, so I wouldn't want to rely
on being able to use onclick in a math element.

> > Are there any plans for some sort of repository of third-party
> > extensions?
>
> We have kicked around the idea, but haven't got anything in place.

[...]


> this is something that would be
> of real benefit that someone in the community could foster.

After I get a counters extension working, I'll slap a basic repository
together on my server and put the counters extension and this knowls
extension onto it as seeds, then post something to this group about
it. Don't expect me to use a fancy subversioning server, though.

Davide P. Cervone

unread,
Nov 19, 2011, 3:37:37 PM11/19/11
to mathja...@googlegroups.com
>>> It seemed a pretty obvious approach to me, once I accepted that
>>> MathML
>>> elements wouldn't support onclick attributes.
>>
>> I think MathML element DO support it; only there is no mechanism in
>> the HTML-CSS output to attach them. So it is theoretically possible,
>> but not yet implemented.
>
> Implementation in MathJax is one thing, but I checked some of the
> relevant specs on this point when I started thinking about how to
> proceed, and I'm not convinced that MathML elements would necessarily
> support event attributes, even in an HTML5 context.
> ...

> conservative interpretations of the specs, so I wouldn't want to rely
> on being able to use onclick in a math element.

What you say is certainly true, there is no guarantee that onclick
will be supported. I did a little checking, though, and found that
Firefox, Safari, and Opera all support onclick events (when they are
added dynamically to the MathML elements via JavaScript). Only
MathPlayer seems to be a hold out in this respect. MathPlayer does
allow onclick on the root <math> element, but not on individual
elements within the math. Unfortunately, it doesn't support any of
the mechanisms for canceling the event or preventing its default
action, so clicks always produce the MathPlayer zoom box, even when
there is an onclick handler that tries to cancel the event. (This is
one of the reasons I had to use an overlay to trap mouse events for
MathPlayer in MathJax.) This testing was in MathPlayer2.2. Not sure
what differences there might be with MathPlayer3.

>>> Are there any plans for some sort of repository of third-party
>>> extensions?
>>
>> We have kicked around the idea, but haven't got anything in place.
> [...]
>> this is something that would be
>> of real benefit that someone in the community could foster.
>
> After I get a counters extension working, I'll slap a basic repository
> together on my server and put the counters extension and this knowls
> extension onto it as seeds, then post something to this group about
> it. Don't expect me to use a fancy subversioning server, though.

I wasn't actually meaning that YOU needed to do it, though I
appreciate your volunteering.

Davide

rabe...@gmail.com

unread,
Aug 20, 2013, 3:48:23 PM8/20/13
to mathja...@googlegroups.com
Dear Tom, Davide and David,

Thanks very much for implementing this!  I'm relying heavily on it in my online linear algebra text.  To see it in action,

(a) http://linear.pugetsound.edu/html/fcla.html

(b) Left Sidebar, Eigenvalues chapter, Eigenvalues and Eigenvectors section

(c) Search for "Theorem EMRCP" (or scroll down about 2/3 way down)

(d) Hit "Proof" knowl to see an align* environment in the proof

Rob

Davide P. Cervone

unread,
Aug 21, 2013, 3:39:30 PM8/21/13
to mathja...@googlegroups.com, rabe...@gmail.com
Thanks, Rob, this looks very cool.  Good work!

Davide


--
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/groups/opt_out.

Peter Krautzberger

unread,
Aug 21, 2013, 11:01:15 AM8/21/13
to mathja...@googlegroups.com
Thanks for sharing this, Rob -- the book keeps getting better!

Peter.


Reply all
Reply to author
Forward
0 new messages