答案1
基于pstricks
和,存在一种可能性xparse
。矩阵中的值以 9 个元素的列表形式给出,以逗号分隔:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{array, mathtools}
\usepackage{pst-node, auto-pst-pdf}
\usepackage{xparse}
\DeclareDocumentCommand\sarrus%
{>{ \SplitArgument{8}{,}} m }
{\sarrusaux #1}
\NewDocumentCommand\sarrusaux{mmmmmmmmm}{%
\begin{postscript}
\begin{array}{|*{3}{c}|cc}
\Rnode{a11}{#1} & \Rnode{a12}{#2} & \Rnode{a13}{#3} & \Rnode{b14}{#1} & \Rnode{b15}{#2}\\
\Rnode{a21}{#4} & \Rnode{a22}{#5} & \Rnode{a23}{#6} & \Rnode{b24}{#4} & \Rnode{b25}{#5} \\
\Rnode{a31}{#7} & \Rnode{a32}{#8} & \Rnode{a33}{#9} & \Rnode{b34}{#7} & \Rnode{b35}{#8}
\end{array}
\psset{linecolor=red, linewidth=0.3pt, nodesep=1pt}
\ncline{a11}{a33}\ncline{a12}{b34}\ncline{a13}{b35}
\psset{linecolor=blue}
\ncline{a31}{a13}\ncline{a32}{b14}\ncline{a33}{b15}
\end{postscript}
}%
\begin{document}
\[ \sarrus{-k, k-1 , 1 , 0 , k-1, k , 2 , 0 , 1} \]%
\end{document}