Jun 26

Last LaTeX Tips for Your Thesis – The TikZ Package and Editing with Vim-LaTeX

This post finishes the series of blog posts on LaTeX for your thesis. I will quickly introduce:

  • the best LaTeX graphics package I know
  • my LaTeX typing environment using vim

TikZ ist kein Zeichenprogramm (TikZ is not a drawing programme)

This is probably the best graphics package available, it feels like you can do anything you like with it and the output looks highly professional. However, it takes a bit time to get used to. The start is very easy, these two lines enable the library and some components which I found useful (you might want to enable those only when you actually need them).


There are multiple layers of its use, you can start drawing simple lines, but higher-level parts provide support for graphs, mind maps, bezier curves etc. Here is a simple example for an illustrated finite-state machine:

%in the document
\node(pseudo) at (-1,0){};
\node(0) at (0,0)[shape=circle,draw]        {$q_0$};
\node(1) at (2,0)[shape=circle,draw]        {$q_1$};
\node(2) at (4,0)[shape=circle,draw]        {$q_2$};
\node(3) at (6,0)[shape=circle,draw,double] {$q_f$};
\path [->]
  (0)      edge                 node [above]  {b}     (1)
  (1)      edge                 node [above]  {a}     (2)
  (2)      edge                 node [above]  {b}     (3)
  (2)      edge [bend left=30]  node [below]  {a}     (0)
  (0)      edge [loop above]    node [above]  {a}     ()
  (1)      edge [loop above]    node [above]  {b}     ()
  (3)      edge [loop above]    node [above]  {a,b}   ()
  (pseudo) edge                                       (0);

As you can see, lines are terminated by a semicolon, so you can whitespace-format your code to make it well-readable. The resulting image is a vector graphic (whereas my screenshot of it isn’t…):

Of course this is only a small fraction of what you can do. In fact the package is so versatile that people actually made a website full of TikZ-Examples (including pictures of the results). The complete guide can be found in the official manual, which is well-illustrated using TikZ itself. The name PGF relates to the lower layer of the package.

Editing with vim-latex

If – and only if – you are a fan of and proficient in vim anyway, I recommend the LaTeX-Suite for vim (a.k.a. Vim-LaTeX). One of the biggest benefits is obviously that you can still do things like ct, (replace the text until the next comma) while editing LaTeX. However there are many more things added specifically for LaTeX editing.

A very useful combination is autocompletion together with jump markers. E.g. if you type matrix and then press <F5>, vim-latex replaces that with



where your cursor is placed in the middle of the matrix environment. Now you can put in the desired content and then press Ctrl+j to move the cursor directly to the marker <++> (which is then removed). This works also for eqnarray, tabular etc. Not needing to type all those curly braces is very relieving. This also works for smaller commands, e.g. `2 is replaced by \sqrt{}<++> and `/ is replaced by \frac{}{<++>}<++> (cursor between the first pair of braces in each case). Needless to say that you can also add your own templates.

Furthermore you can compile and show the pdf file directly from vim using (in command mode) \ll and \lv respectively. Folding and syntax highlighting go without saying. Here are some of the definitions I use in my ~/vim/ftplugin/tex/texrc to further speed up typing:

" start compilation and show pdf even faster
nmap \\ :w<CR>\ll
nmap \v \lv
nmap \a \\ \v

"start environments for italic, bold, typewriter, mathbb or mathmode

imap <C-i> \textit{XXX}<++><Esc>?XXX<CR>cw
imap <C-b> \textbf{XXX}<++><Esc>?XXX<CR>cw
imap <C-t> \texttt{XXX}<++><Esc>?XXX<CR>cw
inoremap <C-n> \mathbb{XXX}<++><Esc>?XXX<CR>cw
"same in visual mode

imap <C-k> $$
vmap <C-i> "zdi\textit{<C-R>z}<ESC>
vmap <C-b> "zdi\textbf{<C-R>z}<ESC>
vmap <C-t> "zdi\texttt{<C-R>z}<ESC>
vnoremap <C-n> "zdi\mathbb{<C-R>z}<ESC>
vmap <C-k> "zdi$<C-R>z$<ESC>

It is also a good idea to use vim’s spelling support (independent of vim-latex) for your thesis. Just put

set spellfile=~/.vim/spellfile.add
set spelllang=en_gb

into your ~/.vimrc and enable it only for your thesis using a so-called mode line. This is done by making the following line the last in your .tex file:

% vim: set spell:

You can then add good and bad spellings into the spellfile using the :spellgood and :spellwrong commands.

For now this concludes my blog series about LaTeX for your thesis. Please tell me if I have missed important tips or packages or you would like to contribute a guest article.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>