0

Is there a way to create a new command with 9 arguments ({a_{11}},{a_{12}},{a_{13}},{a_{21}},{a_{22}},{a_{23}},{a_{31}},{a_{32}},{a_{33}}) that has as output a matrix with the Sarrus Rule? For instance: to obtain enter image description here

just use the command that we will call sarrus: \sarrus{-k}{k-1}{1}{0}{k-1}{k}{2}{0}{1}.

If it is possible i want to use the command sarrus in math mode just like matrix for istance.

greyshade
  • 3,576
Andrea Leo
  • 1,011

1 Answers1

2

Here is a possibility, based on pstricks and xparse. The values in the matrix are given as a list of 9 elements, separated by a comma:

\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} 

enter image description here

Bernard
  • 271,350
  • Hi @Bernard this is the solution I need but it doesn't work because of auto-pst-pdf also in a new tex document. – Andrea Leo Oct 13 '16 at 18:29
  • To compile pstricks code with pdflatex, you have to launch pdflatex with the --enable-write18 switch if you're under MiKTeX, shell-escape for TeX Live or MacTeX. You also can compile with xelatex. – Bernard Oct 13 '16 at 18:46
  • Wait I think we can find a better solution with tikzpicture together! I have this: \begin{tikzpicture} \matrix (a) [matrix of math nodes,left delimiter=|,row sep=.5em,column sep=.5em]{ a_{11} & a_{12} & a_{13} & a_{11} & a_{12} \ a_{21} & a_{22} & a_{23} & a_{21} & a_{22} \ a_{31} & a_{32} & a_{33} & a_{31} & a_{32} \ }; \draw[red] (a-1-1) -- (a-3-3); \draw[red] (a-1-2) -- (a-3-4); \draw[red] (a-1-3) -- (a-3-5);

    \draw[blue] (a-1-3) -- (a-3-1); \draw[blue] (a-1-4) -- (a-3-2); \draw[blue] (a-1-5) -- (a-3-3);
    \end{tikzpicture}

    – Andrea Leo Oct 13 '16 at 19:10
  • Now.. I need two more things from this.. add another ' delimiter ' between the 3 and the 4 column... and then automate all of it with a 9-arguments command. Can you help? – Andrea Leo Oct 13 '16 at 19:13
  • I'll try to see , but I don't know well tikz. The main advantage with the pstricks solution is that you start from an ordinary array environment, and just add some pstricks code to draw lines. – Bernard Oct 13 '16 at 19:59