Tuesday, January 25, 2011

Pragmatic Diary with LaTeX

A while ago, I decided to write something like a personal diary, and wanted to do it with LaTeX. I wanted to have a pragmatic environment, which is established when typing a simple command.

Before I describe the implementation, I would like to describe this environment:
  • When I run the command diary, an instance of kate opens a file named with the current date (e.g. 2010-12-09.tex, located in a directory, let's say $DIARY)
    • If this file exists, then a warning appears, and it is opened
    • Otherwise, this file is created
  • This file contains a skeleton for a LaTeX document, where I immediately can start writing down my thoughts
  • In the terminal-area of kate, I simply have to type pdflatex 2010-12-09.tex to compile the tex-file into a PDF.

And here is how I implemented it.
The template for the LaTeX-skeleton looks as follows (file named $DIARY/template.tex):


Here goes the text

The file $DIARY/macros.tex contains document and package definitions, that define the common properties for all tex-files, and hence a unique look for all resulting pdf-files.


The script, that launches when typing diary is the following ($DIARY/diary.sh):

TODAY=$(date +"%Y-%m-%d")
if [ -f $TEXFILE ] 
  zenity --error --text "Tex-File $TEXFILE already exists!!!"
  cp $BASE/template.tex $TEXFILE

kate $TEXFILE &
cd $BASE
pdflatex $TEXFILE
okular $PDFFILE &

Some notes:
  • zenity simply pops up a dialog box with the given warning
  • okular is my favorite PDF viewer - in fact it could be any other viewer
Finally, I made a softlink to $DIARY/diary.sh in /usr/bin.

By the end of each year I might create a document named diary-201x.pdf, which includes all entries and is a nice compilation of my diary entries. For instance, this could be done with the pdftk. (pdftk *.pdf cat output diary-201x.pdf)

P.S.: You may wonder, why I'm mixing Gnome and KDE software. I'm working with Ubuntu and have some KDE-packages installed. Well, that's my environment, and I'm very fine with that. If you are Ubuntu-User, too, you will find all of the necessary software in the Ubuntu repositories (sudo apt-get install XXX, whereas XXX stands for kate, okular, zenity, pdftkm, etc.)

No comments:

Post a Comment