Using Relative Units in TikZ Drawings

I used to happily create TikZ drawings with pt units, let’s say in a paper using the IEEE style:

\documentclass{IEEEtran}
\usepackage{tikz}
\usetikzlibrary{positioning}
 
\begin{document}
\begin{tikzpicture}
\node[text width=60pt] (mor){Morphological Analysis};
\node[text width=35pt,right=12pt of mor] (syn) {Syntactic Analysis};
\draw[-latex] (mor) -- (syn);
\end{tikzpicture}
\end{document}

The output looks good enough, although I did have to try several times getting the text widths right:

But often times I’d want to reuse my TikZ code in other documents, e.g. a Beamer presentation, or my thesis in which I must use Times 11pt. But when I happily copied over my Tikz snippet over, I get:

\documentclass{beamer}
...
\begin{tikzpicture}
...
\end{tikzpicture}
...
\documentclass[11pt]{memoir}
\usepackage{mathptmx}
...
\begin{tikzpicture}
...
\end{tikzpicture}
...

Ouch, it looks like I need to figure out the different text width values in pts by trial and error, for each document I want to include my picture in!

Or do I?

The real issue here is that pt is an absolute unit (1pt = 1/72 inch), so my TikZ node’s text width stays the same while the font metrics is different in each document. Using relative units, like em or ex, would make my life a lot easier.

Let me explain: 1em is the height of the current typeface in the current size, and is a little bit wider than a capital ‘M’. This means the length/width 1em depends on the active font family and size.

And as a rough estimate, a capital ‘M’ is twice as long as a lowercase letter. ‘Morphological’ has 1 ‘M’ and 12 lower case letters, but 3 of these are ‘thin’ letters (‘l’ and ‘i’), so I’d go with 6em rather then 7. Similarly, I’d try 4em for ‘Syntactic Analysis’.

Let’s see the results, using the same TikZ code in all three versions (IEEE paper, beamer and typical thesis):

\documentclass{IEEEtran}
\usepackage{tikz}
\usetikzlibrary{positioning}
 
\begin{document}
\begin{tikzpicture}
\tikzset{every node/.style={draw,align=center}}
\node[text width=6em] (mor){Morphological Analysis};
\node[text width=4em,right=1em of mor] (syn) {Syntactic Analysis};
\draw[-latex] (mor) -- (syn);
\end{tikzpicture}
\end{frame}
\end{document}
\documentclass{beamer}
...
\begin{tikzpicture}
...
\end{tikzpicture}
...
\documentclass[11pt]{memoir}
\usepackage{mathptmx}
...
\begin{tikzpicture}
...
\end{tikzpicture}
...

There! The text widths would vary relative to the current font families and sizes in use, so I won’t have to fiddle around with pt values for every new document I want to incorporate my existing TikZ code.

Creating Academic Posters (and Printing Them)

I presented a poster paper at CICLing 2011 in Tokyo (that was the end of February so I wasn’t there during the earthquake, but it seems the organising committee members are all alright, thank heavens) and I naturally created my poster with LaTeX. Here’s a thumbnail of my poster:

I created this A0-sized poster (source code the TikZ drawings and CJK characters are externalised as PDF graphics and the bibliography embedded, so it should be compilable on most LaTeX installations without extra packages) with the beamerposter package, mainly by modifying Rob Hyndman’s style file. (There are other packages for creating posters in LaTeX, see this link for an overview.)

You can download my .sty and a simple sample poster .tex files here. I’ve put the colour themes (ComingClean in the left thumbnail, ConspiciousCreep on the right, inspired by this and this respectively) in their own separate .sty files. ConspiciousCreep is probably not so suitable for an academic poster… but perhaps it could be useful for a not-so-serious occasion.

Note that the sample poster is A1-sized; change the poster size in the .tex file as you require. I also defined a \footimage command that can be used to put whatever material you want in the bottom right hand corner. (I included photos of the authors in my poster not because of vanity, but because the organisers asked us to do so, so that it’d be easier for participants to locate the relevant authors.)

I brought my A0-sized PDF along to a printing shop who happily printed it out on one glorious giant A0-sized synthetic paper material. However, if you have trouble finding a printing shop who can print out these big sizes, you can use the pdfposter utility (available on all major GNU/Linux distros) to process your PDF into smaller-sized tiles. For example, if the input LLTposter-sample.pdf is A1-sized, then

pdfposter -s1 -ma4 LLTposter-sample.pdf a4tiles.pdf

will take the input file LLTposter-sample.pdf, split it into 8 A4 pages and save them in a4tiles.pdf. You can then print out the A4 pages and assemble them back into an A1-sized poster at the conference venue. (-s1 means no resizing of the original poster size, hence A1 as the result.) Enjoy!

Coffee stains on your PDF docs

It’s funny and seems pointless, but you may want to play around

Taken from here

Here what I got:

And important point is that, it does not work with pdflatex, use latex compiler instead

(Thanks Toriq for this package. How on earth did you ever came across this package anyway? 😉 )

Update: coffee2.sty works with pdflatex, thanks Sharuzzaman and Curutari for pointing that out. I didn’t check the current sty after I downloaded the old one.

“Why isn’t Arial in my LaTeX installation by default?”

“Or Cooper Black, or a bunch of other fonts? They’re free, aren’t they? They’re already there on my computer!”

If you’ve ever wondered about this, this article on Free Fonts: Free Is Not Always Free may help you understand some of the underlying issues about font licensing. (Some people would argue that the M$-bundled fonts are of inferior quality compared to the real stuff anyway e.g. Times Roman, Helvetica etc)

On the other hand, rest assured that all is not lost as there are free clones of many of such fonts that you can use in your LaTeX documents anyway.

For example, \usepackage{mathptmx} loads Nimbus Roman, a look-alike for Times Roman, while \usepackage{helvet} loads Nimbus Sans to stand in for Helvetica, which is pretty much indistinguishable from Arial — to the untrained eye anyway.

One last thing: You can still use some non-free fonts: install them using the getnonfreefonts script.

One really last thing: The last thing I want to do is to start a font war on this blog, so please spare me the hate mails! 😉

Tamil and Hindi Support in LaTeX

Doing a post on typesetting Tamil and Hindi is only natural after sorting out Jawi and CJK! Just after I managed to get them working using the itrans package and the devanagari fonts, this exact question was asked on the TeX-LaTeX Stack Exchange site, to which I posted what worked for me. So this post is essentially a re-write of my answers there.

(These instructions are LaTeX-only; I’ve not dabbled much in XƎLaTeX.)

Installation on Ubuntu (TeXLive)

This one’s easy. Grab the itrans and itrans-fonts packages for Tamil, and also the texlive-lang-indic package for the Hindi fonts via synaptic (or apt-get).

Installation on Windows XP (MikTeX)

Grab the devanagari package using MikTeX’s Package Manager. As for itrans, since it’s not packaged properly in MikTeX, so we’ll need to install it manually. Download itrans53-win32.zip from CTAN. After unzipping the contents (say C:\itrans53\), assuming being your local TEXMF tree,

  • Move the contents of the lib folder into \tex\latex\itrans
  • Move the contents of the fonts folder into the appropriate locations, i.e.
    • *.mf in \fonts\source\itrans
    • *.afm in \fonts\afm\itrans
    • *.tfm in \fonts\tfm\itrans
    • *.pfb, *.pfa, *.pfm in <texmf>\fonts\type1\itrans
    • *.ttf in \fonts\truetype\itrans
    • *.fd in \tex\latex\itrans
  • Refresh the file name database (e.g. via MikTeX Options/Settings)

Using itrans

itrans doesn’t let you type in Tamil or Hindi (or Marathi, Sanskrit, Telugu and Gujarati) directly, rather you have to key in the ASCII transcription, then process it with itrans from the command prompt, then run (pdf)latex on the resultant file.

Say I have the following file indic-pre.tex:

\documentclass[11pt]{article}
\usepackage[preprocess]{itrans}

\newfont{\tmlb}{wntml12}
\newfont{\tmls}{wntml10}
\newfont{\devnf}{dvng10 scaled \magstep1}
#tamilifm=wntml.ifm
#tamilfont=\tmlb
#hindiifm=dvng.ifm
#hindifont=\devnf

\begin{document}
Thank you!
{#tamil na^nRi #endtamil}
{#hindi dhanyavaad #endhindi}
\end{document}

Process it with itrans: (Windows MikTeX users need to change path to itrans53\bin to evoke itrans.exe

$ itrans -i indic-pre.tex -o indic.tex

Then run (pdf)latex on indic.tex, which is of course the file to edit if you have further text to add. Here’s the output of that little file:

Hold on! How’d you know you needed to type na^nRi etc?

I peeked at the transliteration map files ☺. For example, tamil.ps for the Tamil transliteration, dvng.ps for the Hindi (devanagari) transliteration, etc. If your LaTeX set up doesn’t install these files by default, you can download the package source .zip and look in the doc folder. The .itx files are sample source .tex files that generated the .ps files.

New (La)TeX Q&A Site

I’m sure many people have looked up Stack Overflow for programming-related Q&A. Well there’s now a similar community-driven LaTeX-specific Q&A site: TeX, LaTeX and Friends. Here’ a short snippet from the site FAQ (my own emphasis):

What kind of questions can I ask here?
TeX – LaTeX – Stack Exchange is for expert users of TeX, LaTeX and other related typesetting systems. Please do look around to see if your question has already been asked (and maybe even answered!) before you ask.

What kind of questions should I not ask here?
Avoid asking questions that are subjective, argumentative, or require extended discussion. This is not a discussion board, this is a place for questions that can be answered!

After just 7 days in private beta, the site has 323 users and 658 answers to 242 questions. With many (La)TeX experts already onboard answering questions, this is definitely one for the bookmarks (especially if you still can’t get used to comp.text.tex!)

April Fool came late this year

River Valley TV has posted the video of Donald Knuth’s “earth-shattering” announcement at the TUG 2010 Conference about a “successor to TeX” that he’s been “secretly working on”.

Utterly hilarious, in which Prof Knuth parodies almost every single recent software and technology trends. And taking lots of “inspirations” from the c.t.t. newsgroup posts methinks. 😉 (Gotta love the transparencies too. Really takes me back to my undergrad days…)

As many have commented on the Web, “April Fool came late/early” for TeXies!