# Matrix within equation

I'd modify the `\env@matrix`

command, on which all the matrix constructions are built;

```
\documentclass{article}
\usepackage{amsmath,bm}
\usepackage{setspace}
\usepackage{lipsum} % just for this example
\makeatletter
\def\env@matrix{\hskip -\arraycolsep
\let\@ifnextchar\new@ifnextchar
\linespread{1}\selectfont
\renewcommand{\arraystretch}{1.2}%
\array{*\c@MaxMatrixCols c}}
\makeatother
\doublespacing
\begin{document}
\lipsum*[2]
\begin{equation}
\mathbf{H} =
-\bm{\mu} \cdot \mathbf{B} =
- \gamma B_o \mathbf{S}_z = -\frac{\gamma B_o\hbar}{2}
\begin{bmatrix} 1&0\\0&-1 \end{bmatrix}.
\end{equation}
\lipsum[3]
\end{document}
```

Try also without `\renewcommand{\arraystretch}{1.2}`

, that I added in order to space out a bit the rows, which seems better with `\doublespacing`

.

Actually, it's difficult to improve something using `\doublespacing`

, which destroys any attempt at good typography.

In what does this differ from Mico's and Herbert's methods?

Mico's workaround works only within `equation`

. Herbert's instead applies single spacing to *all* display environments, so also to `align`

, for instance, reducing the line spacing between aligned equations.
This might be desirable or not, it depends on you.

Note that `{\bf H}`

should not be used, preferring `\mathbf{H}`

. Also, you'll have noticed that `{\bf \mu}`

doesn't embolden the mu; use `\bm{\mu}`

and load the `bm`

package as in my code.

```
\documentclass{article}
\usepackage{amsmath}
\usepackage[nodisplayskipstretch]{setspace}
\doublespacing
\everydisplay\expandafter{\the\everydisplay\setstretch{1}}% return to singlespacing
\begin{document}
\begin{equation}
\mathbf{H} = -\mathbf\mu \cdot \mathbf{B} = -\gamma B_o \mathbf{S}_z = -\frac{\gamma B_o\hbar}{2}
\begin{bmatrix} 1&0\\0&-1 \end{bmatrix}.
\end{equation}
\end{document}
```

You could use the `etoolbox`

package and use its `\AtBeginEnvironment`

command to reset spacing to `\singlespacing`

at the start of an `equation`

environment.

```
\documentclass{article}
\usepackage{amsmath}
\usepackage{setspace} % per the OP's information provided in a comment
\doublespacing
\usepackage{etoolbox}
\AtBeginEnvironment{equation}{\singlespacing}
\begin{document}
\begin{equation}
\mathbf{H} = -\boldsymbol{\mu} \cdot \mathbf{B} = - \gamma B_o \mathbf{S}_z = -\frac{\gamma B_o\hbar}{2}
\begin{bmatrix} 1&0\\0&-1 \end{bmatrix}.
\end{equation}
\end{document}
```

Remark: This method is quite simple if only the `equation`

environment has to be fixed; it becomes tedious quickly if lots of different display-math environments occur in your document.