%% to be compiled with pdflatex

\documentclass{amsart}

%%%%%%%%

%%%%% Shows a projection of the 1-skeleton of the 4-dimensional
%%%%% cubical associahedron (an oriented graph).  There are 42
%%%%% vertices and 84 edges.

%%%%% The 28 edges parallel to the 4th basis vector are drawn in
%%%%% green.  The others form two opposite embeddings of the
%%%%% 3-dimensional associahedron and three 2-cells (two pentagons and
%%%%% one quadrilateral).

%%%%% The black (as opposed to blue) arrow heads depict for each point
%%%%% the "canonical directed path" (Mac Lane, Saunders.  Natural
%%%%% associativity and commutativity.  Rice Univ. Stud. 49 (1963),
%%%%% no. 4, 28-46, MR 170925. p.34) to the base point (here denoted
%%%%% by A0).

%%%%% A variant is labeled with parenthetical expressions.

%%%%% Another variant shows the Tamari indices as in the diagrams up
%%%%% to dimension 3 in Tamari's thesis (see Stasheff, Jim.  How I
%%%%% 'met' Dov Tamari.  Associahedra, Tamari lattices and related
%%%%% structures, 45-63. Progr. Math., 299, 2012, MR 3221533. p.46).

%%%%% There is also a less cluttered variant with no arrows.

%%%%% Further, there is the first version with a different geometry
%%%%% (with 1x1x2 cubes and a 1:1:2 subdivision on them).  From a
%%%%% graphical point of view, I like it more than the newer "shoe
%%%%% box" version (with 1x2x3 cubes).  However the arrows and labels
%%%%% don't come out nicely without further twiddling.  The shoe box
%%%%% variant is more systematic anyway.

%%%%% Actually the very first complete drawing was the "skew" version.
%%%%% Here lines get evenly subdivided.  A grave mishap:  the two
%%%%% middle pentagons are not convex (and all three middle 2-cells
%%%%% are not plane in 4-space).  The fix is of course to subdivide
%%%%% coherently according to level as described in "The associahedral
%%%%% chain complex and the cubical associahedron" (assoc2.pdf).

%%%%%%%%

\newif\ifNAMES %
%% uncomment to show the internal names of the 42 vertices
%%% recommended if you read this file
% \NAMEStrue %

%%%%%%%%

\newif\ifPARENS %
%% uncomment to get paren expressions as labels
% \PARENStrue % no effect with \INDICEStrue

\newif\ifINDICES %
%% uncomment to get the variant with Tamari indices as labels
%%% all arrows are black
% \INDICEStrue % overrides \PARENStrue

\newif\ifCAPTION %
%% uncomment to add caption M_5 (meant for \INDICEStrue)
% \CAPTIONtrue %
\ifINDICES \CAPTIONtrue \fi %

\newif\ifSIMPLE %
%% uncomment to get the simple variants with no arrows
% \SIMPLEtrue %

\newif\ifREVERSE %
%% uncomment to reverse orientations
%%% all arrows are black
% \REVERSEtrue %

\newif\ifFIRST %
%% uncomment to get the first version
% \FIRSTtrue %
%% some arrows, lines, labels come too close
\ifFIRST \SIMPLEtrue \fi %

\newif\ifSKEW %
%% Warning: the skew version is eye-disturbing
% \SKEWtrue %
\ifSKEW \FIRSTtrue \SIMPLEtrue \fi %

%%%%%%%%

\usepackage{tikz}
\usetikzlibrary{calc,decorations.markings}

\ifCAPTION %
\DeclareFixedFont{\TMfontD}{OMS}{cmsy}{m}{n}{20.74} % \magstep4
\DeclareFixedFont{\TMfontDSubscript}{OT1}{cmtt}{m}{n}{14.40} % \magstep2
\fi %

\begin{document}
\thispagestyle{empty} %

\centerline{%

  %% default: [x={(1cm,0cm)}, y={(0cm,1cm)}, z={(-3.85mm,-3.85mm)}]
  \ifFIRST %
  \tikzpicture[x={(0cm,-4cm)},y={(-4cm,0cm)},z=-3.85mm*8]
  \else %
  \tikzpicture[x={(0cm,-2cm)},y={(-4cm,0cm)},z={(-3.85mm*6,-3.85mm*12)}]
  \fi %

  %%%% 14 vertices on lower cube (= M_4, the 3-dim associahedron)

  %% 5 points in back of lower cube (= M_3, the pentagon)
  \coordinate (A0) at (0,0,0) ; % origin (M_1)
  \coordinate (A1) at (1,0,0) ; % basis vector 1 (in M_2)
  \coordinate (A2) at (0,1,0) ; % basis vector 2
  \coordinate (A3) at ($(A1)+(A2)$) ; % (1,1,0)
  %% subdivision for M_3
  \coordinate (X0) at ($(A0)!1/2!(A2)$) ; % (0,1/2,0)

  %%%% remaining vertices of M_4

  %% 5 points in front of lower cube (= opposite M_3 in M_4)
  \coordinate (B0) at (0,0,1) ; % basis vector 3
  \coordinate (B1) at ($(A1)+(B0)$) ; % (1,0,1)
  \coordinate (B2) at ($(A2)+(B0)$) ; % (0,1,1)
  \coordinate (B3) at ($(A3)+(B0)$) ; % (1,1,1)
  \coordinate (X3) at ($(X0)+(B0)$) ; % (0,1/2,1)

  %% 4 inner subdivisions

  \ifFIRST %
  \def\StepA{1/4}
  \def\StepB{1/2}
  \else %
  \def\StepA{1/3}
  \def\StepB{2/3}
  \fi %

  %% \SKEWtrue subdivides evenly

  \ifSKEW \def\StepB{1/2} \fi %
  \coordinate (X2) at ($(X0)!\StepB!(X3)$) ; % (0,1/2,2/3)
  \ifSKEW \def\StepA{1/3} \def\StepB{2/3} \fi %
  \coordinate (Y1) at ($(A0)!\StepA!(B0)$) ; % (0,0,1/3)
  \coordinate (Y2) at ($(A0)!\StepB!(B0)$) ; % (0,0,2/3)
  \ifSKEW \def\StepA{1/2} \fi %
  \coordinate (Z1) at ($(A1)!\StepA!(B1)$) ; % (1,0,1/3)

  %%%% 14 vertices on upper cube (= opposite M_4 in M_5)

  \ifFIRST %
  \coordinate (A0d) at (-10/4,9.8/4,-3/8) ; % basis vector 4
  \else %
  %% stretch a bit to avoid too narrow pairs of points
  \coordinate (A0d) at ($1.1*(-2,3,-1)$) ; % basis vector 4
  \fi %

  \def\BottomVertices{A1,X0,A2,A3,Y1,Y2,B0,Z1,B1,X2,X3,B2,B3}
  \foreach \XXX in \BottomVertices { %
    \coordinate (\XXX d) at ($(\XXX)+(A0d)$) ; }
  \edef\BottomVertices{A0,\BottomVertices}

  %%%%%%%%

  %%%% make the xy-coordinates of the 4 basis vectors explicit

  %% \newdimen\cx %
  %% \newdimen\cy %
  %% \foreach \XXX in {%
  %%   A0,A1,A2,B0,A0d%
  %% }{ %
  %%   \pgfextractx{\cx}{\pgfpointanchor{\XXX}{center}} %
  %%   \pgfextracty{\cy}{\pgfpointanchor{\XXX}{center}} %
  %%   \typeout{\string\coordinate \space (\XXX) at (\the\cx,\the\cy) ; \csname@percentchar\endcsname} %
  %%   %%
  %% }

  %%%% geometry of the first version (with a 1x1x2 cuboid)
  %%%%%% \tikzpicture[x={(0cm,-4cm)},y={(-4cm,0cm)},z=-3.85mm*8]
  %%%%%% \coordinate (A0d) at (-10/4,9.8/4,-3/8) ; % basis vector 4
  %% \coordinate (A0) at (0.0pt,0.0pt) ; %
  %% \coordinate (A1) at (0.0pt,-113.81102pt) ; %
  %% \coordinate (A2) at (-113.81102pt,0.0pt) ; %
  %% \coordinate (B0) at (-87.63452pt,-87.63452pt) ; %
  %% \coordinate (A0d) at (-245.9737pt,317.39049pt) ; %

  %%%% geometry of the current version (with a 1x2x3 cuboid)
  %%%%%% \tikzpicture[x={(0cm,-2cm)},y={(-4cm,0cm)},z={(-3.85mm*6,-3.85mm*12)}]
  %%%%%% \coordinate (A0d) at ($1.1*(-2,3,-1)$) ; % basis vector 4
  %% \coordinate (A0) at (0.0pt,0.0pt) ; %
  %% \coordinate (A1) at (0.0pt,-56.9055pt) ; %
  %% \coordinate (A2) at (-113.81102pt,0.0pt) ; %
  %% \coordinate (B0) at (-65.72589pt,-131.45178pt) ; %
  %% \coordinate (A0d) at (-303.27956pt,269.79056pt) ; %

  %%%%%%%%

  %% placement in shipout is independent of labels, thickness of
  %% bullets
  \useasboundingbox (B3d) (A0d) (A0) (B3) ; %

  %%%%%%%%

  %% remaining 14 vertices of M_5 (4-dim associahedron)

  \def\StepA{1/4}
  \def\StepB{1/2}
  \def\StepC{3/4}

  %% \SKEWtrue subdivides the green lines evenly

  \coordinate (A0a) at ($(A0)!\StepA!(A0d)$) ; % red rail
  \coordinate (A0b) at ($(A0)!\StepB!(A0d)$) ; % red
  \coordinate (A0c) at ($(A0)!\StepC!(A0d)$) ; % red
  \ifSKEW \def\StepA{1/3} \def\StepB{2/3} \let\StepC\StepB \fi %
  \coordinate (A1a) at ($(A1)!\StepA!(A1d)$) ; % cyan rail
  \coordinate (A1b) at ($(A1)!\StepB!(A1d)$) ; % cyan
  \coordinate (X0a) at ($(X0)!\StepA!(X0d)$) ; % orange rail
  \coordinate (X0c) at ($(X0)!\StepC!(X0d)$) ; % orange
  \ifSKEW \let\StepB\StepA \fi %
  \coordinate (Y1b) at ($(Y1)!\StepB!(Y1d)$) ; % blue rail
  \coordinate (Y1c) at ($(Y1)!\StepC!(Y1d)$) ; % blue
  \ifSKEW \def\StepA{1/2} \let\StepB\StepA \let\StepC\StepA \fi %
  \coordinate (A2a) at ($(A2)!\StepA!(A2d)$) ; % darkgray rail 1
  \coordinate (A3a) at ($(A3)!\StepA!(A3d)$) ; % darkgray rail 2
  \coordinate (X2c) at ($(X2)!\StepC!(X2d)$) ; % darkgray rail 3
  \coordinate (Y2c) at ($(Y2)!\StepC!(Y2d)$) ; % darkgray rail 4
  \coordinate (Z1b) at ($(Z1)!\StepB!(Z1d)$) ; % darkgray rail 5

  %%%%%%%% draw the cubes

  %%%% https://tex.stackexchange.com/questions/28284/how-to-draw-a-cube-with-tikz-where-all-faces-have-a-distinct-color
  %%%% https://tex.stackexchange.com/a/28286

  %%%% using it without change

  \foreach \p in {,d}{ %

    \draw[blue,fill=yellow!80] (A1\p) -- (B1\p) -- (B3\p) -- (A3\p) -- cycle ; % Bottom Face
    \draw[blue,fill=blue!30] (A0\p) -- (A1\p) -- (A3\p) -- (A2\p) -- cycle ; % Back Face
    \draw[blue,fill=red!10] (A2\p) -- (B2\p) -- (B3\p) -- (A3\p) -- cycle ; % Left Face
    \draw[blue,fill=red!20,opacity=0.8] (A0\p) -- (B0\p) -- (B1\p) -- (A1\p) -- cycle ; % Right Face
    \draw[blue,fill=red!20,opacity=0.6] (B0\p) -- (B2\p) -- (B3\p) -- (B1\p) -- cycle ; % Front Face
    \draw[blue,fill=red!20,opacity=0.8] (A0\p) -- (A2\p) -- (B2\p) -- (B0\p) -- cycle ; % Top Face

    %% 3 subdivisions
    \draw (X0\p) -- (X3\p) ; %
    \draw (X2\p) -- (Y2\p) ; %
    \draw (Y1\p) -- (Z1\p) ; %

  } %

  %%%%%%%% 3 interesting 2-cells
  %%%%%% see the descriptions at the end of the file

  \scope[fill=gray,fill opacity=0.2,draw opacity=0.3]

  %%%% order matters! (a tiny bit)

  %% the middle pentagon near top (\StepC)
  \filldraw (A0c) -- (Y1c) -- (Y2c) -- (X2c) -- (X0c) -- cycle ; %
  %%% (Y1c) could be dropped unless \SKEWtrue

  %% the middle quadrilateral (\StepB)
  \filldraw (A0b) -- (Y1b) -- (Z1b) -- (A1b) -- cycle ; %

  %% the middle pentagon near bottom (\StepA)
  \filldraw (A0a) -- (X0a) -- (A2a) -- (A3a) -- (A1a) -- cycle ; %
  %%% (X0a) could be dropped unless \SKEWtrue

  \endscope

  %%%%%%%% 14 green lines

  \foreach \XXX in \BottomVertices { %
    \draw[green] (\XXX) -- (\XXX d) ; }

  %%%%%%%% Note:  arrows, bullets, labels are drawn on top of
  %%%%%%%% everything else.

  %%%%%%%% arrows

  \tikzset{
    midtip/.style={postaction={decorate,decoration= %
        {markings,mark=at position #1 with %
          {\arrow{stealth}} %
    }}}, %
    midtip/.default=1/2, %
  }

  %%%% black arrows (steps, canonical edges):
  %% 1x1 + 1x2+1x1 + 1x3+2x2+2x1 + 1x4+3x3+5x2+5x1 = 41 (of 84)
  %%%% (it is a tree with 42 vertices)

  \def\ARROWSA{%
    %%% from \VERTICES
    %% orientation is reversed
    A0/A1, % M_1 <-- M_2
    A0/X0,X0/A2, % M_2 <-- M_3
    A1/A3, %
    A0/Y1,Y1/Y2,Y2/B0, % M_3 <-- M_4
    A1/Z1,Z1/B1, %
    X0/X2,X2/X3, %
    A2/B2, %
    A3/B3, %
    A0/A0a,A0a/A0b,A0b/A0c,A0c/A0d, % M_4 <-- M_5
    A1/A1a,A1a/A1b,A1b/A1d, %
    X0/X0a,X0a/X0c,X0c/X0d, %
    Y1/Y1b,Y1b/Y1c,Y1c/Y1d, %
    A2/A2a,A2a/A2d, %
    A3/A3a,A3a/A3d, %
    Y2/Y2c,Y2c/Y2d, %
    Z1/Z1b,Z1b/Z1d, %
    X2/X2c,X2c/X2d, %
    B0/B0d, %
    B1/B1d, %
    X3/X3d, %
    B2/B2d, %
    B3/B3d%
  }

  %%%% 43 remaining arrows (blue)

  \def\ARROWSB{%
    %%%%
    %%%% 22 remaining arrows not on the upper cube
    %% from the list at the end of this file
    %%%%
    A3/A2, %
    Y1/Z1,X2/Y2,X3/B0,B2/X3,B1/B0,B3/B2,B3/B1, %
    A0a/A1a,A1a/A3a,A3a/A2a, %
    A0a/X0a,X0a/A2a, %
    Y1b/Z1b,Z1b/A1b, %
    Y1b/A0b,A0b/A1b, %
    X2c/Y2c,Y2c/Y1c,Y1c/A0c, %
    X2c/X0c,X0c/A0c, %
    %%%%
    %%%% all 21 arrows on the lower cube, collected from above
    %%%%
    %% A0/A1,A0/X0,A0/Y1, % -1
    %% A1/A3,A1/Z1,X0/A2,X0/X2,Y1/Y2,Y1/Z1, % -1
    %% A3/B3,Z1/B1,Y2/B0,X2/X3,A2/B2, % -1
    %% A3/A2,X2/Y2, % +1
    %% X3/B0,B2/X3,B1/B0,B3/B2,B3/B1, % +1
    %%%%
    %%%% Here are the corresponding oriented edges in the upper cube,
    %%%% see the text at the end of this file.  The sign indicates the
    %%%% orientation change.
    %%%%
    A1d/A0d,X0d/A0d,Y1d/A0d, % -1
    A3d/A1d,Z1d/A1d,A2d/X0d,X2d/X0d,Y2d/Y1d,Z1d/Y1d, % -1
    B3d/A3d,B1d/Z1d,B0d/Y2d,X3d/X2d,B2d/A2d, % -1
    A3d/A2d,X2d/Y2d, % +1
    X3d/B0d,B2d/X3d,B1d/B0d,B3d/B2d,B3d/B1d% +1
  }

  \ifSIMPLE\else %% no arrows

  \ifREVERSE %

  \foreach \XXX/\YYY in \ARROWSA { \path[midtip] (\XXX) -- (\YYY) ; } %
  \foreach \XXX/\YYY in \ARROWSB { \path[midtip] (\XXX) -- (\YYY) ; } %

  \else % \ifREVERSE

  \ifINDICES \def\BLUE{} \else \def\BLUE{blue} \fi %

  \foreach \XXX/\YYY in \ARROWSA { \path[midtip] (\YYY) -- (\XXX) ; } %
  \foreach \XXX/\YYY in \ARROWSB { \path[midtip,\BLUE] (\YYY) -- (\XXX) ; } %

  \fi % \ifREVERSE

  \fi % \ifSIMPLE

  %%%%%%%% bullets and labels

  %%%%%% color setup

  %% Don't use cyan and magenta in the same picture, for the sake of
  %% red-green color blind people!

  % mygray    % 808080 % gray(128)      % hsv(0,0,50)      % xcolor: gray, black!50
  % myblack   % 404040 % gray(64)       % hsv(0,0,25)      % xcolor: darkgray, black!75
  % myred     % FF0000 % rgb(255,0,0)   % hsv(0,100,100)   % xcolor: red
  % mygreen   % 00FF00 % rgb(0,255,0)   % hsv(120,100,100) % xcolor: green
  % myblue    % 0000FF % rgb(0,0,255)   % hsv(240,100,100) % xcolor: blue
  % myorange  % FF8000 % rgb(255,128,0) % hsv(30,100,100)  % 30=120-90
  % mycyan    % 0080FF % rgb(0,128,255) % hsv(210,100,100) % 210=120+90=240-30

  \colorlet{mygray}{gray} %
  \colorlet{myblack}{black!75} %
  \colorlet{myred}{red} %
  \colorlet{mygreen}{green} %
  \colorlet{myblue}{blue} %
  \definecolor{myorange}{RGB}{255,128,0} %
  \definecolor{mycyan}{RGB}{0,128,255} %

  %%%% these don't work with TikZ/plain TeX
  %% \colorlet{myblack}{darkgray} %
  %% \definecolor{myorange}{HTML}{FF8000} %
  %% \definecolor{mycyan}{HTML}{0080FF} %

  %%%% \color{yellow}:
  %% rgb(255,242,0) % LaTeX package xcolor used by TikZ/LaTeX
  %% rgb(255,255,0) % TikZ/plain TeX

  %%%%%%

  \def\Co{myred}    % 3 intermediate points on green line over base point (A0)
  \def\Ca{mycyan}   % 2 over (A1)
  \def\Cb{myorange} % 2 over (X0)
  \def\Cc{myblue}   % 2 over (Y1)
  \def\Cd{myblack}  % 1 intermediate (5x)
  \def\Ce{mygray}   % 0 intermediates (5x)

  %%%%

  %%%%%% A step in the MacLane path moves 1 opening paren to the
  %%%%%% front.  One performs at the first possible spot:
  %% A(BC) -> (AB)C, then (AB)(C'C'') -> ((AB)C')C'' etc.

  %%%% Here the steps are constructed backwards, e.g., to get
  %% A1->A0  A2->X0->A0  B0->Y2->Y1->A0
  %%%% one starts at A0 in 3 different directions and follows at first
  %%%% without direction change.  Reference is the last column.

  %%%% The columns come in reflection pairs.  The Tamari index counts
  %%%% opening parens right before the slots, including the outer
  %%%% paren.  The first Tamari index can be easily read from the
  %%%% second to last column (which has the outer paren pair).

  %%%% (columns 1,2,8 were created by hand, columns 3-7 then derived
  %%%% from the last by a script)

  \def\VERTICES{%
    %%%% M_1
    A0/\Co/11111/5(4(3(2(10))))/50000/((((01)2)3)4)5,       %%%  (5(4(3(2( 10 )))))  %%%  (((( 01 )2)3)4)5
    %%%% M_2
    % A0/\Co/11111,                                         %%%  (5(4(3( 2(10) ))))  %%%  ((( (01)2 )3)4)5
    A1/\Ca/11120/5(4(3((21)0)))/41000/(((0(12))3)4)5,       %%%  (5(4(3( (21)0 ))))  %%%  ((( 0(12) )3)4)5
    %%%% M_3 (pentagon)
    % A0/\Co/11111,                                         %%%  (5(4( 3(2(10)) )))  %%%  (( ((01)2)3 )4)5
    X0/\Cb/11201/5(4((32)(10)))/40100/(((01)(23))4)5,       %%%  (5(4( (32)(10) )))  %%%  (( (01)(23) )4)5
    A2/\Cd/11300/5(4(((32)1)0))/31100/((0(1(23)))4)5,       %%%  (5(4( ((32)1)0 )))  %%%  (( 0(1(23)) )4)5
    % A1/\Ca/11120,                                         %%%  (5(4( 3((21)0) )))  %%%  (( (0(12))3 )4)5
    A3/\Cd/11210/5(4((3(21))0))/32000/((0((12)3))4)5,       %%%  (5(4( (3(21))0 )))  %%%  (( 0((12)3) )4)5
    %%%% M_4 (3-dim associahedron, 14 vertices, lower cube)
    % A0/\Co/11111,                                         %%%  (5( 4(3(2(10))) ))  %%%  ( (((01)2)3)4 )5
    Y1/\Cc/12011/5((43)(2(10)))/40010/(((01)2)(34))5,       %%%  (5( (43)(2(10)) ))  %%%  ( ((01)2)(34) )5
    Y2/\Cd/13001/5(((43)2)(10))/30110/((01)(2(34)))5,       %%%  (5( ((43)2)(10) ))  %%%  ( (01)(2(34)) )5
    B0/\Ce/14000/5((((43)2)1)0)/21110/(0(1(2(34))))5,       %%%  (5( (((43)2)1)0 ))  %%%  ( 0(1(2(34))) )5
    % A1/\Ca/11120,                                         %%%  (5( 4(3((21)0)) ))  %%%  ( ((0(12))3)4 )5
    Z1/\Cd/12020/5((43)((21)0))/31010/((0(12))(34))5,       %%%  (5( (43)((21)0) ))  %%%  ( (0(12))(34) )5
    B1/\Ce/13010/5(((43)(21))0)/22010/(0((12)(34)))5,       %%%  (5( ((43)(21))0 ))  %%%  ( 0((12)(34)) )5
    % X0/\Cb/11201,                                         %%%  (5( 4((32)(10)) ))  %%%  ( ((01)(23))4 )5
    X2/\Cd/12101/5((4(32))(10))/30200/((01)((23)4))5,       %%%  (5( (4(32))(10) ))  %%%  ( (01)((23)4) )5
    X3/\Ce/13100/5(((4(32))1)0)/21200/(0(1((23)4)))5,       %%%  (5( ((4(32))1)0 ))  %%%  ( 0(1((23)4)) )5
    % A2/\Cd/11300,                                         %%%  (5( 4(((32)1)0) ))  %%%  ( (0(1(23)))4 )5
    B2/\Ce/12200/5((4((32)1))0)/22100/(0((1(23))4))5,       %%%  (5( (4((32)1))0 ))  %%%  ( 0((1(23))4) )5
    % A3/\Cd/11210,                                         %%%  (5( 4((3(21))0) ))  %%%  ( (0((12)3))4 )5
    B3/\Ce/12110/5((4(3(21)))0)/23000/(0(((12)3)4))5,       %%%  (5( (4(3(21)))0 ))  %%%  ( 0(((12)3)4) )5
    %%%% M_5 (4-dim associahedron, 14+14+14 vertices)
    % A0/\Co/11111,                                         %%%  ( 5(4(3(2(10)))) )  %%%  ((((01)2)3)4)5
    A0a/\Co/20111/(54)(3(2(10)))/40001/(((01)2)3)(45),      %%%  ( (54)(3(2(10))) )  %%%  (((01)2)3)(45)
    A0b/\Co/30011/((54)3)(2(10))/30011/((01)2)(3(45)),      %%%  ( ((54)3)(2(10)) )  %%%  ((01)2)(3(45))
    A0c/\Co/40001/(((54)3)2)(10)/20111/(01)(2(3(45))),      %%%  ( (((54)3)2)(10) )  %%%  (01)(2(3(45)))
    A0d/\Co/50000/((((54)3)2)1)0/11111/0(1(2(3(45)))),      %%%  ( ((((54)3)2)1)0 )  %%%  0(1(2(3(45))))
    %%
    % A1/\Ca/11120,                                         %%%  ( 5(4(3((21)0))) )  %%%  (((0(12))3)4)5
    A1a/\Ca/20120/(54)(3((21)0))/31001/((0(12))3)(45),      %%%  ( (54)(3((21)0)) )  %%%  ((0(12))3)(45)
    A1b/\Ca/30020/((54)3)((21)0)/21011/(0(12))(3(45)),      %%%  ( ((54)3)((21)0) )  %%%  (0(12))(3(45))
    A1d/\Ca/40010/(((54)3)(21))0/12011/0((12)(3(45))),      %%%  ( (((54)3)(21))0 )  %%%  0((12)(3(45)))
    %%
    % X0/\Cb/11201,                                         %%%  ( 5(4((32)(10))) )  %%%  (((01)(23))4)5
    X0a/\Cb/20201/(54)((32)(10))/30101/((01)(23))(45),      %%%  ( (54)((32)(10)) )  %%%  ((01)(23))(45)
    X0c/\Cb/30101/((54)(32))(10)/20201/(01)((23)(45)),      %%%  ( ((54)(32))(10) )  %%%  (01)((23)(45))
    X0d/\Cb/40100/(((54)(32))1)0/11201/0(1((23)(45))),      %%%  ( (((54)(32))1)0 )  %%%  0(1((23)(45)))
    %%
    % Y1/\Cc/12011,                                         %%%  ( 5((43)(2(10))) )  %%%  (((01)2)(34))5
    Y1b/\Cc/21011/(5(43))(2(10))/30020/((01)2)((34)5),      %%%  ( (5(43))(2(10)) )  %%%  ((01)2)((34)5)
    Y1c/\Cc/31001/((5(43))2)(10)/20120/(01)(2((34)5)),      %%%  ( ((5(43))2)(10) )  %%%  (01)(2((34)5))
    Y1d/\Cc/41000/(((5(43))2)1)0/11120/0(1(2((34)5))),      %%%  ( (((5(43))2)1)0 )  %%%  0(1(2((34)5)))
    %%
    % A2/\Cd/11300,                                         %%%  ( 5(4(((32)1)0)) )  %%%  ((0(1(23)))4)5
    A2a/\Cd/20300/(54)(((32)1)0)/21101/(0(1(23)))(45),      %%%  ( (54)(((32)1)0) )  %%%  (0(1(23)))(45)
    A2d/\Cd/30200/((54)((32)1))0/12101/0((1(23))(45)),      %%%  ( ((54)((32)1))0 )  %%%  0((1(23))(45))
    %%
    % A3/\Cd/11210,                                         %%%  ( 5(4((3(21))0)) )  %%%  ((0((12)3))4)5
    A3a/\Cd/20210/(54)((3(21))0)/22001/(0((12)3))(45),      %%%  ( (54)((3(21))0) )  %%%  (0((12)3))(45)
    A3d/\Cd/30110/((54)(3(21)))0/13001/0(((12)3)(45)),      %%%  ( ((54)(3(21)))0 )  %%%  0(((12)3)(45))
    %%
    % Y2/\Cd/13001,                                         %%%  ( 5(((43)2)(10)) )  %%%  ((01)(2(34)))5
    Y2c/\Cd/22001/(5((43)2))(10)/20210/(01)((2(34))5),      %%%  ( (5((43)2))(10) )  %%%  (01)((2(34))5)
    Y2d/\Cd/32000/((5((43)2))1)0/11210/0(1((2(34))5)),      %%%  ( ((5((43)2))1)0 )  %%%  0(1((2(34))5))
    %%
    % Z1/\Cd/12020,                                         %%%  ( 5((43)((21)0)) )  %%%  ((0(12))(34))5
    Z1b/\Cd/21020/(5(43))((21)0)/21020/(0(12))((34)5),      %%%  ( (5(43))((21)0) )  %%%  (0(12))((34)5)
    Z1d/\Cd/31010/((5(43))(21))0/12020/0((12)((34)5)),      %%%  ( ((5(43))(21))0 )  %%%  0((12)((34)5))
    %%
    % X2/\Cd/12101,                                         %%%  ( 5((4(32))(10)) )  %%%  ((01)((23)4))5
    X2c/\Cd/21101/(5(4(32)))(10)/20300/(01)(((23)4)5),      %%%  ( (5(4(32)))(10) )  %%%  (01)(((23)4)5)
    X2d/\Cd/31100/((5(4(32)))1)0/11300/0(1(((23)4)5)),      %%%  ( ((5(4(32)))1)0 )  %%%  0(1(((23)4)5))
    %%
    % B0/\Ce/14000,                                         %%%  ( 5((((43)2)1)0) )  %%%  (0(1(2(34))))5
    B0d/\Ce/23000/(5(((43)2)1))0/12110/0((1(2(34)))5),      %%%  ( (5(((43)2)1))0 )  %%%  0((1(2(34)))5)
    %%
    % B1/\Ce/13010,                                         %%%  ( 5(((43)(21))0) )  %%%  (0((12)(34)))5
    B1d/\Ce/22010/(5((43)(21)))0/13010/0(((12)(34))5),      %%%  ( (5((43)(21)))0 )  %%%  0(((12)(34))5)
    %%
    % X3/\Ce/13100,                                         %%%  ( 5(((4(32))1)0) )  %%%  (0(1((23)4)))5
    X3d/\Ce/22100/(5((4(32))1))0/12200/0((1((23)4))5),      %%%  ( (5((4(32))1))0 )  %%%  0((1((23)4))5)
    %%
    % B2/\Ce/12200,                                         %%%  ( 5((4((32)1))0) )  %%%  (0((1(23))4))5
    B2d/\Ce/21200/(5(4((32)1)))0/13100/0(((1(23))4)5),      %%%  ( (5(4((32)1)))0 )  %%%  0(((1(23))4)5)
    %%
    % B3/\Ce/12110,                                         %%%  ( 5((4(3(21)))0) )  %%%  (0(((12)3)4))5
    B3d/\Ce/21110/(5(4(3(21))))0/14000/0((((12)3)4)5)%      %%%  ( (5(4(3(21))))0 )  %%%  0((((12)3)4)5)
  }

  \tikzset{
    %% there is node option /tikz/label
    labelbox/.style={ %
      fill=white,fill opacity=0.6, %
      draw,text opacity=1, %
      inner sep=7/3pt}, %
  }
  %% inner sep has tikz initial value 1/3em
  %%% For the small \scriptscriptstyle text we take 2/3 of it.  In
  %%% font \tt, for which 1em=21/2pt, this gives 2/9em=7/3pt.

  \def\Label#1{$\tt\scriptscriptstyle#1$}

  \ifINDICES %

  \ifREVERSE %
  \foreach \NNN/\CCC/\TRight in \VERTICES { %
    \node[labelbox] at (\NNN) {\Label\TRight} ; } %
  \else %
  \foreach \NNN/\CCC/\TRight/\PRight/\TLeft in \VERTICES { %
    \node[labelbox] at (\NNN) {\Label\TLeft} ; } %
  \fi %

  \else % \ifINDICES

  \ifPARENS %

  \ifREVERSE %
  \foreach \NNN/\CCC/\TRight/\PRight in \VERTICES { %
    \node[labelbox] at (\NNN) {\Label\PRight} ; } %
  \else %
  \foreach \NNN/\CCC/\TRight/\PRight/\TLeft/\PLeft in \VERTICES { %
    \node[labelbox] at (\NNN) {\Label\PLeft} ; } %
  \fi %

  \else % \ifPARENS

  \ifNAMES \def\RADIUS{2.2pt} \else \def\RADIUS{1.4pt} \fi %
  \foreach \NNN/\CCC in \VERTICES { %
    \fill[\CCC] (\NNN) circle[radius=\RADIUS] ; } %

  \fi % \ifPARENS
  \fi % \ifINDICES

  %%%%%%%% caption M_5, continuing M_2,M_3,M_4 in tamari-diagram.tex
  \ifCAPTION

  %%%% M_5 is like M_4 scaled \magstep2 (1.44)
  %%%% subscript down shift: 1.44*8/3pt = 3.84pt
  %%%% cmtt10 cap height-4/5ex = 55/9pt-(4/5)*155/36pt = 8/3pt
  %%% no interword spacing in \TMfontD (cmsy)
  % \def\MFive{\TMfontD M \lower 3.84pt\hbox{\TMfontDSubscript 5}}
  %% place the M as if the subscript were not present
  \def\MFive{\TMfontD M \smash{\lower 3.84pt\rlap{\TMfontDSubscript 5}}}

  \path ($(B1d)!1/2!(B3d)$) ($(B2)!1/2!(B3)$) %
  node at (current path bounding box.south west) {\MFive} ; %

  \fi % \ifCAPTION

  %%%%%%%% show the names of the 2x14+14 vertices
  \ifNAMES

  \tikzset{outer sep=0pt} %

  \foreach \xy in \BottomVertices { %
    \node[above] at (\xy) {\xy} ; %
    \node[above] at (\xy d) {\xy d} ; %
  }
  \foreach \xy in {%
    A0a,A0b,A0c,A1a,A1b,X0a,X0c,Y1b,Y1c,A2a,A3a,X2c,Y2c,Z1b%
  }{
    \node[above] at (\xy) {\xy} ; %
  }

  \fi % \ifNAMES

  %%%%%%%%

  \endtikzpicture
} % \centerline
\end{document}

%%%%%%%%

{{
    %%%%%%%% list of edges which are not steps (blue arrows)
    %%%%%% ordered (backwards) by the inner step

    %%%% M_3 (pentagon)
    A3/\Cd,  %% ((0( (12)3 ))4)5
    A2/\Cd,  %% ((0( 1(23) ))4)5
    %%%%%%%%
    %%%% M_4 (lower cube)
    Y1/\Cc,  %% (( (01)2) (34))5
    Z1/\Cd,  %% (( 0(12)) (34))5
    %%
    X2/\Cd,  %% ((01)( (23)4 ))5
    Y2/\Cd,  %% ((01)( 2(34) ))5
    %%
    X3/\Ce,  %% (0(1( (23)4 )))5
    B0/\Ce,  %% (0(1( 2(34) )))5
    %%
    B2/\Ce,  %% (0( (1(23))4 ))5
    X3/\Ce,  %% (0( 1((23)4) ))5
    %%
    B1/\Ce,  %% (0( (12)(34) ))5
    B0/\Ce,  %% (0( 1(2(34)) ))5
    %%
    B3/\Ce,  %% (0(( (12)3)4 ))5
    B2/\Ce,  %% (0(( 1(23))4 ))5
    %%
    B3/\Ce,  %% (0( ((12)3)4) )5
    B1/\Ce,  %% (0( (12)(34)) )5
    %%
    %%%% the front of the lower cube is a pentagon with incoming
    %%%% vertex B3 and outgoing vertex B0
    % B3 <- B2 <- X3 <- B0
    % B3 <- B1 <- B0
    %%%%%%%%
    %%%% M_5 (84 edges)
    %%% have the 21 edges on the lower cube
    %%% green edges from lower to upper cube:  1x4+3x3+5x2+5x1 = 28
    %%% 14 edges in the "middle":
    %%%%%% 3 interesting 2-cells
    %% the lower middle pentagon
    A0a/\Co,  %% ( ((01)2)3 )(45) % incoming
    A1a/\Ca,  %% ( (0(12))3 )(45)
    A3a/\Cd,  %% ( 0((12)3) )(45)
    %
    X0a/\Cb,  %% ( (01)(23) )(45)
    A2a/\Cd,  %% ( 0(1(23)) )(45) % outgoing
    %% the middle quadrilateral
    Y1b/\Cc,  %% ( (01)2 )( (34)5 )
    A0b/\Co,  %% ( (01)2 )( 3(45) )
    Z1b/\Cd,  %% ( 0(12) )( (34)5 )
    A1b/\Ca,  %% ( 0(12) )( 3(45) )
    %% the upper middle pentagon
    X2c/\Cd,  %% (01)( ((23)4)5 ) % incoming
    Y2c/\Cd,  %% (01)( (2(34))5 )
    Y1c/\Cc,  %% (01)( 2((34)5) )
    %
    X0c/\Cb,  %% (01)( (23)(45) )
    A0c/\Co,  %% (01)( 2(3(45)) ) % outgoing
    %%%%%%%%
    %%% 21 edges on upper cube:
    %% With some consideration one finds (details might be written
    %% elsewhere):
    %%%%
    %% For every edge A-B in the lower cube there is an edge Ad-Bd in
    %% the upper cube.  However the orientation may change.
    %%%%
    %% The orientation change is the change of parity of the numbers
    %% of intermediates over A, B.
    %%%%
    %% One may also look at the parity of the numbers of pentagons in
    %% the rectangle Ad,Bd,B,A.
    %%%%%
    %% For instance, over A0->Y1 there are 1 pentagon and 2
    %% quadrilaterals, so A0d<-Y1d.
    %%%%%
    %% A practical description:  The orientation gets reversed if and
    %% only if there is a color change.  (Colors \Ca, \Cb, \Cc should
    %% be considered equal here, but there is no edge with both
    %% endpoints in these colors anyway.)
    %%%%%
    %% The same argument applies in all dimensions:  A0<-A1 : B0->B1
    %% since there is 1 pentagon between them.  However in lower
    %% dimensions it is easy enough to compute explicitly with paren
    %% expressions.
}}

%%%%%%%%

%% png creation (small size, transparent)

%%% pdflatex cube-4-84.tex
%%% pdftocairo -png -singlefile -transp -r 97.5 cube-4-84.pdf tmp
%%% magick -define png:exclude-chunk=date,time tmp.png -trim +repage cube-4-84.png
%%% optipng cube-4-84.png

%%%% magick adds white (fallback) background to the transparent image
%%%% and has the convenient option -trim.

%%%% Image size is 657x623.

%%%% The trim parameters for cube-4-84.png are used for
%%%% cube-4-84-simple.png:
%%% magick tmp.png -format "%@\n" info: %% 657x623+86+155
%%% magick -define png:exclude-chunk=date,time tmp-simple.png -crop $(magick tmp.png -format "%@\n" info:) +repage cube-4-84-simple.png

%%%%

%% png creation (large size)

%%% pdflatex cube-4-84.tex
%%% pdftocairo -png -singlefile -r 300 -W 2188 -H 2085 -x 181 -y 392 cube-4-84.pdf cube-4-84-large
%%% optipng cube-4-84-large.png

%%%% The padding (approx. 90 pixels after trimming) covers the paren
%%%% labels with a left/right padding of 2 pixels.

%%% pdftocairo crop parameters for \FIRSTtrue
%%% -W 2040 -H 2337 -x 255 -y 392

%% program versions

%%% This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019/Debian) (preloaded format=pdflatex)
%%% Document Class: amsart 2017/10/31 v2.20.4
%%% Package: tikz 2020/01/08 v3.1.5b (3.1.5b)

%%% pdftocairo version 0.86.1
%%% ImageMagick 7.1.1-43 Q16-HDRI x86_64 22550 https://imagemagick.org
%%% OptiPNG version 0.7.7

%%%%%%%%

%% first version

%%%% At first used a 1x1x2 cuboid with steeper green lines.

%%%% With no arrows and only 1x3+3x2 intermediate points:
%%% 2025-01-05

%%%% With all vertices and edges:
%%% 2025-06-21 simple (as with \FIRSTtrue)

%%%% Complete with all arrows:
%%% 2025-07-21 colored dots
%%% 2025-07-22 indices
%%% 2025-07-24 parens

%% latest changes

%%%% New geometry (with a 1x2x3 cuboid):
%%% 2025-08-18

%%%% Latest change of an image:
%%% 2025-08-18
%%% 2026-02-11 (cube-4-84-indices-large.png)
%%% 2026-02-14 (cube-4-84-skew-large.png)
%%% 2026-03-01 (cube-4-84-names-large.png)

%%%% Latest code change:
%%% 2026-02-11 % change \MFive
%%% 2026-02-14 % implement \ifSKEW
%%% 2026-03-01 % outer sep=0pt \ifNAMES

%%%% Latest change of comments:
%%% 2026-02-14 % \ifSKEW

%%%%%%%%

%% plain TeX compatibility

%%%% With the following few changes, pdftex creates practically
%%%% identical png files.  There is a normal (negligible) rendering
%%%% change.

%% %% to be compiled with pdflatex
%% to be compiled with pdftex

%%%% Of course these have to be commented out:
%% \documentclass{amsart}
%% \usepackage{tikz}

%%%% After this use

\input tikz
\usetikzlibrary{calc,decorations.markings}

\ifCAPTION %
%% \DeclareFixedFont{\TMfontD}{OMS}{cmsy}{m}{n}{20.74} % \magstep4
%% \DeclareFixedFont{\TMfontDSubscript}{OT1}{cmtt}{m}{n}{14.40} % \magstep2
\font\TMfontD=cmsy10 scaled \magstep4 %
\font\TMfontDSubscript=cmtt12 scaled \magstep1 %
\fi %

%%%% for \PARENStrue and \INDICEStrue
\font\fivett=cmtt8 scaled 625 %
\scriptscriptfont\ttfam=\fivett %

%%%% yellow from xcolor package, see section "color setup"
\definecolor{yellow}{RGB}{255,242,0} %

%% \begin{document}
%% \thispagestyle{empty} %
\nopagenumbers

%%%% Horizontal placement is the same for amsart, plain (text is
%%%% central).  After this "topskip" have identical placement relative
%%%% to the top left corner.
%%% amsart: \topmargin=22.215pt + \headheight=8pt + \headsep=14pt = 44.215pt
\vbox to 43.215pt{} %
%% there is \lineskip=1pt here

\long\edef\centerline#1{\centerline{#1}}
%%%% \centerline{%
%%%% ... [no changes inside the \centerline]
%%%% } % \centerline
\bye
%%%% \end{document}

%%%%

%%%% The yellow correction is not really important.

%%%% Skipping the "topskip" has no practical effect, except that one
%%%% needs to use a different pdftocairo crop parameter -y.

%%%% Remarkably, with \FIRSTtrue tex and latex yield *identical* png files
%%%% (cube-4-84-v1-simple-large.png, cube-4-84-v1-skew-large.png).

%%%%%%%%
