mathjaxquarto# Align numbers with a minus sign in a matrix for a quarto document in html

I would like to align numbers with a minus sign in a matrix for a Quarto document in HTML format, similar to the following example:

```
$$\begin{bmatrix}
3 & 4 \\
-2 & 0 \\
1 & 2
\end{bmatrix}$$
```

One possible solution is to use `\phantom{-}`

:

```
$$\begin{bmatrix}
\phantom{-}3 & 4 \\
-2 & 0 \\
\phantom{-}1 & 2
\end{bmatrix}$$
```

However, when the matrix has many numbers, this is not very efficient. I am aware that in LaTeX, the `mathtools`

package can achieve the desired result:

```
\documentclass{article}
\usepackage{mathtools}
\begin{document}
\[
\begin{bmatrix*}[r]
3 & 4 \\
-2 & 0 \\
1 & 2
\end{bmatrix*}
\]
\end{document}
```

Is it possible to use the `mathtools`

LaTeX package in a Quarto HTML document? Alternatively, if not, are there other alternatives to `mathtools`

to consider, keeping in mind that Quarto uses MathJax to render equations?

Solution

I think you were close to solving your problem (assuming I have understood the issue at hand). Simply just use the right alignment on `bmatrix*`

and compile the qmd file. It should work even without loading `mathtools`

explicitly (at least working in my case and I am using quarto version `1.3.450`

)

```
---
title: "mathtools in html"
format: html
# include-in-header: load-mathtools.html
---
## Quarto
$$
\begin{bmatrix*}[r]
3 & 4 \\
-2 & 0 \\
1 & 2
\end{bmatrix*}
$$
```

And if for some other reason, you need the `mathtools`

extension, you need to explicitly load it.

**load-mathtools.html**

```
<script>
window.MathJax = {
loader: {load: ['[tex]/mathtools']},
tex: {packages: {'[+]': ['mathtools']}}
};
</script>
```

- Get error when MathJax 3.0.1 typeset fails
- Why has Text in MathJax html-css fractions different letter sizes in the same fraction part, and how to prevent it?
- Converting MathJax into pdf with wkhtmltopdf yields too small maths
- SVG Path incorrect size and position
- MathJax + Knockout.js Subscription
- Synthetic division: MathJax
- How to make MathJax faster?
- How to left align Mathjax elements
- HTML code with MathJax SVG does not work in XHTML
- Running Jemdoc on Windows
- How to have math expression in spoiler block in markdown
- Load MathJax on github page using jekyll without overwriting layout
- MathJax not rendering LaTeX in React with ReactMarkdown
- How to '\dotfill' at MathJaX
- gollum-wiki mathjax.config.js use "<math>" and "</math>" to delimit
- How to create multi-line equation blocks in GitHub?
- Retrieving input from MathML rendered using MathJax
- jupyter notebook takes forever to open and then pages unresponsive - [MathJax] issue
- How to configure R Markdown to use the "textmacros" MathJax extension for HTML rendering?
- Double brackets in MathJax
- Align numbers with a minus sign in a matrix for a quarto document in html
- How to make MathJax equation render properly in href?
- Adding colorful background to equation by acting directly on MathJax without CSS
- Can't get MathJax math font size to stay same size relative to surrounding text
- Using GitHub LaTeX Markdown to color header text with specific colors
- MathJax Rendering is not working properly in Android
- MathJax does not allow multi-row in-line math on GitHub Pages
- wkhtmltopdf and MathJax: equations are rendered too small
- How to change alignment of displayed equations in IPython Notebook?
- How to add spaces in mathjax table cell?