Skip to content

Instantly share code, notes, and snippets.

@Bryce-MW
Last active November 10, 2020 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bryce-MW/e178846526d75d66fea141bbb7b4b812 to your computer and use it in GitHub Desktop.
Save Bryce-MW/e178846526d75d66fea141bbb7b4b812 to your computer and use it in GitHub Desktop.
LaTeX list processing example
\documentclass{standalone}
\usepackage{xparse}
\usepackage{ifthen}
\newcommand\SepCount{0}
\newcommand\s{\renewcommand\SepCount{0}}
\NewDocumentCommand\ApplySep{m}{\ifthenelse{\SepCount=1}{&}{}#1\renewcommand\SepCount{1}}
\NewDocumentCommand\x
{
s
>{\SplitList{,}}o
>{\SplitList{,}}o
>{\SplitList{,}}o
>{\SplitList{,}}o
>{\SplitList{,}}o
>{\SplitList{,}}o
>{\SplitList{,}}o
>{\SplitList{,}}o
}{
\expandafter\begin{\IfBooleanTF{#1}{pmatrix}{bmatrix}}
\IfValueT{#2}{\s\ProcessList{#2}{\ApplySep}}
\IfValueT{#3}{\\\s\ProcessList{#3}{\ApplySep}}
\IfValueT{#4}{\\\s\ProcessList{#4}{\ApplySep}}
\IfValueT{#5}{\\\s\ProcessList{#5}{\ApplySep}}
\IfValueT{#6}{\\\s\ProcessList{#6}{\ApplySep}}
\IfValueT{#7}{\\\s\ProcessList{#7}{\ApplySep}}
\IfValueT{#8}{\\\s\ProcessList{#8}{\ApplySep}}
\IfValueT{#9}{\\\s\ProcessList{#9}{\ApplySep}}
\expandafter\end{\IfBooleanTF{#1}{pmatrix}{bmatrix}}
}
% This is how far I had gotten working on it myself. It does not work for even the first element of the list.
%\newcommand\MCount{0}
%\NewDocumentCommand\ProcessSingle{m}{\ifthenelse{\MCount=0}{#1}{}\renewcommand\MCount{1}}
%\NewDocumentCommand\mxm
%{
% s
% >{\SplitList{*}}o
% >{\SplitList{*}}o
% >{\SplitList{*}}o
% >{\SplitList{*}}o
% >{\SplitList{*}}o
% >{\SplitList{*}}o
% >{\SplitList{*}}o
% >{\SplitList{*}}o
%}{
% %\message{Two: #2}
% %\message{Res: \ProcessList{#2}{\ProcessSingle}\renewcommand\MCount{0}}
% \expandafter\csname\IfBooleanTF{#1}{x}{x*}\endcsname
% \IfValueT{#2}{\ProcessList{#2}{\ProcessSingle}\renewcommand\MCount{0}}
% \IfValueT{#3}{\ProcessList{#3}{\ProcessSingle}\renewcommand\MCount{0}}
% \IfValueT{#4}{\ProcessList{#4}{\ProcessSingle}\renewcommand\MCount{0}}
% \IfValueT{#5}{\ProcessList{#5}{\ProcessSingle}\renewcommand\MCount{0}}
% \IfValueT{#6}{\ProcessList{#6}{\ProcessSingle}\renewcommand\MCount{0}}
% \IfValueT{#7}{\ProcessList{#7}{\ProcessSingle}\renewcommand\MCount{0}}
% \IfValueT{#8}{\ProcessList{#8}{\ProcessSingle}\renewcommand\MCount{0}}
% \IfValueT{#9}{\ProcessList{#9}{\ProcessSingle}\renewcommand\MCount{0}}
%}
\begin{document}
$$\x[3,2]
[1,1]
\x[-3, 0]
[ 0,-2]
\x[ 1,-2]
[-1, 3]$$
$$\mxm[ [3,2]*[-3, 0]*[ 1,-2] ]
[ [1,1]*[ 0,-2]*[-1, 3] ]$$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment