%%%%%%

%% Comments and notes related with tamari-diagram*.tex.  For the most
%% part, dimensions are discussed.

%%%%%%

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

%%% 10.5pt=21/2pt % \tt 1em
%%% 5.25pt=21/4pt % \tt width (monospacing), \enspace (.5em)
%%% 6.11111pt=55/9pt % \tt cap height (uppercase, digits)

%% get these from
\setbox0\hbox{\tt \quad}
\setbox0\hbox{\tt X}
\typeout{\the\wd0 \space \the\ht0 \space \the\dp0}
%% 10.4999pt 0.0pt 0.0pt
%% 5.24995pt 6.11111pt 0.0pt

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

%%% outer xsep, outer ysep: 1/2\pgflinewidth
%% default: 0.2pt

%%%%%

%% 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 are 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
      %%% ...
      \vss
    }%
  }

  \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 placed as with \vcenter (note: math axis = 2.5pt)
\def\TTto{%
  \hbox to 3\tten{% 15.75pt
    \hss
    \begin{tikzpicture} [baseline=-2.5pt] % vcenter
      \draw[\TTthick,-Straight Barb] (0,0) -- (2\tten,0) ; % 10.5pt
    \end{tikzpicture}%
    \hss
  }%
}
%%% compare \TTto (drawn in red) with $\to$
\def\TTto{%
  \rlap{\hbox to 3\tten{\hss$\to$\hss}}%
  \hbox to 3\tten{% 15.75pt
    \hss
    \begin{tikzpicture} [baseline=-2.5pt,red,opacity=0.5] % vcenter
      \draw[\TTthick,-Straight Barb] (0,0) -- (2\tten,0) ; % 10.5pt
    \end{tikzpicture}%
    \hss
  }%
}

%% monosized subscript for monospaced fonts
\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, we cut at 0.55 (instead of 1/2)
%%% of the full line.

\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)!1/2!(#3)$),
  \p1=($(\p0)!6pt!(#3)$) 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{
  \begin{scope} [#1]
    \draw let
    \p0=($(#2)!1/2!(#3)$),
    \p1=($(\p0)!5pt!(#3)$) in
    (#2) edge[-LatexF] (\p0) (\p1) -- (#3) ;
  \end{scope}
}

%% \BULLET - nothing to comment

%%%%%

%% \showTMCaption*

%%% A \node[\below] has an intrinsic separation by inner ysep (3.5pt)
%%% and outer ysep (0.2pt).  This means that
\node[\below=-3.7pt] at (XXX) {LABEL} ;
%%% attaches the label directly underneath without any separating
%%% space.

%%% clearances of M_* captions are proportional to font size
\def\TMCaptionClearA{1.095*8pt-3.7pt} % 8.76pt
\def\TMCaptionClearB{1.2*8pt-3.7pt} % 9.6pt
\def\TMCaptionClearC{1.44*8pt-3.7pt} % 11.52pt

%%% To make the clearance independent of any other decorations it is
%%% placed at (XXX.base) if necesssary.

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

\def\TMCaption#1#2{$\hbox{#1 M}_{\hbox{#2}}$}

%%% don't let the \prime in M'_* move the caption down
\def\TMCaption#1#2{
  \setbox0\hbox{#1 M}%
  \setbox1\hbox{$\copy0'_{\hbox{#2}}$}%
  \ht1=\ht0 \box1}

%%%%%

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

    %%% ...

    %%% 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[left] (2011N) at (2011) {2011} ;
    \node[inner xsep=0] at ([xscale=-1] 2011N) {2200} ;

    %%% ...

  \end{tikzpicture}%
}

%%%%%%
