I would like to modify a command so that it doesn't need the ifthen package not necessarily because of this, Why is the ifthen package obsolete?, but just to used the funcationality in Tikz/PGF. The problem is nothing I've tried works. I thought \pgfmathifthenelse{}{}{} and \pgfmathequal{}{} would work but they doesn't. I get unknown control sequence errors. Am I missing something simple?
% !TEX TS-program = lualatexmk
% !TEX encoding = UTF-8 Unicode
\documentclass{article}
\RequirePackage{unicode-math}
\unimathsetup{math-style=ISO}
\setmathfont[Scale=MatchLowercase]{TeX Gyre DejaVu Math} % Good g everywhere. Based on
\setmathfont[Scale=MatchLowercase,range={\mathscr,\mathbfscr}]{XITS Math}
\setmathfont[Scale=MatchLowercase,range={\mathcal,\mathbfcal},StylisticSet=1]{XITS Math}
\setmathfont[Scale=MatchLowercase,range= it/{greek,Greek}]{Latin Modern Math}
\setmathfont[Scale=MatchLowercase,range= bfit/{greek,Greek}]{Latin Modern Math}
\setmathfont[Scale=MatchLowercase,range= up/{greek,Greek}]{Latin Modern Math}
\setmathfont[Scale=MatchLowercase,range= bfup/{greek,Greek}]{Latin Modern Math}
\setmathfont[Scale=MatchLowercase,range=bfsfup/{greek,Greek}]{Latin Modern Math}
\usepackage{tikz}
\usepackage{xstring} % needed for \StrCount
\usepackage{ifthen}
\ExplSyntaxOn
\NewDocumentCommand{\reverselist}{ m m }{%
\clist_clear_new:N #1
\clist_set:Nx #1 { \clist_reverse:n { #2 } }
}%
\ExplSyntaxOff
\NewDocumentCommand{\TensorMachine}{ m O{} O{} }{%
% For aesthetic reasons, we need to reverse the order of #1.
\reverselist{\revslots}{#1}
\begin{tikzpicture}[baseline]
\pgfmathsetmacro{\cubex}{4}
\pgfmathsetmacro{\cubey}{1}
\pgfmathsetmacro{\cubez}{3}
\pgfmathsetmacro{\slotwidth}{1}
% front
\draw[fill=white,thick,line join=round] (0.5*\cubex,0.5*\cubey,0.5*\cubez) --
++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0,0) -- cycle
% label the machine
node at (-0.30*\cubex,0,0.5*\cubez) {\(\symbf{#2}\)}
node at (0.30*\cubex,0,0.5*\cubez) {\(\symbf{#3}\)};
% side
\draw[fill=white,thick,line join=round] (0.5*\cubex,0.5*\cubey,-0.5*\cubez) --
++(0,0,\cubez) -- ++(0,-\cubey,0) -- ++(0,0,-\cubez) -- cycle;
% top
\draw[fill=white,thick,line join=round] (0.5*\cubex,0.5*\cubey,-0.5*\cubez) --
++(-\cubex,0,0) -- ++(0,0,\cubez) -- ++(\cubex,0,0) -- cycle;
% output slot
\draw[fill=black,ultra thick] (-0.5*\slotwidth,0,0.5*\cubez) --
++(0,0.03,0) -- ++(\slotwidth,0,0) -- ++(0,-0.03,0) -- cycle;
%\fill (0,0,0) circle (2pt); % origin
\ifthenelse{\equal{#1}{}}%
{% We have a scalar. Fill the output slot and we're done.
\draw[fill=white,thin,-] (-0.5*\slotwidth+0.1,0,0.5*\cubez)
-- ++(-0.25,-\slotwidth,0) -- ++(\slotwidth-0.2,0,0)
-- ++(0.25,\slotwidth,0)
node at (-0.125*\slotwidth,-0.5*\cubey,0.5*\cubez) {\(\symbb{R}\)};
}%
{% We have slots, which may be filled or unfilled.
% Set some values.
\StrCount{#1,}{,}[\numslots]
\StrCount{#1}{+}[\numfilledslots]
\pgfmathsetmacro{\startvslotx}{-0.25*\cubex-0.5*\slotwidth}
\pgfmathsetmacro{\startoslotx}{+0.25*\cubex-0.5*\slotwidth}
\pgfmathsetmacro{\sloty}{0.5*\cubey}
\pgfmathsetmacro{\totalnumslots}{\numslots}
\pgfmathsetmacro{\slotspace}{\cubez / (\totalnumslots + 1)}
\pgfmathsetmacro{\islotspaceindex}{1}
% Loop through the reversed list of slots.
\foreach \currentslot in \revslots {%
%\node at (4,0,0) {\currentslot}; % debug
\IfBeginWith{\currentslot}{v}%
{% Draw a vector slot.
\draw[fill=black,ultra thick]
(\startvslotx,\sloty,-0.5*\cubez+\islotspaceindex*\slotspace)
-- ++(0,0,0.04) -- ++(\slotwidth,0,0) -- ++(0,0,-0.04) -- cycle;
% Test to see if we need to fill the slot.
\IfEndWith{\currentslot}{+}%
{% Fill the slot.
\draw[fill=white,thin]
(\startvslotx+0.1,\sloty,-0.5*\cubez+\islotspaceindex*\slotspace)
-- ++(0,\slotwidth,0) -- ++(\slotwidth-0.2,0,0) -- ++(0,-\slotwidth,0);
}%
{% Leave it empty.
}%
}%
{% Draw a 1-form slot.
\draw[fill=black,ultra thick]
(\startoslotx,\sloty,-0.5*\cubez+\islotspaceindex*\slotspace)
-- ++(0,0,0.04) -- ++(\slotwidth,0,0)-- ++(0,0,-0.04) -- cycle;
% Test to see if we need to fill the slot.
\IfEndWith{\currentslot}{+}%
{% Fill the slot.
\draw[fill=lightgray,thin]
(\startoslotx+0.1,\sloty,-0.5*\cubez+\islotspaceindex*\slotspace)
-- ++(0,\slotwidth,0) -- ++(\slotwidth-0.2,0,0) -- ++(0,-\slotwidth,0);
}%
{% Leave it empty.
}%
}%
\pgfmathparse{\islotspaceindex+1}
\xdef\islotspaceindex{\pgfmathresult}
}%
% Test to see if we need to fill the output slot.
\ifthenelse{\equal{\numslots}{\numfilledslots}}%
{% Fill the output slot.
\draw[fill=white,thin,-] (-0.5*\slotwidth+0.1,0,0.5*\cubez)
-- ++(-0.25,-\slotwidth,0) -- ++(\slotwidth-0.2,0,0)
-- ++(0.25,\slotwidth,0)
node at (-0.125*\slotwidth,-0.5*\cubey,0.5*\cubez) {\(\symbb{R}\)};
}%
{% Leave it empty.
}%
}%
\end{tikzpicture}
}%
\begin{document}
[
\TensorMachine{v,o}[T][e]
]
%[
%\TensorMachine{o+,v+}[T][e']
%]
%[
%\TensorMachine{o+,o+,v+}[T]
%]
%[
%\TensorMachine{}[\phi]
%]
\end{document}
The output:


\TensorMachine{}[T][e]then it works and I get a different result. :D Like a piece of paper coming out of the box with the mathRon it. – Alenanno Nov 07 '20 at 23:24TensorMachine{v+,o+}[T][e]and see what happens. – LaTeXereXeTaL Nov 07 '20 at 23:31ifthenpackage. I don't know how to make the drawing code more compact. – LaTeXereXeTaL Nov 07 '20 at 23:33