Everyone likes trailing commas! But trailing newlines in matrices seem to add an extra newline 😢
LaTeX source to test:
\documentclass{article}
\pagestyle{empty}
\usepackage{amsmath}
\begin{document}
\[
\begin{bmatrix}
a & b \\
c & d \\
\end{bmatrix}
\]
\end{document}
LaTeX output:

KaTeX output:
