# How to put 2x2 matrices in the denominator and numerator using MathJax?

Answer(s) to Reciprocal vectors of a two dimensional lattice without borrowing from the third dimension suggest a way forward in figuring out how to divide 2x2 matrices in a straightforward way.

In order to ask a further question on that I'd like to construct a faction like this in MathJax.

and I see the notation used for example in Table 1 of Multi-oriented moiré superstructures of graphene on Ir(111): experimental observations and theoretical models (viewable also: 1, 2) a screen shot is shown below.

Question: If I wanted to generate [[A, B], [C, D]] / [[E, F], [G, H]] as a MathJax fraction with a 2x2 matrix on the top and bottom like these, how would I do it?

note: I don't want to hack the augmented matrix feature, it would be nice if I could use these as real MathJax \frac{}{}tions and perhaps add additional terms.

I also understand that math allows work-arounds where I wouldn't have to write it like this, for example

$$\frac{\mathbf{M_1}+1}{\mathbf{M_2}}$$

but here I'm asking how to do it the hard way, thanks!

  | A  B |
|      |                 | A  B |
| C  D |                 |      |  /
----------     - OR -     | C  D | /
| E  F |                         / | E  F |
|      |                        /  |      |
| G  H |                           | G  H |


and ideally:

  | A  B |
|      | + 1                 | A  B |
| C  D |                     |      | + 1 /
--------------     - OR -     | C  D |    /
| E  F |                              / | E  F |
|      |                             /  |      |
| G  H |                                | G  H |


\frac{\left[\begin{array}{cc}A&B\\C&D\end{array}\right]+1}{\left[\begin{array}{cc}E&F\\G&H\end{array}\right]} $$\frac{\left[\begin{array}{cc}A&B\\C&D\end{array}\right]+1}{\left[\begin{array}{cc}E&F\\G&H\end{array}\right]}$$

Anything you can create in MathJax (as far as I know) you can put into a fraction using

\frac{Top}{Bottom}.

• my first attempt failed but since I rarely use matrices in MathJax perhaps I simply did it wrong. Thanks for the speedy and definitive answer! I'll try to do those slanted fractions as homework.
– uhoh
Oct 13, 2020 at 23:31
• @uhoh You're welcome. Oct 13, 2020 at 23:32
• I seems that there is no easy way. This answer to Slanted fractions in MathJax provides a hack, but if I want to pursue it I'll have to see if there's a way to make the slash bigger. $$\stackrel{{\left[\begin{array}{cc}A&B\\C&D\end{array}\right]+1}}{}\!\!\unicode{x2215}_{\!\unicode{x202f}{\left[\begin{array}{cc}E&F\\G&H\end{array}\right]}}$$ yields $$\stackrel{{\left[\begin{array}{cc}A&B\\C&D\end{array}\right]+1}}{}\!\!\unicode{x2215}_{\!\unicode{x202f}{\left[\begin{array}{cc}E&F\\G&H\end{array}\right]}}$$
– uhoh
Oct 14, 2020 at 0:13
• also this 2013 tweet (I didn't know there was such a thing as a 2013 tweet!) twitter.com/mathjax/status/320203899220942849?lang=en
– uhoh
Oct 14, 2020 at 0:15
• @uhoh Twitter launched in 2006 so you can find earlier :) Oct 14, 2020 at 4:55
• @postmortes time flies when we're not paying attention!
– uhoh
Oct 14, 2020 at 4:56

Using the pmatrix environment (or bmatrix for square braces, but I find the round braces more aesthetically pleasing), the expression with a vinculum may be typeset with the code

$$\frac{% \begin{matrix}% A & B \\% C & D% \end{pmatrix} + 1% }{% \begin{pmatrix} D & E \\ F & G \end{pmatrix}% }.$$


This is rendered as

$$\frac{% \begin{pmatrix}% A & B \\% C & D% \end{pmatrix} + 1% }{% \begin{pmatrix} E & F \\ G & H \end{pmatrix}% }.$$

Alternatively, the backslash is understood as a delimiter, which can be made large using the \left, \middle, and \right commands. In the style of the screenshot at the end of the question, I might use the code

$$\left.% \left[ \begin{pmatrix}% A & B \\% C & D% \end{pmatrix} + 1 \right]% \middle/% \begin{pmatrix}% E & F \\% G & H% \end{pmatrix} \right..$$


This is rendered as

$$\left.% \left[ \begin{pmatrix}% A & B \\% C & D% \end{pmatrix} + 1 \right]% \middle/% \begin{pmatrix}% E & F \\% G & H% \end{pmatrix} \right..$$

Finally, if you want to make things a little smaller and adjust the vertical alignment a bit, I suppose that you could make the numerator a superscript and the denominator a subscript. To do this, use the code

$$\left.% ^{% \left[ \begin{pmatrix}% A & B \\% C & D% \end{pmatrix} + 1 \right]% }% \!\!\middle/\!\!% _{% \begin{pmatrix}% E & F \\% G & H% \end{pmatrix}.% }% \right.$$


Personally, I think that this is rather ugly, but it renders as

$$\left.% ^{% \left[ \begin{pmatrix}% A & B \\% C & D% \end{pmatrix} + 1 \right]% }% \!\!\middle/\!\!% _{% \begin{pmatrix}% E & F \\% G & H% \end{pmatrix}.% }% \right.$$

All of that having been said, one presumes that $$1/M$$ is meant to denote the inverse of $$M$$, presuming that $$M$$ is invertible. My preference would be to write

$$\begin{pmatrix} A&B\\C&D \end{pmatrix}\begin{pmatrix} E&F\\G&H\end{pmatrix}^{-1}.$$

• Wow excellent. Yes I agree that that slanted one currently looks terrible and I promise to avoid that. It is wonderful to have so many different and better options to choose from, thank you!
– uhoh
Oct 14, 2020 at 0:55
• According to the first link in my question, should there be a transpose after the inverse in that last expression? I'm out of my depth here, but that's how I plan to implement it. Or does that just depend on how one defines division in a given context?
– uhoh
Oct 14, 2020 at 5:02
• I was only trying to demonstrate how to create a fraction with matrices in the numerator and denominator. You can typeset the trace operator with \operatorname{\tr}: $\operatorname{tr}$. Based on what is written in the question I would think that $(/\operatorname{tr}N)^{-1}$ would be correct (i.e. use extra parentheses).
– Xander Henderson Mod
Oct 14, 2020 at 11:52

As in Xander's answer, / can be used as a delimiter like ()[]|, by which I mean its adjusted by the commands \left, \right, \middle, and also \big, \Big, \bigg, and \Bigg.

For instance, $A/B\big/C\Big/D\bigg/E\Bigg/$ gives $$A/B\big/C\Big/D\bigg/E\Bigg/$$.

PS the slash slanting the other way can be achieved with $\Bigg\backslash$$$\Bigg\backslash$$.

Another way to create a slanted line is with the cancel package. Unfortunately it needs something to cancel; so I've used \phantom to make an invisible $$2\times 3$$ matrix to cancel, then the sub/superscript idea of Xander and some negative \hspace to achieve: $$\require{cancel}M= {}^{\displaystyle \begin{pmatrix}% A & B \\% C & D% \end{pmatrix} + 1 % }% \hspace{-3.5em}\cancel{\phantom{\begin{pmatrix}% A & B & C \\% C & D & C% \end{pmatrix}}}% _{% \displaystyle \hspace{-3em} \begin{pmatrix}% E & F \\% G & H% \end{pmatrix}.% }%$$ Definitely hacky but it seems fine in the three MathJax renderers I tried (SVG, common HTML, and HTML-CSS). Code below-

$$\require{cancel} M= {}^{\displaystyle \begin{pmatrix}% A & B \\% C & D% \end{pmatrix} + 1 % }% \hspace{-3.5em}\cancel{\phantom{\begin{pmatrix}% . & . & . \\% . & . & .% \end{pmatrix}}}% _{% \displaystyle \hspace{-3em} \begin{pmatrix}% E & F \\% G & H% \end{pmatrix}.% }%$$

• Wow/Yikes! If this creativity keeps up I'm going to vote to close and ask for this question to be migrated to Code Golf ;-) Seriously though this is very educational. Thank you!
– uhoh
Oct 14, 2020 at 4:50
• @uhoh If the goal of your question is to ask about MathJax for display on MathSE, then here is fine. On the other hand, if you goal is to typeset other documents, you might consider asking this kind of question on TeX - LaTeX. In particular, they are likely to do a better job of telling you what kinds of things to avoid.
– Xander Henderson Mod
Oct 14, 2020 at 11:56
• @XanderHenderson i believe uhoh was joking about the migration...? :) Oct 14, 2020 at 12:16
• @XanderHenderson I indeed plan to ask one or more question in the main site here about division of 2x2 matrices and answers here help me to compose them. That first bit was meant as ascii levity and to express surprise at how flexible MathJax can be.
– uhoh
Oct 14, 2020 at 15:08