summaryrefslogtreecommitdiff
path: root/macros/latex209/contrib/timeline
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex209/contrib/timeline
Initial commit
Diffstat (limited to 'macros/latex209/contrib/timeline')
-rw-r--r--macros/latex209/contrib/timeline/timeline.sty118
-rw-r--r--macros/latex209/contrib/timeline/tl-sample.tex20
2 files changed, 138 insertions, 0 deletions
diff --git a/macros/latex209/contrib/timeline/timeline.sty b/macros/latex209/contrib/timeline/timeline.sty
new file mode 100644
index 0000000000..59223b360a
--- /dev/null
+++ b/macros/latex209/contrib/timeline/timeline.sty
@@ -0,0 +1,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
diff --git a/macros/latex209/contrib/timeline/tl-sample.tex b/macros/latex209/contrib/timeline/tl-sample.tex
new file mode 100644
index 0000000000..fbfa9f39a4
--- /dev/null
+++ b/macros/latex209/contrib/timeline/tl-sample.tex
@@ -0,0 +1,20 @@
+\documentstyle[timeline]{article}
+\def\TeXMaG{T\kern-.1667em\lower.5ex\hbox{E}\kern-.125emX% TeX part
+ M\kern-.1667em\lower.5ex\hbox{A}\kern-.2267emG}
+\begin{document}
+This is a timeline of the history of \TeXMaG.
+\begin{timeline}{2in}(0,180)
+\optrule
+\item[12]{Jan. 24}{Volume 1, Number 1}
+\item[33]{Mar. 6}{Volume 1, Number 2}
+\item[43]{Mar. 25}{Volume 1, Number 3}
+\item[81]{May. 13}{Volume 1, Number 4}
+\item[102]{Jun. 25}{Volume 1, Number 5}
+\item[132]{Aug. 24}{Volume 1, Number 6}
+\item[160]{Oct. 10}{Volume 1, Number 7}
+\item[179]{Dec. 31}{The distant future}
+\end{timeline}%% There needs to be a comment here, unfortunately.
+This text should not be indented at all. I'm going to keep on going
+to see what happens, because the best way to test these things is to
+have the text longer than one line.
+\end{document}