-
Notifications
You must be signed in to change notification settings - Fork 231
Multi line equations with center alignment of terms
From https://groups.google.com/d/msg/mathjax-users/wIhEPFHaI9g/FRI3ikyaDZMJ
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:
http://jsfiddle.net/keithphw/9EH8X/6/
I'd be very grateful for any pointers.
Thanks and best regards, Keith
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, Fred.
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
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
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> \begin{myarray} \cdot & & \uparrow & \uparrow & & \downarrow & \uparrow \\
\beta_V & = & \frac{D}{V} & \beta_D & + & \frac{D}{E} & \beta_E
\end{myarray}
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
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: http://jsfiddle.net/keithphw/9EH8X/10/