%% -*- tex-command: "./tex-command.bash"; -*-
%% (setq tex-command "pdflatex")

%%%%%%%%

%%%%% The arrows show 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).

%%%%%%%%

\documentclass{amsart}

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

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

%%%%

% \scalebox{.65}{% for tex2png
\begin{tikzpicture} [x={(0cm,-4cm)},y={(-4cm,0cm)},z=-3.85mm*8]
  % [x=1cm,y=1cm,z=-3.85mm] % initially

  %%%%%%%%

  %%%% 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
  \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 (= shifted M_3)
  \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
  \coordinate (X1) at ($(X0)!1/2!(X2)$) ; % (0,1/2,1/2)
  \coordinate (Y1) at ($(A0)!1/4!(B0)$) ; % (0,0,1/4)
  \coordinate (Y2) at ($(A0)!1/2!(B0)$) ; % (0,0,1/2)
  \coordinate (Z1) at ($(A1)!1/4!(B1)$) ; % (1,0,1/4)

  %%%% 14 vertices on upper cube (= shifted M_4)

  %%%%%% In a projection of a 4-dimensional object to the plane one
  %%%%%% wants to avoid too close image points and lines.
  \coordinate (TA0) at (-10/4,9.8/4,-3/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) ; %

  %%%%%%%%

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

  %% remaining 14 vertices of M_5 (4-dim associahedron)
  \coordinate (A01) at ($(A0)!\StepA!(TA0)$) ; %
  \coordinate (A02) at ($(A0)!\StepB!(TA0)$) ; %
  \coordinate (A03) at ($(A0)!\StepC!(TA0)$) ; %
  \coordinate (A11) at ($(A1)!\StepA!(TA1)$) ; %
  \coordinate (A12) at ($(A1)!\StepB!(TA1)$) ; %
  \coordinate (X01) at ($(X0)!\StepA!(TX0)$) ; %
  \coordinate (X02) at ($(X0)!\StepC!(TX0)$) ; %
  \coordinate (Y11) at ($(Y1)!\StepB!(TY1)$) ; %
  \coordinate (Y12) at ($(Y1)!\StepC!(TY1)$) ; %
  \coordinate (MA2) at ($(A2)!\StepA!(TA2)$) ; %
  \coordinate (MA3) at ($(A3)!\StepA!(TA3)$) ; %
  \coordinate (MX1) at ($(X1)!\StepC!(TX1)$) ; %
  \coordinate (MY2) at ($(Y2)!\StepC!(TY2)$) ; %
  \coordinate (MZ1) at ($(Z1)!\StepB!(TZ1)$) ; %

  %%%%%%%% 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

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

    %% the 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 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 : 1x1 + 1x2+1x1 + 1x3+2x2+2x1 + 1x4+3x3+5x2+5x1

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

  \foreach \XXX/\YYY in {%
    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%
  }{
    \path[midtip] (\YYY) -- (\XXX) ; %
  }

  %%%%%%%% bullets

  % 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\ColorIthree{myred}  % 3 intermediate points on green line over base point (A0)
  \def\ColorKone{mycyan}   % 2 over (A1)
  \def\ColorKtwo{myorange} % 2 over (X0)
  \def\ColorKthree{myblue} % 2 over (Y1)
  \def\ColorIone{myblack}  % 1 intermediate (5x)
  \def\ColorIzero{mygray}  % 0 intermediates (5x)

  \def\VERTICES{%
    %% M_1
    A0/\ColorIthree, %
    %% M_2
    A1/\ColorKone, %
    %% M_3
    X0/\ColorKtwo, %
    A2/\ColorIone, %
    A3/\ColorIone, %
    %% M_4
    Y1/\ColorKthree, %
    Y2/\ColorIone, %
    B0/\ColorIzero, %
    Z1/\ColorIone, %
    B1/\ColorIzero, %
    X1/\ColorIone, %
    X2/\ColorIzero, %
    B2/\ColorIzero, %
    B3/\ColorIzero, %
    %% M_5
    A01/\ColorIthree, %
    A02/\ColorIthree, %
    A03/\ColorIthree, %
    TA0/\ColorIthree, %
    %%
    A11/\ColorKone, %
    A12/\ColorKone, %
    TA1/\ColorKone, %
    %%
    X01/\ColorKtwo, %
    X02/\ColorKtwo, %
    TX0/\ColorKtwo, %
    %%
    Y11/\ColorKthree, %
    Y12/\ColorKthree, %
    TY1/\ColorKthree, %
    %%
    MA2/\ColorIone, %
    TA2/\ColorIone, %
    %%
    MA3/\ColorIone, %
    TA3/\ColorIone, %
    %%
    MY2/\ColorIone, %
    TY2/\ColorIone, %
    %%
    MZ1/\ColorIone, %
    TZ1/\ColorIone, %
    %%
    MX1/\ColorIone, %
    TX1/\ColorIone, %
    %%
    TB0/\ColorIzero, %
    TB1/\ColorIzero, %
    TX2/\ColorIzero, %
    TB2/\ColorIzero, %
    TB3/\ColorIzero%
  }

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

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

  %% better come last

  \iftrue %
  \else % comment out to show

  \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 %

  %%%%%%%%

\end{tikzpicture}%
%}% \scalebox
\end{document}
