summaryrefslogtreecommitdiff
path: root/macros/latex209/contrib/timeline/timeline.sty
blob: 59223b360afcd3587a4fbeedc797d2239434d06c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
%%% Slice------------------------------------------------------------
%%% File: Timeline.Sty
%%% Written to work with either LaTeX or plain TeX
%%%
%%% In LaTeX:
%%% \begin{timeline}{length}(start,stop)
%%%   .
%%%   .
%%%   .
%%% \end{timeline}
%%%
%%% in plain TeX
%%% \timeline{length}(start,stop)
%%%   .
%%%   .
%%%   .
%%% \endtimeline
%%% in between the two, we may have:
%%% \item{date}{description}
%%% \item[sortkey]{date}{description}
%%% \optrule
%%%
%%% the options to timeline are:
%%%      length The amount of vertical space that the timeline should
%%%                use.
%%%      (start,stop) indicate the range of the timeline. All dates or
%%%                sortkeys should lie in the range [start,stop]
%%%
%%% \item without the sort key expects date to be a number (such as a
%%%      year).
%%% \item with the sort key expects the sort key to be a number; date
%%%      can be anything. This can be used for log scale time lines
%%%      or dates that include months or days.
%%% putting \optrule inside of the timeline environment will cause a
%%%      vertical rule to be drawn down the center of the timeline.
 
\catcode`\@=11     % Pretend @ is a letter
\newcount\startat            \newcount\tllength
\newdimen\putithere          \newdimen\itwasthere
\newcount\scr@tchi           \newdimen\scr@tchii
 
% A vertically centered lap
\long\def\ylap#1{\vbox to \z@{\vss#1\vss}}
 
%         Vertical `laps'; cf. \llap and \rlap
\long\def\ulap#1{\vbox to \z@{\vss#1}}
\long\def\dlap#1{\vbox to \z@{#1\vss}}
 
\def\timeline#1(#2,#3){\ifvmode\else\par\fi$$\vbox to#1\bgroup
                                       % The \vbox command is
                                       % surrounded by $$..$$ to make it
                                       % fit in well with paragraphs.
    \offinterlineskip
    \startat=#2\tllength=#3
         \advance\tllength by-\startat % \tllength should be the total
                                       % length of the timeline.
    \def\item{\@ifnextchar[\@item\@itemnosrtkey}
    \def\@item[##1]##2##3{\scr@tchi=##1
         \advance\scr@tchi by-\startat
         \putithere=#1 \divide\putithere by 65536 % to avoid arithmetic
                                                  % overflow
              \multiply\putithere by \scr@tchi    % we only remain
              \divide\putithere by\tllength       % accurate to 1pt in
              \multiply\putithere by 65536        % these calculations
                                       % Now \putithere has how far
                                       % down we should go for this item.
         \scr@tchii=\putithere \advance\scr@tchii by -\itwasthere
         \ifdim\scr@tchii<12pt
              \ifx\lrswitch L \@putright{\putithere}{##2}{##3}
              \else \@putleft{\putithere}{##2}{##3}
              \fi
         \else \@putleft{\putithere}{##2}{##3}
         \fi
         \itwasthere=\putithere
    }
    \def\@itemnosrtkey##1##2{\@item[##1]{##1}{##2}}
    \def\@putright##1##2##3{\dlap
         {\kern##1\centerline
              {\rlap
                   {\ $\bullet$\hskip1.5em{\bf ##2} \ ##3}}}
         \let\lrswitch=R
    }
    \def\@putleft##1##2##3{\dlap
         {\kern##1\centerline
              {\llap
                   {{\bf ##2} \ ##3\hskip1.5em$\bullet$\ }}}
         \let\lrswitch=L
    }
    \def\optrule{\dlap
         {\centerline
              {\dimen0=#1 \advance\dimen0 by 6pt % This calculation is
                                                 % kept local
                   \vrule depth \dimen0 height-6pt}}
    }
}
\def\endtimeline{\vfill\egroup
          \ifx\@latexerr\undefined\else
             \global\@ignoretrue
          \fi
          \vbox{\vskip\baselineskip}$$}
                   % Put the extra \vskip in a \vbox to hide it from
                   % the math gods.
\ifx\@latexerr\undefined
    \def\@ifnextchar#1#2#3{\let\@tempe #1\def\@tempa{#2}\def\@tempb{#3}
         \futurelet\@tempc\@ifnch}
     \def\@ifnch{\ifx \@tempc \@sptoken \let\@tempd\@xifnch
           \else \ifx \@tempc \@tempe\let\@tempd\@tempa\else\let\@tempd\@tempb
                \fi
           \fi \@tempd}
 
     % NOTE: the following hacking must precede the definition of \:
     %  as math medium space.
 
     \def\:{\let\@sptoken= } \:  % this makes \@sptoken a space token
 
     \def\:{\@xifnch} \expandafter\def\: {\futurelet\@tempc\@ifnch}
     \catcode`\@=12   % Let's not pretend @ is a letter
\fi