This repository has been archived by the owner on Jan 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
domimatrix.sty
55 lines (45 loc) · 1.5 KB
/
domimatrix.sty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
\ProvidesPackage{domimatrix}
% Crossword package
% Copyright 2011 Benedict Harcourt
% License Pending
% Contact: ben.harcourt@harcourtprogramming.co.uk
\usepackage{etoolbox}
\usepackage{etextools}
% Write the letter c the number of times specified
% I suspect there's a better way to do this...
\newcommand{\dmmakecolumn}[1]{\ifnumequal{#1}{0}{}{c\dmmakecolumn{#1-1}}}
% Prints out a cell separator and a cell value
%
% Value after separator to stop a trailing line break which will cause
% the matrix to have an extra row. This means that there is a special
% case (cellcount == 0) for the first cell, where no separator is used.
\newcommand{\dmmakecell}[1]
{
\ifnumequal{\value{dmcellcount}}{0}{
\setcounter{dmcellcount}{1}
}{
\ifnumequal{\value{dmcellcount}}{\value{dmwidth}}
{ \\ \setcounter{dmcellcount}{1}}
{ & \addtocounter{dmcellcount}{1} }
}
#1
}
\newcounter{dmwidth} % Cells per line
\newcounter{dmcellcount} % Cells printed in current line
\newcommand{\dmstretch}{1}
\newcommand{\domimatrix}[2]{
\ensuremath{
\left(
\renewcommand{\arraystretch}{\dmstretch}
\begin{array}{\dmmakecolumn{#1}}
\setcounter{dmwidth}{#1}
\setcounter{dmcellcount}{0}
\csvloop[\dmmakecell]{#2} % Free CSV parsing from etextools :)
\end{array}
\right)
}
}
\newcommand{\bra}[1]{\ensuremath{\left\langle#1\right|}}
\newcommand{\ket}[1]{\ensuremath{\left|#1\right\rangle}}
\newcommand{\inprod}[2]{\ensuremath{\left\langle#1|#2\right\rangle}}
\newcommand{\tuple}[1]{\ensuremath{\left\langle#1\right\rangle}}