Multi line equations with center alignment of terms

740 views
Skip to first unread message

keit...@gmail.com

unread,
Jun 23, 2013, 10:01:36 AM6/23/13
to mathja...@googlegroups.com
Hi Peter, Davide and fellow MathJax users,
I have a problem with equation alignment. I'm trying to line up terms in an equation with each the terms in columns, but centered rather than left or right aligned. My problem and different attempts at solutions are given here:


I'd be very grateful for any pointers. 

Thanks and best regards,
Keith

Frédéric WANG

unread,
Jun 25, 2013, 6:45:05 AM6/25/13
to mathja...@googlegroups.com
Hi Keith,

For the last method, you may first try to write the = and + sign in
their own cell:

\begin{array}{c @{{}={}} c c @{{}+{}} c c}
\cdot & & \uparrow & \uparrow & & \downarrow & \uparrow \\
\beta_V & = & \frac{D}{V} & \beta_D & + & \frac{D}{E} & \beta_E \\
\end{array}

Note that you can reduce the space by modifying the "columnspacing"
value in the MathML source. This corresponds e.g. to the fifth parameter
of Array:
https://github.com/mathjax/MathJax/blob/master/unpacked/jax/input/TeX/jax.js#L1738

The definition of 'Array' and other similar environments can be found here:
https://github.com/mathjax/MathJax/blob/master/unpacked/jax/input/TeX/jax.js#L987
https://github.com/mathjax/MathJax/blob/master/unpacked/extensions/TeX/AMSmath.js#L118

You might want to try another LaTeX environment with smaller column
spacing or add your own definition to
MathJax.Input.TeX.Definitions.environment. See
http://docs.mathjax.org/en/latest/signals.html#creating-a-listener (I
think there is a typo, it should be ""TeX Jax Ready " without space at
the end)

Hope that helps,
> --
> 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.
>
>


--
Fr�d�ric Wang
maths-informatique-jeux.com/blog/frederic

keit...@gmail.com

unread,
Jun 25, 2013, 11:04:16 AM6/25/13
to mathja...@googlegroups.com
Hi Fred,
Thank you very much for the links and code. 
I'll try to adjust the alignment using those tips.
Have a fantastic week.
Best regards,
Keith

Peter Krautzberger

unread,
Jun 25, 2013, 12:43:48 PM6/25/13
to mathja...@googlegroups.com

William F Hammond

unread,
Jun 25, 2013, 3:57:12 PM6/25/13
to mathja...@googlegroups.com
Previously:

>  \begin{array}{c @{{}={}} c c @{{}+{}} c c}

In the case of the given example I don't understand why this should be different from 7 simple c-cells.  It looks identical to me in firefox and chrome.

          -- Bill


keit...@gmail.com

unread,
Jun 27, 2013, 4:40:45 AM6/27/13
to mathja...@googlegroups.com
Dear William,
Thank you for your pointer, your method gives much cleaner code with the same result:
\[\begin{array}{c c c c c c c}
\cdot     & & \uparrow    & \uparrow & & \downarrow & \uparrow \\
\beta_V &=& \frac{D}{V} & \beta_D  &+& \frac{D}{E} & \beta_E \\
\end{array}\]
I've updated the example here: http://jsfiddle.net/keithphw/9EH8X/9/

Dear Frederic,
I have studied your advice, thank you. So far as I understand you recommend 2 different ways to deal with my problem of reducing the space between columns in the 'array' environment which is used in the code above. 

Method 1: Make my own mathjax config file that over-rides the default column spacing of the array environment. I understand that this has the disadvantage that this small column spacing will be set for all array formulas whether I want that or not. Is there a way to change this? 
It is a pity that there is no way to use \setlength{\arraycolsep}{0pt} in MathJax as follows, which I believe works in most latex editors:
\[{\setlength{\arraycolsep}{0pt}
    \begin{array}{c c c c c c c}
    \cdot    & & \uparrow    & \uparrow & & \downarrow  & \uparrow \\
    \beta_V  &=& \frac{D}{V} & \beta_D  &+& \frac{D}{E} & \beta_E \\
    \end{array}
}\]

Method 2: Make my own custom environment such as 'array_custom_spacing' which defines a new column spacing. This has the disadvantage of making the latex code non-standard and not-portable, but doesn't have the problem of affecting uses of the array formula where the normal large column spacing is needed, such as in matrix equations.

To go about making my own config file to do method 1 or 2 above, what exactly should I do? I'm not sure if I should add my own extension file as an in-line config option or use a listener as you described above. Also, which file should i copy and amend to be the extension with the new array spacing? The following files seem like candidates: tex2jax.js, jax.js and default.js. 

Thanks very much for your help. Any brief pointers would be greatly appreciated. 
I am using MathJax and your ideas for an education website designed to help students learn finance and basic maths. Having arrows above and below terms in an equation is a very useful and succinct way to explain the answer to many questions, such as in the answer to this question: http://www.fightfinance.com/index.jsp?deal=98

Kind regards,
Keith

Frédéric WANG

unread,
Jun 27, 2013, 5:17:06 AM6/27/13
to mathja...@googlegroups.com
I was suggesting either to use another LaTeX environment appropriate for
column spacing if there is one (but I don't think so?) or to define you
own env (Method 2). I'm not sure you can do the latter with
configuration option, so you need a listener and to define your
environment. For example, if you are using the AMS extension:

<script type="text/x-mathjax-config">
MathJax.Hub.Register.StartupHook("TeX AMSmath Ready",function () {
MathJax.InputJax.TeX.Definitions.environment["myarray"] =
['AMSarray',null,true,true,'c',".2em"];
});
</script>
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
</head>
<body>
\begin{myarray}
\cdot & & \uparrow & \uparrow & & \downarrow & \uparrow \\
\beta_V & = & \frac{D}{V} & \beta_D & + & \frac{D}{E} & \beta_E
\end{myarray}
</body>

With a similar technique but more complicated it is probably possible to
modify the TeX input Jax to implement setlength{\arraycolsep}{0pt} so
that all the arrays will use the specified value. You'll need to
carefully read unpacked/jax/input/TeX/jax.js and
unpacked/extensions/TeX/AMSmath.js. If you try that I'd recommend to
write an extension and to share it on our contrib repository

@Thomas, Peter: I see two repositories but the "official" is empty...
what's the status? I think I suggested to give Thomas the commit access
to a github.com/mathjax repository at some point...
https://github.com/mathjax/MathJax-third-party-extensions
https://github.com/leathrum/mathjax-ext-contrib

keit...@gmail.com

unread,
Jun 27, 2013, 11:51:30 AM6/27/13
to mathja...@googlegroups.com
That's a fantastic solution, thank you Fred. 
Works just right. I didn't think it was possible to do such a thing without modifying an existing mathjax javascript file and re-compiling mathjax. Goes to show how well designed the library is.
I think it is beyond my abilities to create the setlength{\arraycolsep}{0pt} environment variable, but if you get time, I will definitely contribute $100 to the cause.
Thanks very much for your help.
Best regards,
Keith
ps: I've updated the jsfiddle example code for those who want to see Fred's solution in action:
Reply all
Reply to author
Forward
0 new messages