Left align selected equations in MathJax

2,430 views
Skip to first unread message

michaelq...@gmail.com

unread,
May 7, 2015, 2:41:41 AM5/7/15
to mathja...@googlegroups.com
Hi there, I am trying to find a way to left align only certain equations in MathJax.  I tried posting this on stack overflow but have had no responses.  This is basically what I posted:

So, by default MathJax equations are centered, but I want to left align certain equations. I know how to make ALL equations left aligned with MathJax.Hub.Config, but this is not what I want.

I've tried other code found on the web, such as the following:

<script type="text/javascript">
  MathJax.Hub.Queue(function () {
      MathJax.Hub.Config({displayAlign:"left"});
      MathJax.Hub.Typeset(["leqn"]);
    });
 </script>

then wrapped a div around the equation with an id of leqn, like so:

<div id="leqn">$$e^{\pi i} - 1 = 0$$</div>

This does not work and I don't know enough about MathJax or even JS to have any idea as to what I'm doing wrong. Any ideas?

Peter Krautzberger

unread,
May 7, 2015, 7:14:05 AM5/7/15
to mathja...@googlegroups.com

Hi,

As mentioned in the User Group guidelines, please mark double-posts to avoid duplicated efforts.

I've posted an answer at http://stackoverflow.com/questions/30077862/how-to-left-align-certain-equations-in-mathjax/.

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.

Murray

unread,
May 8, 2015, 4:40:21 AM5/8/15
to mathja...@googlegroups.com
Hi Peter

Actually, Michael did flag this Google Groups post as a duplicate.

Just a comment - it seems to me both Davide's and your suggested approaches are somewhat sledgehammer-like. Apart from the extra coding, there is a processing hit due to adding and removing classes, and/or waiting for one processing run before doing the special case.

The specific left-aligned equation has 4 appearances and 3 jumps:

Appearance 1: Un-processed LaTeX in among the other snippets.

Appearance 2: Un-processed LaTeX on the left, as the surrounding two get processed

Appearance 3: Processed math, centered

Appearance 4: Processed math, left aligned.

In the example you posted in StackOverflow, why not just do this?

$$e^{\pi i} - 1 = 0$$
\( e^{\pi i} - 1 = 0 \)

$$e
^{\pi i} - 1 = 0$$


The second equation is left aligned all along, and there is less flicker.

The following would be even better, to reduce one of the jumps:

$$e^{\pi i} - 1 = 0$$
<p>\( e^{\pi i} - 1 = 0 \)</p>

$$e
^{\pi i} - 1 = 0$$


The only time I can imagine wanting to left-align a "display" equation is if it involved upper and lower limits, e.g. on a sum, and we wanted the symbol to be large.

In which case, this would do it:

$$e^{\pi i} - 1 = 0$$

<p>\( \displaystyle{\sum_{n=1}^{10}{\frac{1}{n}}=1+\frac{1}{2}+\frac{1}{3}+\dots}\)</p>


$$e
^{\pi i} - 1 = 0$$

Just my 2c.

Regards
Murray

Peter Krautzberger

unread,
May 8, 2015, 5:18:45 AM5/8/15
to mathja...@googlegroups.com

Ah, very sorry about that, Michael!

Thanks for correcting me, Murray.

Yes, using displaystyle and styling a surrounding element is of course another alternative. As I wrote on SO it depends on the use case. E.g., whether you can control the TeX content or just the html.

Again, sorry for missing the SO mention earlier.

Best,
Peter.

Davide P. Cervone

unread,
May 8, 2015, 7:39:15 AM5/8/15
to mathja...@googlegroups.com
Murry,

Your appearance 3 is due to the "Fast preview" feature, which doesn't respect the displayAlign setting.  Turning off fast preview would eliminate that.  I'm not sure I'd call 1 to 2 a jump for the left-aligned equation, as it hasn't moved (the OTHER equations have).  

I've through of several other approaches since then.  For example, a TeX input jax post-filter that adds indentalign="left" based on the class of the parent element, or defining a tex macro that allows you to control the indentalign setting that you can include in the TeX code itself.

Either of these would also prevent the multi-pass processing that you object to.

Davide

Michael Quinlivan

unread,
May 8, 2015, 7:57:18 AM5/8/15
to mathja...@googlegroups.com
Thanks Murray, that works as well, and much simpler!

I'm new to this, and still don't completely understand TeX syntax, and what the \( and \displaystyle bits do, but I'm slowly getting there.

I must say though, I'm loving MathJax!  It's been some time since trying math on the web, and I remember it being so painful that I gave up.  This makes it so simple. Keep up the good work!

--
You received this message because you are subscribed to a topic in the Google Groups "MathJax Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mathjax-users/Y3SEX4-P9XI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mathjax-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages