[Tex/LaTex] Scaling \ddots in smallmatrix

math-modemathtoolsmatrices

I'm trying visualize a very large matrix. To do so, I'm trying to use \vdots and \ddots in a bsmallmatrix enviroment. It works but they do not scale properly as \cdots do.
Now, in the minimal reproducible example below, I have found a fix here which works, but only the vertical dots and not the diagonal dots.
I do not understand why it does not work for \ddots.

\documentclass{article}

\usepackage{mathtools}
\newcommand{\svdots}{\raisebox{3pt}{\scalebox{.75}{\vdots}}} % <- Works
\newcommand{\sddots}{\raisebox{3pt}{\scalebox{.75}{\ddots}}} % <- Do not work

\begin{document}

\begin{equation*}
  \begin{bsmallmatrix}
    a_{11}  & a_{12}  & \cdots  & a_{1m}  \\
    a_{21}  & a_{22}  & \cdots  & a_{2m}  \\
    \svdots & \svdots & \sddots & \svdots \\
    a_{n1}  & a_{n2}  & \cdots  & a_{nm}
  \end{bsmallmatrix}
\end{equation*}

\end{document}

The compilation errors revolves around missing $ and brackets.
The document complies fine when substituting \sddots for \ddots but, obviously, the ddots have the wrong size.

How do I best accomplish my desired result?

Best Answer

The following example redefines \vdots and \ddots to get a resizable version according to the current math style. The vertical space between the dots is taken from the horizontal dots. Also the dots in \ddots match the vertical spacing of \vdots and the horizontal spacing of the horizontal dots in \cdots. \cdots adds a thin space at the right side. For a better alignment in matrices, the redefined \ddots also adds this space.

The space above \vdots and \ddots is not fixed, the space between the dots is used for the additional vertical space above the symbol. It's a tiny bit smaller in \textstyle and \displaystyle than the original symbols, but the resizing in \scriptstyle and \scriptscriptstyle is much better as the bsmallmatrix example shows.

The following example shows the bsmallmatrix with the resizable dots. Then a normal bmatrix follows to show the symbols in the normal larger style. Then the bmatrix follows with the original \vdots and \ddots, saved in \orgvdots and \orgddots.

At the end of the example, the bounding boxes for the symbols in the different math styles are shown, first the original symbols, then the redefined symbols.

\documentclass{article}

\usepackage{mathtools}

\usepackage{letltxmacro}
\LetLtxMacro\orgvdots\vdots
\LetLtxMacro\orgddots\ddots

\makeatletter
\DeclareRobustCommand\vdots{%
  \mathpalette\@vdots{}%
}
\newcommand*{\@vdots}[2]{%
  % #1: math style
  % #2: unused
  \sbox0{$#1\cdotp\cdotp\cdotp\m@th$}%
  \sbox2{$#1.\m@th$}%
  \vbox{%
    \dimen@=\wd0 %
    \advance\dimen@ -3\ht2 %
    \kern.5\dimen@
    % remove side bearings
    \dimen@=\wd2 %
    \advance\dimen@ -\ht2 %
    \dimen2=\wd0 %
    \advance\dimen2 -\dimen@
    \vbox to \dimen2{%
      \offinterlineskip
      \copy2 \vfill\copy2 \vfill\copy2 %
    }%
  }%
}
\DeclareRobustCommand\ddots{%
  \mathinner{%
    \mathpalette\@ddots{}%
    \mkern\thinmuskip
  }%
}
\newcommand*{\@ddots}[2]{%
  % #1: math style
  % #2: unused
  \sbox0{$#1\cdotp\cdotp\cdotp\m@th$}%
  \sbox2{$#1.\m@th$}%
  \vbox{%
    \dimen@=\wd0 %
    \advance\dimen@ -3\ht2 %
    \kern.5\dimen@
    % remove side bearings
    \dimen@=\wd2 %
    \advance\dimen@ -\ht2 %
    \dimen2=\wd0 %
    \advance\dimen2 -\dimen@
    \vbox to \dimen2{%
      \offinterlineskip
      \hbox{$#1\mathpunct{.}\m@th$}%
      \vfill
      \hbox{$#1\mathpunct{\kern\wd2}\mathpunct{.}\m@th$}%
      \vfill
      \hbox{$#1\mathpunct{\kern\wd2}\mathpunct{\kern\wd2}\mathpunct{.}\m@th$}%
    }%
  }%
}
\makeatother

\begin{document}

\begin{gather*}
  \begin{bsmallmatrix}
    a_{11}  & a_{12}  & \cdots  & a_{1m}  \\
    a_{21}  & a_{22}  & \cdots  & a_{2m}  \\
    \vdots & \vdots & \ddots & \vdots \\
    a_{n1}  & a_{n2}  & \cdots  & a_{nm}
  \end{bsmallmatrix}
\\
  \begin{bmatrix}
    a_{11}  & a_{12}  & \cdots  & a_{1m}  \\
    a_{21}  & a_{22}  & \cdots  & a_{2m}  \\
    \vdots & \vdots & \ddots & \vdots \\
    a_{n1}  & a_{n2}  & \cdots  & a_{nm}
  \end{bmatrix}
\\
  \begin{bmatrix}
    a_{11}  & a_{12}  & \cdots  & a_{1m}  \\
    a_{21}  & a_{22}  & \cdots  & a_{2m}  \\
    \orgvdots & \orgvdots & \orgddots & \orgvdots \\
    a_{n1}  & a_{n2}  & \cdots  & a_{nm}
  \end{bmatrix}
\end{gather*}

\setlength{\fboxsep}{0pt}
\setlength{\fboxrule}{.1pt}

\newcommand*{\test}[1]{%
  \fbox{$#1\orgvdots$}%
  \fbox{$#1\orgddots$}%
  \fbox{$#1\vdots$}%
  \fbox{$#1\ddots$}%
  \fbox{$#1\dots$}%
  \fbox{$#1\cdots$}%
  \fbox{$#1\cdotp\cdotp\cdotp$}%
}
\begin{gather*}
  \test{}\\
  \test{\scriptstyle}\\
  \test{\scriptscriptstyle}
\end{gather*}
\end{document}

Result

Related Question