%% to be compiled with pdflatex

\documentclass{amsart}

%%%%%%%%

%%%%% Shows a projection of the 1-skeleton of the 4-dimensional
%%%%% associahedron (an oriented graph).  Shows also two opposite
%%%%% embeddings of the 3-dimensional associahedron.  And some further
%%%%% 2-cells, too.

%%%%% The black (as opposed to blue) arrows 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. p.46).

%%%%%%%%

\newif\ifNAMES %
%% uncomment to show the 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 \ifPARENS

\newif\ifMFive %
%% uncomment to add caption M_5 (meant for \INDICEStrue)
% \MFivetrue %

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

%%%%%%%%

\usepackage{tikz}
\usetikzlibrary{calc,decorations.markings}
\let\next\undefined

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

\begin{document}
\thispagestyle{empty} %
\parindent=0pt %

%%%%%%%%

\begin{tikzpicture} [x={(0cm,-4cm)},y={(-4cm,0cm)},z=-3.85mm*8]

  %%% The tikzpicture options stem from changing the xy-coordinate
  %%% square to size 1 and its origin to the top right corner (A0).

  %%% At first had no tikzpicture options, that is,
  % [x=1cm,y=1cm,z=-3.85mm] % tikz initial values
  % [x={(1cm,0cm)},y={(0cm,1cm)},z{(-3.85mm,-3.85mm)}] % expanded version
  %%% with the coordinate system:
  %% \coordinate (A3) at (0,0,0) ; % origin
  %% \coordinate (A1) at (4,0,0) ; % basis vector 1
  %% \coordinate (A2) at (0,4,0) ; % basis vector 2
  %% \coordinate (B0) at (0,0,8) ; % basis vector 3
  %% \coordinate (TA3) at (-9.8,10,-3) ; % basis vector 4

  %%% The triple (-9.8,10,-3) determines the projection of 4-space to
  %%% 3-space.  The projection from 3-space to 2-space is the tikz
  %%% initial one.

  %%%%%%%%

  %%%% 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 (X2) at ($(X0)+(B0)$) ; % (0,1/2,1)

  %% 4 inner subdivisions

  \iftrue
  \def\StepA{1/4}
  \def\StepB{1/2}
  \else % alternative values
  \def\StepA{1/3}
  \def\StepB{2/3}
  \fi

  \coordinate (X1) at ($(X0)!\StepB!(X2)$) ; % (0,1/2,1/2)
  \coordinate (Y1) at ($(A0)!\StepA!(B0)$) ; % (0,0,1/4)
  \coordinate (Y2) at ($(A0)!\StepB!(B0)$) ; % (0,0,1/2)
  \coordinate (Z1) at ($(A1)!\StepA!(B1)$) ; % (1,0,1/4)

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

  \coordinate (TA0) at (-10/4,9.8/4,-3/8) ; % basis vector 4
  %% steeper "waterfall" variant
  % \coordinate (TA0) at (-9.5/4,8/4,-4.5/8) ; % basis vector 4
  %% less steep variant
  % \coordinate (TA0) at (-9.5/4,10.6/4,-2.55/8) ; % basis vector 4

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

  %%%%%%%%

  %%% projection of 3rd basis vector (B0) in xy-plane
  %% \coordinate (B0) at (0.385*2,0.385*2) ; %
  %% \coordinate (B0) at (0.77,0.77) ; %

  %%% projection of 4th basis vector (TA0) in xy-plane
  %% \coordinate (TA0) at (-2.5-0.385*3/4,2.45-0.385*3/4) ; %
  %% \coordinate (TA0) at (-2.78875,2.16125) ; %

  %%%% make them explicit

  \iftrue %
  \else % comment out to print
  \newdimen\cx %
  \newdimen\cy %
  \foreach \XXX in {%
    A0,A1,A2,B0,TA0%
  }{ %
    \pgfextractx{\cx}{\pgfpointanchor{\XXX}{center}} %
    \pgfextracty{\cy}{\pgfpointanchor{\XXX}{center}} %
    \typeout{\string\coordinate \space (\XXX) at (\the\cx,\the\cy) ; \csname@percentchar\endcsname} %
    %%
  }
  \fi %

  %% \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 (TA0) at (-245.9737pt,317.39049pt) ; %

  %%%%%%%%

  %% placement in shipout is independent of labels, thickness of
  %% bullets
  \useasboundingbox (TB3) -- (TA0) -- (A0) -- (B3) ; %

  %%%%%%%%

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

  % \iftrue
  \iffalse %% things get too close
  \def\StepA{1/8}
  \def\StepB{1/4}
  \def\StepC{1/2}
  \else % alternative values
  \def\StepA{1/4}
  \def\StepB{1/2}
  \def\StepC{3/4}
  \fi

  \coordinate (A01) at ($(A0)!\StepA!(TA0)$) ; % red rail
  \coordinate (A02) at ($(A0)!\StepB!(TA0)$) ; % red
  \coordinate (A03) at ($(A0)!\StepC!(TA0)$) ; % red
  \coordinate (A11) at ($(A1)!\StepA!(TA1)$) ; % cyan rail
  \coordinate (A12) at ($(A1)!\StepB!(TA1)$) ; % cyan
  \coordinate (X01) at ($(X0)!\StepA!(TX0)$) ; % orange rail
  \coordinate (X02) at ($(X0)!\StepC!(TX0)$) ; % orange
  \coordinate (Y11) at ($(Y1)!\StepB!(TY1)$) ; % blue rail
  \coordinate (Y12) at ($(Y1)!\StepC!(TY1)$) ; % blue
  \coordinate (MA2) at ($(A2)!\StepA!(TA2)$) ; % darkgray rail 1
  \coordinate (MA3) at ($(A3)!\StepA!(TA3)$) ; % darkgray rail 2
  \coordinate (MX1) at ($(X1)!\StepC!(TX1)$) ; % darkgray rail 3
  \coordinate (MY2) at ($(Y2)!\StepC!(TY2)$) ; % darkgray rail 4
  \coordinate (MZ1) at ($(Z1)!\StepB!(TZ1)$) ; % 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 {,T}{ %

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

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

  } %

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

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

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

    %% the middle pentagon near top (\StepC)
    \filldraw (A03) -- (Y12) -- (MY2) -- (MX1) -- (X02) -- cycle ; %
    %%% (Y12) could be dropped

    %% the middle quadrilateral (\StepB)
    \filldraw (A02) -- (Y11) -- (MZ1) -- (A12) -- cycle ; %

    %% the middle pentagon near bottom (\StepA)
    \filldraw (A01) -- (X01) -- (MA2) -- (MA3) -- (A11) -- cycle ; %
    %%% (X01) could be dropped

  \end{scope}

  %%%%%%%% 14 green lines

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

  %%%%%%%% arrows

  \tikzset{
    midtip/.style={decoration={markings, %
        mark=at position #1 with %
        {\arrow{stealth[sep=-2pt]}} %
      },postaction={decorate}}, %
    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/X1,X1/X2, %
    A2/B2, %
    A3/B3, %
    A0/A01,A01/A02,A02/A03,A03/TA0, % M_4 <-- M_5
    A1/A11,A11/A12,A12/TA1, %
    X0/X01,X01/X02,X02/TX0, %
    Y1/Y11,Y11/Y12,Y12/TY1, %
    A2/MA2,MA2/TA2, %
    A3/MA3,MA3/TA3, %
    Y2/MY2,MY2/TY2, %
    Z1/MZ1,MZ1/TZ1, %
    X1/MX1,MX1/TX1, %
    B0/TB0, %
    B1/TB1, %
    X2/TX2, %
    B2/TB2, %
    B3/TB3%
  }

  %%%% 43 remaining arrows (blue)

  %%% 6 arrows are moved a bit because of overlapping
  \def\ARROWSBW{A3/A2,TA3/TA2} %
  \def\ARROWSBX{X01/MA2,Y11/MZ1} %
  \def\ARROWSBY{MX1/MY2,TZ1/TA1} %

  \def\ARROWSB{%
    %%%%
    %%%% 22 remaining arrows not on the upper cube
    %% from the list at the end of this file
    %%%%
    %% A3/A2, % in \ARROWSBW
    Y1/Z1,X1/Y2,X2/B0,B2/X2,B1/B0,B3/B2,B3/B1, %
    A01/A11,A11/MA3,MA3/MA2, %
    A01/X01,
    %% X01/MA2, % in \ARROWSBX
    %% Y11/MZ1, % in \ARROWSBX
    MZ1/A12, %
    Y11/A02,A02/A12, %
    %% MX1/MY2, % in \ARROWSBY
    MY2/Y12,Y12/A03, %
    MX1/X02,X02/A03, %
    %%%%
    %%%% all 21 arrows on the lower cube, collected from above
    %%%%
    %% A0/A1,A0/X0,A0/Y1, % -1
    %% A1/A3,A1/Z1,X0/A2,X0/X1,Y1/Y2,Y1/Z1, % -1
    %% A3/B3,Z1/B1,Y2/B0,X1/X2,A2/B2, % -1
    %% A3/A2,X1/Y2, % +1
    %% X2/B0,B2/X2,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.
    %%%%
    TA1/TA0,TX0/TA0,TY1/TA0, % -1
    TA3/TA1, % -1
    %% TZ1/TA1, % -1 % in \ARROWSBY
    TA2/TX0,TX1/TX0,TY2/TY1,TZ1/TY1, % -1
    TB3/TA3,TB1/TZ1,TB0/TY2,TX2/TX1,TB2/TA2, % -1
    %% TA3/TA2, in \ARROWSBW
    TX1/TY2, % +1
    TX2/TB0,TB2/TX2,TB1/TB0,TB3/TB2,TB3/TB1% +1
  }

  \ifREVERSE %

  \foreach \XXX/\YYY in \ARROWSA  {\path[midtip] (\XXX) -- (\YYY) ; } %
  \foreach \XXX/\YYY in \ARROWSBW {\path[midtip=0.46] (\XXX) -- (\YYY) ; } %
  \foreach \XXX/\YYY in \ARROWSBX {\path[midtip=0.46] (\XXX) -- (\YYY) ; } %
  \foreach \XXX/\YYY in \ARROWSBY {\path[midtip=0.44] (\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 \ARROWSBW {\path[midtip=0.54,\BLUE] (\YYY) -- (\XXX) ; } %
  \foreach \XXX/\YYY in \ARROWSBX {\path[midtip=0.53,\BLUE] (\YYY) -- (\XXX) ; } %
  \foreach \XXX/\YYY in \ARROWSBY {\path[midtip=0.56,\BLUE] (\YYY) -- (\XXX) ; } %
  \foreach \XXX/\YYY in \ARROWSB  {\path[midtip,\BLUE] (\YYY) -- (\XXX) ; } %

  \fi % \ifREVERSE

  %%%%%%%% bullets

  %%%% 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}{darkgray} %
  \colorlet{myred}{red} %
  \colorlet{mygreen}{green} %
  \colorlet{myblue}{blue} %
  \definecolor{myorange}{HTML}{FF8000} %
  \definecolor{mycyan}{HTML}{0080FF} %

  %%%%

  \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).

  %%%% (The last column was created by hand, the 4 columns before it
  %%%% then 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
    X1/\Cd/12101/5((4(32))(10))/30200/((01)((23)4))5,       %%%  (5( (4(32))(10) ))  %%%  ( (01)((23)4) )5
    X2/\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
    A01/\Co/20111/(54)(3(2(10)))/40001/(((01)2)3)(45),      %%%  ( (54)(3(2(10))) )  %%%  (((01)2)3)(45)
    A02/\Co/30011/((54)3)(2(10))/30011/((01)2)(3(45)),      %%%  ( ((54)3)(2(10)) )  %%%  ((01)2)(3(45))
    A03/\Co/40001/(((54)3)2)(10)/20111/(01)(2(3(45))),      %%%  ( (((54)3)2)(10) )  %%%  (01)(2(3(45)))
    TA0/\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
    A11/\Ca/20120/(54)(3((21)0))/31001/((0(12))3)(45),      %%%  ( (54)(3((21)0)) )  %%%  ((0(12))3)(45)
    A12/\Ca/30020/((54)3)((21)0)/21011/(0(12))(3(45)),      %%%  ( ((54)3)((21)0) )  %%%  (0(12))(3(45))
    TA1/\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
    X01/\Cb/20201/(54)((32)(10))/30101/((01)(23))(45),      %%%  ( (54)((32)(10)) )  %%%  ((01)(23))(45)
    X02/\Cb/30101/((54)(32))(10)/20201/(01)((23)(45)),      %%%  ( ((54)(32))(10) )  %%%  (01)((23)(45))
    TX0/\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
    Y11/\Cc/21011/(5(43))(2(10))/30020/((01)2)((34)5),      %%%  ( (5(43))(2(10)) )  %%%  ((01)2)((34)5)
    Y12/\Cc/31001/((5(43))2)(10)/20120/(01)(2((34)5)),      %%%  ( ((5(43))2)(10) )  %%%  (01)(2((34)5))
    TY1/\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
    MA2/\Cd/20300/(54)(((32)1)0)/21101/(0(1(23)))(45),      %%%  ( (54)(((32)1)0) )  %%%  (0(1(23)))(45)
    TA2/\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
    MA3/\Cd/20210/(54)((3(21))0)/22001/(0((12)3))(45),      %%%  ( (54)((3(21))0) )  %%%  (0((12)3))(45)
    TA3/\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
    MY2/\Cd/22001/(5((43)2))(10)/20210/(01)((2(34))5),      %%%  ( (5((43)2))(10) )  %%%  (01)((2(34))5)
    TY2/\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
    MZ1/\Cd/21020/(5(43))((21)0)/21020/(0(12))((34)5),      %%%  ( (5(43))((21)0) )  %%%  (0(12))((34)5)
    TZ1/\Cd/31010/((5(43))(21))0/12020/0((12)((34)5)),      %%%  ( ((5(43))(21))0 )  %%%  0((12)((34)5))
    %%
    % X1/\Cd/12101,                                         %%%  ( 5((4(32))(10)) )  %%%  ((01)((23)4))5
    MX1/\Cd/21101/(5(4(32)))(10)/20300/(01)(((23)4)5),      %%%  ( (5(4(32)))(10) )  %%%  (01)(((23)4)5)
    TX1/\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
    TB0/\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
    TB1/\Ce/22010/(5((43)(21)))0/13010/0(((12)(34))5),      %%%  ( (5((43)(21)))0 )  %%%  0(((12)(34))5)
    % X2/\Ce/13100,                                         %%%  ( 5(((4(32))1)0) )  %%%  (0(1((23)4)))5
    TX2/\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
    TB2/\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
    TB3/\Ce/21110/(5(4(3(21))))0/14000/0((((12)3)4)5)%      %%%  ( (5(4(3(21))))0 )  %%%  0((((12)3)4)5)
  }

  \tikzset{
    labels/.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[labels] at (\NNN) {\Label\TRight} ; } %
  \else %
  \foreach \NNN/\CCC/\TRight/\PRight/\TLeft in \VERTICES { %
    \node[labels] at (\NNN) {\Label\TLeft} ; } %
  \fi %

  \else % \ifINDICES

  \ifPARENS %

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

  \else % \ifPARENS

  \foreach \NNN/\CCC in \VERTICES { %
    \fill[\CCC] (\NNN) circle[radius=2.2pt] ; } %

  \fi % \ifPARENS
  \fi % \ifINDICES

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

  % \def\MFive{$\scriptspace=0pt \hbox{\TMfontD M}_{\hbox{\TMfontDSubscript 5}}$} %
  %% place the M as if the subscript were not present
  \def\MFive{ %
    \setbox0\hbox{\TMfontD M}%
    \setbox1\hbox{$\copy0_{\hbox{\TMfontDSubscript 5}}$}%
    \wd1=\wd0 \dp1=0pt \box1} % \ht doesn't change

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

  \fi % \ifMFive

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

  \foreach \xy in \BottomVertices { %
    \node[above] at (\xy) {\xy} ; %
    \node[above] at (T\xy) {T\xy} ; %
  }
  \foreach \xy in {%
    A01,A02,A03,A11,A12,X01,X02,Y11,Y12,MA2,MA3,MX1,MY2,MZ1%
  }{
    \node[above] at (\xy) {\xy} ; %
  }

  \fi % \ifNAMES

  %%%%%%%%

\end{tikzpicture}%
\end{document}

%%%%%%%%

{{
    %%%%%%%% list of edges which are not steps
    %%%%%% 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
    %%
    X1/\Cd,  %% ((01)( (23)4 ))5
    Y2/\Cd,  %% ((01)( 2(34) ))5
    %%
    X2/\Ce,  %% (0(1( (23)4 )))5
    B0/\Ce,  %% (0(1( 2(34) )))5
    %%
    B2/\Ce,  %% (0( (1(23))4 ))5
    X2/\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 <- X2 <- 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
    A01/\Co,  %% ( ((01)2)3 )(45) % incoming
    A11/\Ca,  %% ( (0(12))3 )(45)
    MA3/\Cd,  %% ( 0((12)3) )(45)
    %
    X01/\Cb,  %% ( (01)(23) )(45)
    MA2/\Cd,  %% ( 0(1(23)) )(45) % outgoing
    %% the middle quadrilateral
    Y11/\Cc,  %% ( (01)2 )( (34)5 )
    A02/\Co,  %% ( (01)2 )( 3(45) )
    MZ1/\Cd,  %% ( 0(12) )( (34)5 )
    A12/\Ca,  %% ( 0(12) )( 3(45) )
    %% the upper middle pentagon
    MX1/\Cd,  %% (01)( ((23)4)5 ) % incoming
    MY2/\Cd,  %% (01)( (2(34))5 )
    Y12/\Cc,  %% (01)( 2((34)5) )
    %
    X02/\Cb,  %% (01)( (23)(45) )
    A03/\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 TA-TB 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 TA,TB,B,A.
    %%%%%
    %% For instance, over A0->Y1 there are 1 pentagon and 2
    %% quadrilaterals, so TA0<-TY1.
    %%%%%
    %% 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 for the transparent image
%%%% and has the convenient option -trim.

%% png creation (large size)

%%% pdflatex cube-4-84.tex
%%% pdftocairo -png -singlefile -r 300 -W 2040 -H 2336 -x 437 -y 393 cube-4-84.pdf cube-4-84-large
%%% optipng cube-4-84-large.png

%% program versions

%%% This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019/Debian) (preloaded format=pdflatex)

%%%% TikZ
%%% \gdef\pgfversion{3.1.5b}
%%% \gdef\pgfversiondatetime{2020-01-08 10:30:17 +1300}

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

%%%%%%%%
