# double-underline notation for matrices and single-underline notation for vectors [duplicate]

This is a fairly nice solution to double-underlines for matrices and single-underline for vectors:

\def\mat#1{\underline{\underline{#1}}}

\def\v#1{\underline{#1}}

However, it doesn’t work well when you have multiple matrices or vectors in a row, since it underlines them all continuously:

\mat{X}\mat{X}\mat{Y}

\v{X}\v{X}\v{Y}

How do I get the above kluge to treat the matrix/vector elements as separate?

I understand that potentially may have to use different solutions/macros instead of the basic \underline.

• Do you really want to use a very old-fashioned notation? Jun 27 at 19:49
• Is there no easy solution other than going to double-overline (which, I also do not know if it has an easy/clean solution either).
– puf
Jun 27 at 19:56
• @egreg: don't you get a sense of deja vu? :-) The duplicate I found started with you asking basically the same question in the comment and then providing an answer... Jun 27 at 20:18
• Thanks to both :) I am using google keywords of vectors and matrices; I did not find that answer using these keywords :(
– puf
Jun 27 at 20:28

I still think that underlining is evil and really old-fashioned notation.

Anyway, here's a working solution.

\documentclass{article}
\usepackage{amsmath}

\makeatletter
% overline
\newcommand{\dbloverline}[1]{\overline{\dbl@overline{#1}}}
\newcommand{\dbl@overline}[1]{\mathpalette\dbl@@overline{#1}}
\newcommand{\dbl@@overline}[2]{%
\begingroup
\sbox\z@{$\m@th#1\overline{#2}$}%
\box\z@
\ifx#1\scriptstyle\kern-\scriptspace\else
\ifx#1\scriptscriptstyle\kern-\scriptspace\fi\fi
\endgroup
}
% underline
\newcommand{\dblunderline}[1]{\@@underline{\dbl@underline{#1}}}
\newcommand{\dbl@underline}[1]{\mathpalette\dbl@@underline{#1}}
\newcommand{\dbl@@underline}[2]{%
\begingroup
\sbox\z@{$\m@th#1\@@underline{#2}$}%
\box\z@
\ifx#1\scriptstyle\kern-\scriptspace\else
\ifx#1\scriptscriptstyle\kern-\scriptspace\fi\fi
\endgroup
}
\fontdimen8
\ifx#1\displaystyle\textfont\else
\ifx#1\textstyle\textfont\else
\ifx#1\scriptstyle\scriptfont\else
\scriptscriptfont\fi\fi\fi 3
}
\makeatother

% vectors and matrices
\renewcommand{\vec}[1]{{%
\mspace{0.5mu}%
\underline{\mspace{-0.5mu}#1_{}\kern-\scriptspace\mspace{-0.5mu}}%
\mspace{0.5mu}%
\mathcorr{#1}%
}}
\newcommand{\mat}[1]{{%
\mspace{0.5mu}%
\dblunderline{\mspace{-0.5mu}#1_{}\kern-\scriptspace\mspace{-0.5mu}}%
\mspace{0.5mu}%
\mathcorr{#1}%
}}
\makeatletter
\newcommand{\mathcorr}[1]{\mathpalette\math@corr{#1}}
\newcommand{\math@corr}[2]{%
\begingroup
\sbox\z@{$\m@th#1#2$}\sbox2{$\m@th#1#2_{}\kern-\scriptspace$}%
\kern\dimexpr\wd\z@-\wd\tw@\relax
\endgroup
}
\makeatother

\begin{document}

\begin{gather*}
\mat{X}\mat{X}\mat{Y}^2
\\
\vec{X}\vec{X}\vec{f}
\\
F(\vec{v})
\\
3\vec{\mathrm{i}}+2\vec{\mathrm{j}}-\vec{\mathrm{k}}
\end{gather*}

\end{document}


The idea is to

1. remove the italic correction inserted after the letter
2. underline a smaller part of the letter
3. add the same space around
4. reinstate the italic correction
5. using a more compact version of double underlining

Bits of code from

https://tex.stackexchange.com/a/452094/4427

https://tex.stackexchange.com/a/71065/4427

• Thanks so much @egreg ! I like the notation in handwriting, when it is hard to bold; in use in formal latex, perhaps it is not the most suitable / appropriate :)
– puf
Jun 27 at 20:29