%%%%%%

%% Comments and notes related with tamari-diagram*.tex.  In particular
%% on dimensions and coordinate choices.

%%%%%%

%% include the file

%%%% To integrate the diagram into a normal LaTeX file, copy the
%%%% preamble part to the file, copy the content part to a separate
%%%% file, say FOO.tex, and include that with something like

\medskip
\vskip\baselineskip \nointerlineskip

\centerline{\vbox{\input{FOO}}}
%% smaller size?
\centerline{\scalebox{0.5}{\vbox{\input{FOO}}}}

\vskip\baselineskip \nointerlineskip
\medskip

%% the \nointerlineskip equalize the vertical distances (to 0pt
%% without the skips)

%%%%%

%% \tt dimensions (cmtt10)

%%% 10.5pt=21/2pt % \tt 1em (\quad)
%%% 5.25pt=21/4pt % \tt width (monospacing), \enspace (.5em)
%%% 4.30554pt=155/36pt % \tt 1ex (x-height)
%%% 6.11111pt=55/9pt % \tt cap height (uppercase, digits)
%%% 3.05556pt=55/18pt % 1/2 of cap height, vcenter of \tt parens (math_axis)

%% get these from
\tt \setbox0\vbox to 1ex{\hbox to 1em{}}
\setbox0\hbox{\tt 1}
\setbox0\hbox{\tt (}
\typeout{\the\wd0 \space \the\ht0 \space \the\dp0}
%% 10.4999pt 4.30554pt 0.0pt
%% 5.24995pt 6.11111pt 0.0pt
%% 5.24995pt 6.94444pt 0.8333pt

%%% \newlength defines globally, so use a less simple name in the
%%% preamble and then abbreviate:
\let\tten\TypewriterEnskip
\tten=5.25pt % \tt letter width, \tt \enspace

%%%%%

%% tikz padding and margins of \node labels

%%% inner xsep, inner ysep: .3333em
%% \tt .3333em = (21/2pt)/3 = 3.5pt

%%% no extra space around the labels
\tikzset{outer sep=0pt}

%%%%%

%% baselineskip

%%% \bs is an abbreviation
\let\bs\baselineskip
%%% normal value is 12.0pt

%%% value 10.97pt is a guess from the scan of the original:
%%%% 10.97pt / 55/9pt estimates the ratio line-feed/cap-height on
%%%% Tamari's typewriter
\bs=10.97pt

%%%%%

%% \extrabox is a right shifted smashed box with internal down shift
%% placed at the reference point of the previous line, basically like
%% this:
\long\def\extrabox#1#2#3{
  \vskip-\baselineskip % go up to previous line
  \setbox0\hbox{#3} \moveright #1 \hbox{\smash{\lower #2 \box0}}
}
\extrabox{97.125pt}{52.6pt}{...}

%% The actual macro \extrabox gives finer control and is easily hooked
%% up.  The shifts can be specified by sequences of kerns which eases
%% additions.  It adjusts \hsize.  To be used as only item on a new
%% line with no indentation.

%%% arg 1 is a name, args 2 (3) are for \hskip (\vskip) material
\long\def\extrabox#1 | #2|#3|#4{

  \setbox0\hbox{#4}

  %% print the dimensions
  \typeout{extra box #1: \the\wd0 \space \the\ht0 \space \the\dp0}

  \setbox0\hbox{#2% horizontal material
    \vbox to 0pt{#3 % vertical material
      %%% ...
      \ht0=0pt \dp0=0pt \box0 % smash
      %%% ... %%% if there is nothing here, one may skip \dp0=0pt
      \vss
    }%
  }

  %% print the dimensions
  \typeout{extra box #1 complete: \the\wd0 \space \the\ht0 \space \the\dp0}

  \ifdim\hsize<\wd0 \hsize=\wd0 \fi % adjust \hsize

  \vskip-\baselineskip % go up to previous line
  \unhbox0

}
\extrabox 1 | \hskip18.5\tten | \vskip5\bs \vskip-2.2pt | {...}
%%% the skips could be \kern, but \hskip/\vskip are better recognizable

%%%%%

%% lines and arrows for \tt

\def\TTthick{semithick} % 0.6pt
%% \pgflinewidth:
%%% thin: 0.4pt % default thickness = TeX rule width
%%% semithick: 0.6pt % \TTthick
%%% thick: 0.8pt

%%%% horizontal tikz lines ( \draw (x1,y) -- (x2,y) ; ) have a
%%%% left/right padding of 1/2\pgflinewidth

%% \overharpoon is build like TeX \overline
\def\overharpoon#1{%
  \vbox{
    \setbox0\hbox{#1}
    \hbox{%
      \begin{tikzpicture}
        %% this gets rid of the padding
        % [trim left,trim right=\wd0]
        %% since \box0 follows anyway, can simply do an \rlap
        [trim left,trim right=0]
        \draw[\TTthick,arrows={-Straight Barb[harpoon]}]
        (0,0) -- (\wd0,0) ;
      \end{tikzpicture}%
    }
    \nointerlineskip
    \vskip1.2pt % clearance as in TeX \overline (3*rule width)
    \box0
  }%
}
%%% removing the \draw options results in
%%% \def\overharpoon#1{$\tt \overline{#1}$}

%% \TTto is a right arrow for monospaced \tt
%%% vertically centered like () but with a visual correction of 0.2pt
%%% (for the single use case)
\def\TTto{%
  \hbox to 3\tten{% 15.75pt
    \hss
    \begin{tikzpicture} [baseline=-55/18pt+0.2pt]
      %% width is 10.5pt + padding 2x0.3pt = 11.1pt
      \draw[\TTthick,-Straight Barb] (0,0) -- (2\tten,0) ;
    \end{tikzpicture}%
    \hss
  }%
}

%% monosized, monospaced and monoplaced subscript
%%% down shift of digits is \tt height-4/5*(x-height) = 8/3pt
%%% used for all 4 subscripts
\def\TTsubscript#1{$\scriptspace=0pt _{\hbox{#1}}$}

%%%%%

%% \dottedbox

%%% like \draw[thick,dotted], but with explicit dots to get exact
%%% corners and symmetric dotting

%%% \draw[thick,dotted] has dot distance 0.8pt + 2pt = 2.8pt
%%% (cf. tikz.code.tex)

%%% the enclosed content has width 15\tten (15=6+3+6), horizontally
%%% there are 29 dots, so dot distance is better
%% 15 * 21/4pt / 28 = 45/16pt = 2.8125pt

%%% \dottedbox is vertically centered at 1/2 of \tt cap height

\def\dottedbox{%
  \begin{tikzpicture} [trim left,baseline=-55/18pt]
    \fill[x=45/16pt,y=45/16pt,radius=0.5pt]
    foreach \x in {0,28} { foreach \y in {-4,...,4} { (\x,\y) circle[] }}
    foreach \y in {-4,4} { foreach \x in {1,...,27} { (\x,\y) circle[] }}
    ;
  \end{tikzpicture}%
}

%%%%%

%% \ARROW

%%%% Generally, if one wants to put the arrow tip in the middle of the
%%%% arrow line, it is not obvious where to put the tip exactly.  One
%%%% does not want the tip to end at the midpoint, it rather should be
%%%% somewhere "over" the midpoint.  The exact choice may depend on
%%%% the tip shape.

%%% Here the arrow line gets divided into 2 parts, the first getting
%%% the tip (moved forward).  A side effect is that dashes and dots
%%% start out coherently after the tip.

%%% arrow tip Latex forward leaning
\tikzset{LatexF/.tip={Latex[sep=-4pt]}}
%%% 4pt seems to be a useful value
%%% in the dashed case, the tip just covers the first dash-on of the
%%% continuing path

%%% To better resemble the original, the cut is taken at 0.55 instead
%%% of 1/2 of the full line (in the basic version).

\def\ARROW#1#2{
  \draw let
  \p0=($(#1)!0.55!(#2)$) in
  (#1) edge[-LatexF] (\p0) (\p0) -- (#2) ;
}

%%% in the dashed case, move the second part up by 1 dash period:
%%% dash-on + dash-off = 3pt + 3pt = 6pt
%%% this avoids an overlap of the two parts
\def\ARROWDASHED[#1]#2#3{
  \draw[#1] let
  \p0=($(#2)!0.55!(#3)$),
  \p1=($(\p0)!-6pt!(#2)$) in
  (#2) edge[-LatexF] (\p0) (\p1) -- (#3) ;
}

%%% similarly for dotted arrows
%%% dotted-off=2pt, dashed-off=3pt, so use 5pt here instead of 6pt
\def\ARROWDOTTED[#1]#2#3{ % from tamari-diagram-h.tex
  \draw[#1] let
  \p0=($(#3)!1/2!(#2)$),
  \p1=($(\p0)!5pt!(#2)$) in
  (#3) edge[-LatexF] (\p0) (\p1) -- (#2) ;
}

%% \BULLET - nothing to comment

%%%%%

%% \showTMCaption*

%%% use magnified \mathcal
\DeclareFixedFont{\TMfontA}{OMS}{cmsy}{m}{n}{10.95} % \magstephalf
\DeclareFixedFont{\TMfontB}{OMS}{cmsy}{m}{n}{12} % \magstep1
\DeclareFixedFont{\TMfontC}{OMS}{cmsy}{m}{n}{14.4} % \magstep2

%%% A \node[\below] has a separation by inner/outer ysep which are set
%%% to 0pt here.

%%% clearances of M_* captions are proportional to font size
%%%% set by hand emulating inner ysep=0.8em
\def\TMCaptionClearA{1.095*8pt} % 8.76pt
\def\TMCaptionClearB{1.2*8pt} % 9.6pt
\def\TMCaptionClearC{1.44*8pt} % 11.52pt

%%% To make the clearance independent of decorations (for instance an
%%% arrow tip) it is placed at (XXX.base) if necesssary.

\def\showTMCaptionA{
  \node[below=\TMCaptionClearA,inner ysep=0pt] at (current bounding box.base)
       {\TMCaption\TMfontA2} ; }

\def\TMCaption#1#2{{#1 M}\TTsubscript{#2}}

%%% don't let the \prime in M'_* move the caption down
\def\TMCaption#1#2{ % from tamari-diagram-d.tex
  \setbox0\hbox{#1 M}%
  \setbox1\hbox{$\copy0'$}%
  \wd1=\wd0 \ht1=\ht0 \box1\TTsubscript{#2}}

%%% alternative:
\tikzset{
  captionM/.style={below,
    node font=#1\usefont{OMS}{cmsy}{m}{n},
    inner ysep=0.8em},
  captionM/.default=\normalsize,
}
%% with \documentclass{amsart}
\node[captionM=\large]
\node[captionM=\Large]
\node[captionM=\LARGE]
%% this needs font resetting before the subscript and \prime
%% \large,\Large,\LARGE are larger with \documentclass{article}

%%%%%

%% ? is space

%%% too many "\ " are annoying, make (almost) all spaces explicit
\catcode`\?=\active
\let?=\ \relax

%%% without the \relax would get ?=\^^M=\<return> (which normally
%%% expands to a space anyway)

%%%%%

%% the top line is very long, handle it with \extrabox

\vphantom{X} % a box with the same height as the top line
%%% gives the right distance to previous material (in an include)

\hsize=0pt % don't worry, will be adjusted soon

\extrabox top line | | | {%
  \hskip33.5\tten
  -?\S
  ?1?-%
  \hskip30.5\tten
  -?12?-%
}

%%% latex tt section sign \S would be in plain tex
%% \font\ts=tctt1000 {\ts \char167}

%%%%%

\extrabox 4 | \hskip58\tten \hskip2pt | \vskip155pt | {%
  \begin{tikzpicture} [trim left,baseline=(1120),x=1pt,y=1pt]

    %%% ...
    \node[left] (2011N) at (2011) {2011} ;

    %%% Label '2200' is at the right border of the whole page.  Avoid
    %%% extra space from inner xsep to get the correct final \hsize
    %%% (and width of the whole box in an include).

    % \node at ([xscale=-1] 2011N) {2200} ;
    \node[inner xsep=0pt] at ([xscale=-1] 2011N) {2200} ;
    %%% ...

  \end{tikzpicture}%
}

%%%%%

%% dimensions of the \extrabox

%%%% cf. tamari-diagram-boxes-large.png

%%%% the internal box
%% \typeout{extra box #1: \the\wd0 \space \the\ht0 \space \the\dp0}
%%%% after smash and right shift
%% \typeout{extra box #1 complete: \the\wd0 \space \the\ht0 \space \the\dp0}

%%% extra box top line: 404.24817pt 6.11111pt 2.22168pt
%%% extra box top line complete: 404.24817pt 0.0pt 0.0pt
%%% extra box 1: 110.74973pt 14.80554pt 8.69446pt
%%% extra box 1 complete: 207.87473pt 0.0pt 0.0pt
%%% extra box 2: 92.74954pt 13.31029pt 22.40836pt
%%% extra box 2 complete: 195.12454pt 0.0pt 0.0pt
%%% extra box 3: 82.19902pt 123.51028pt 23.96582pt
%%% extra box 3 complete: 206.17403pt 0.0pt 0.0pt
%%% extra box 4: 126.9994pt 127.4103pt 125.23654pt
%%% extra box 4 complete: 433.4994pt 0.0pt 0.0pt

%% dimension of the full page

%% \setbox0\vbox{\input{FOO}} % content part of tamari-diagram.tex
%% \typeout{page dimensions: \the\wd0 \space \the\ht0 \space \the\dp0}
%%% page dimensions: 433.29941pt 302.30115pt 2.22223pt

%%%% depth 2.22223pt stems from the 'g' in 'Fig. 1'.

%%%%%

%% general comments

%%%% When reproducing a scan of a page typed with a real (old)
%%%% typewriter, important parameters to estimate are the ratios
%%%% letter-width:letter-height:line-feed.  For the first ratio, font
%%%% cmtt10 from \tt seems to work well here.  The second ratio was
%%%% estimated from the scan (leading to \baselineskip=10.97pt).

%%%% The top line is easy to reproduce.  Except when using plain TeX.
%%%% It takes the section sign \S from cmsy10 which doesn't look
%%%% typewriter-like.  Tracing the better LaTeX section sign yields
%%%% \char167 in tctt1000.

%%%% The first diagram with the dots (\extrabox 1) has a simple
%%%% geometry but a couple of challenges in the details:  Each of the
%%%% macros \overharpoon, \TTto, \TTsubscript, \dottedbox took some
%%%% experiments and decisions.

%%%% The diagram for M_2 (\extrabox 2) is the easiest.  As in the
%%%% scan, it is aligned with \extrabox 1.  Label '11' is 'n' in the
%%%% original for which I couldn't figure out a reason.

%%%% The diagram for M_3 in the scan is somewhat unsymmetric.  Drawing
%%%% a regular pentagon would change the shape too much.  On the other
%%%% hand, too much unsymmetry in a technical reproduction would
%%%% rather be a distraction.  I chose to draw a left-right symmetric
%%%% pentagon with the same height and the same length of the base
%%%% (210--120).  It turned out that then point 300 can be chosen so
%%%% that all 5 angels match the angles in the scan.

%%%% The diagram for M_4 has an obvious symmetry along the vertical
%%%% line through the top/bottom points.  The scan is unsymmetric,
%%%% partly due to the scan process itself.  The coordinates were
%%%% chosen to get the lines on the left half match those in the
%%%% original and then let the symmetry do its job.

%%%% A problem is the placement of the labels in M_4.  I don't know a
%%%% recipe for such a complex diagram.  The positions were chosen ad
%%%% hoc, trying to be not too sophisticated (see
%%%% tamari-diagram-labels-large.png).

%%%% About the placement of the arrow tips:  Placing them exactly as
%%%% in the original would distract the eye (and need a lot of work).
%%%% Better have a general recipe for which I chose LatexF at 55%.

%%%% As for the dual diagram M'_4 (tamari-diagram-d-large.png,
%%%% tamari-diagram-d-var-large.png):  I did not try to put the new
%%%% vertices exactly at the centers of the 2-cells of M_4.  I just
%%%% tried to make it fit to the background and recognizable as dual.

%%%% The dual is a triangulated 2-sphere and can be realized as the
%%%% "triaugmented triangular prism" with equilateral triangles.
%%%% However there is no reason to require equilaterality.  The shown
%%%% projection diagrams have the feature that only 1 vertex is hidden
%%%% (and 1 vertex is in front).  I have not seen similar projections.

%%%%%

%% the scan of the 1951 original

%%%% The source is the file St_Tamari-thesis.jpg in
%%%% arXiv-1809.02526v2.tar.gz on https://arxiv.org/abs/1809.02526v2.
%%%% [Jim Stasheff, L_\infty and A_\infty structures: then and now, 2018]
%%%% It has been scaled and extended with

%%% magick St_Tamari-thesis.jpg -scale 301.45% -background \#967E4E -extent 2208 tamari-diagram_orig_extended.jpg

%%%% This format has the same dimensions (2208x1583) as
%%%% tamari-diagram-large.png, for direct comparison.

%% png creation (normal size, transparent)

%%% pdflatex tamari-diagram.tex
%%% pdftocairo -png -singlefile -transp tamari-diagram.pdf tmp
%%% magick -define png:exclude-chunk=date,time tmp.png -trim +repage tamari-diagram.png
%%% optipng tamari-diagram.png

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

%%%% Default resolution of pdftocairo is 150 ppi.  Size of trimmed
%%%% image is 897x632.

%% png creation (large size)

%%% pdflatex tamari-diagram.tex
%%% pdftocairo -png -singlefile -r 361 -W 2208 -H 1583 -x 613 -y 558 tamari-diagram.pdf tamari-diagram-large
%%% optipng tamari-diagram-large.png

%%%% The resolution 361 ppi translates 1pt to 5 pixels (with a
%%%% precision of 0.1%, in TeX have 1in=72.27pt and 5*72.27=361.35).
%%%% Hence 1 pixel in the png corresponds to 0.2pt.  A TeX rule
%%%% becomes 2 pixels wide.

%%%% trim parameters:
%%% magick tmp.png -format "%@\n" info: %% 2160x1523+637+600
%%%% left/right/top/bottom padding is 24/24/42/18 px matching the
%%%% original scan

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

%%%%%

%%%% The project started as innocent playful experiment in February
%%%% 2025.  The images from the first versions

%%%% tamari-diagram.tex        2025-02-27
%%%% tamari-diagram-boxes.tex  2025-03-26
%%%% tamari-diagram-h.tex      2025-04-07
%%%% tamari-diagram-labels.tex 2025-04-18
%%%% tamari-diagram-d.tex      2025-06-09
%%%% tamari-diagram-d-var.tex  2025-06-29

%%%% look already like the current versions (at least from a
%%%% distance).

%%%% Latest change of images:
%%% 2025-08-01
%%% 2026-02-06 (vertical shift of \TTto)
%%% 2026-03-01 (outer sep=0pt)

%%%% Latest code change:
%%% 2026-03-01

%%%% Latest change of comments:
%%% 2026-03-04 (captionM)

%%%%%%
