[Tex/LaTex] A matrix with breaking line and matrix transformations

matricestransformation

folks!
Sorry if this question has already been asked and answered, but I googled so hard I just can't find the right answer.

I learned how to write a matrix with a breaking line, using the array:

\left[ \begin{array}{ccc;{2pt/2pt}c} 1 & 2 & 3 & -2 \\
 0 & 5 & 10 & -5 \\
 3 & 4 & 5 & 0 
 \end{array} \right]

The result is this:

enter image description here

Now, I would like to write down the matrix transformations on this type of matrix. By searching some of the answered questions on this website, I found that the best solution would be this:

\begin{gmatrix}[b]
1 & 2 & \BAR & 3 \\
4 & 5 & \BAR & 6 \\
7 & 8 & \BAR & 9
\rowops
 \swap{0}{1}
 \mult{0}{\cdot 7}
 \add[5]{1}{2}
\end{gmatrix}

To make this work, it is necessary to add \usepackage{gauss} as well as

\newcommand{\BAR}{%
  \hspace{-\arraycolsep}%
  \strut\vrule 
  \hspace{-\arraycolsep}%
}

The outcome depends on the enviroment that I am using. If I write down the matrix by using $$ $$, I get the full line, while it breaks within \begin{align*} \end{align*}. In respective order, the outcomes are

enter image description here

My goal is to keep matrix transformations, but instead of complete vertical line to have a broken line, just like in the first matrix of this post. Is that possible by keeping the commands from gauss package? If not, what is the best and the simplest solution to this?

Bonus question, if I happen to need it (or in case all of this is impossible to make): how to keep a vertical line in one piece by using \begin{align*} \end{align*}? Do I really need to change the environment for these matrices (I need it to write matrices in more than one line and having lines aligned the way I want)?

Thank you so much in advance! I truly hope someone has a simple answer to this.

Best Answer

The gmatrix environment uses low level table making functions, which are affected by the current baseline skip, which is increased in align.

An easy modification of https://tex.stackexchange.com/a/337481/4427 solves the problem. See the answer for more options to xgmatrix.

\documentclass{article}
\usepackage{amsmath}
\usepackage{gauss}
\usepackage{xparse}

\newcommand{\BAR}{%
  \hspace{-\arraycolsep}%
  \strut\vrule 
  \hspace{-\arraycolsep}%
}

\ExplSyntaxOn
\keys_define:nn { gauss }
 {
  type .tl_set:N = \l_gauss_type_tl,
  type .initial:n = {},
  right .code:n = \tl_set:cn { g@post } { \relax$ },
  right .value_forbidden:n = true,
  spread .tl_set:N = \l_gauss_spread_tl,
  spread .initial:n = 1,
  colsep .dim_set:N = \l_gauss_colsep_dim,
  colsep .initial:n = \arraycolsep,
 }
\NewDocumentEnvironment{xgmatrix}{O{}}
 {
  \keys_set:nn { gauss } { #1 }
  \normalbaselines % <-----------  ADDED
  \linespread{\l_gauss_spread_tl}\selectfont
  \setlength{\arraycolsep}{\l_gauss_colsep_dim}
  \begin{gmatrix}[\l_gauss_type_tl]
 }
 {
  \end{gmatrix}
 }
\ExplSyntaxOff


\begin{document}

\[
\begin{gmatrix}[b]
1 & 2 & \BAR & 3 \\
4 & 5 & \BAR & 6 \\
7 & 8 & \BAR & 9
\rowops
 \swap{0}{1}
 \mult{0}{\cdot 7}
 \add[5]{1}{2}
\end{gmatrix}
\]

\begin{align*}
\begin{gmatrix}[b]
1 & 2 & \BAR & 3 \\
4 & 5 & \BAR & 6 \\
7 & 8 & \BAR & 9
\rowops
 \swap{0}{1}
 \mult{0}{\cdot 7}
 \add[5]{1}{2}
\end{gmatrix}
\end{align*}

\begin{align*}
\begin{xgmatrix}[type=b]
1 & 2 & \BAR & 3 \\
4 & 5 & \BAR & 6 \\
7 & 8 & \BAR & 9
\rowops
 \swap{0}{1}
 \mult{0}{\cdot 7}
 \add[5]{1}{2}
\end{xgmatrix}
\end{align*}

\end{document}

enter image description here