# Using Python to Make a TikZ Timeline

TikZ is a drawing language for LaTeX that can produce all sorts of diagrams, including commutative diagrams with the tikz-cd package, which is possibly the best package for commutative diagrams, at least with regards to typesetting quality and usability. Sometimes when you draw a diagram, though, you might want a little more programming language thrown in to make drawing easier. A classic example is a timeline. Though probably not useful for research math papers, a timeline could be helpful for a survey paper or history text.

Suppose you have a tab-delimited text file of dates of birthdays:

1809-02-12	Charles Darwin
1822-12-27	Louis Pasteur
1826-09-17	Bernhard Riemann
1877-02-07	Godfrey Harold Hardy
1845-03-03	Georg Cantor


You could draw them on a timeline in TikZ directly, but the problem is you'd have to worry about manually calculating how far down the line these dates are. This is a good case where writing a program in Python 3 that outputs the TikZ picture drawing commands is much easier and painless, especially if you need several timelines:

What it does is read the file in, do all the calculations, and ouputs the following TikZ code into a file called "picture.tex":

textlabel/.style={anchor=west,text height=1.7ex,text depth=.25ex}]
\draw (0,0) — (0,10);
\node at (0, 10.0) [datemarker] {};
\draw (0.1, 10.0) node [textlabel] {Feburary 12, 1809: Charles Darwin};
\node at (0, 7.959890463917526) [datemarker] {};
\draw (0.1, 7.959890463917526) node [textlabel] {December 27, 1822: Louis Pasteur};
\node at (0, 7.412210051546392) [datemarker] {};
\draw (0.1, 7.412210051546392) node [textlabel] {September 17, 1826: Bernhard Riemann};
\node at (0, 0.0) [datemarker] {};
\draw (0.1, 0.0) node [textlabel] {Feburary 7, 1877: Godfrey Harold Hardy};
\node at (0, 4.697164948453608) [datemarker] {};
\draw (0.1, 4.697164948453608) node [textlabel] {March 3, 1845: Georg Cantor};
\end{tikzpicture}

You can then include it into a LaTeX document using the tikz package by using the comamnd "\input{picture.tex}" to get: