Archive for February, 2007

The da Vinci Code

Wednesday, February 21st, 2007 | Personal | No Comments

A good while ago this ‘spectacular’ movie came out, based on Dan Brown’s novel. When it came out, most critics pretty much eviscerated it for its poor quality. Last week I watched it on DVD, and I have to say… the critics were pretty lenient on it. While the novel wasn’t exactly the pinnacle of literary craftmanship, it was leagues better than the movie. Now, if we neatly sidestep the whole anti-Christian bias in the novel and movie, there are still a great number of unfortunate changes from the novel.

Enter Langdon, the middle-aged bachelor university professor in religious symbolism. Hanks conveys the image of Langdon rather poorly in my opinion, but I’m sure others will disagree.

In the novel, Langdon is disturbed at his hotel room after giving a guest lecture on his latest book. In the movie we see the police officer show up in the middle of Langdon signing books and showing him a picture of Saunière (the guy who died, in case anyone is wondering) in the middle of it all. To the astonished gasps of the attendees. We quickly change the scene to the Louvre where Langdon is to be questioned by the chief investigator, Fachè, as his primary suspect.

In the middle of the investigation, the second main character shows up, the charming Sophie who is a member of the cryptography unit of the Paris police. She arrives with a faux phone message for Langdon telling him that he is in danger and she starts a ploy to ‘free’ him from Fachè. So far so good.

Now, once freed, they start discussing the fibonacci sequence that Saunière has written on the floor and Langdon suddenly guesses that it’s a key to the rest of the message that it’s an anagram for something else. Langdon, a professor in symbolism, sees this, not the female cryptographer who has spent ages learning about substitution ciphers, Vignière ciphers, elliptic curve cryptography and the Gods knows what else. Audrey Tautou is reduced to nothing more than a beautiful side-kick without the brains to go with a degree in mathematics. Pitiful.

Jumping a bit ahead, in the end of the movie, suddenly everything is revealed from Langdon glancing at a few newspaper clips that Sophie is actually of the Saint-Claire family and she is the sangreal. Then the whole Priory of Sion shows up in the church where this revelation takes place, and a woman tells Sophie that she is her grandmother. Now contrast this with the entire premise of the book: only four members of the Priory of Sion knows of the Sangreal: the three sénéchaux and the grand master, now the entire Priory shows up and says ‘by the way, hi, we’re here to protect you’. And then we close up the movie with a bit of philosophical meandering on whether Sophie revealing herself to the world would constitute the final breakdown of the Catholic church and restore the true gospel of Christ, or something to that effect. Honestly!

There is a host of changes from the novel to the movie, hardly any for the better, most for the worse. Wikipedia has a long list of differences for those who are interested in the finer details. I had low expectations for this movie, and even they were let down. The only relatively positive side to the movie was Sir Ian McKellen, as he successfully portrayed Sir Leigh Teabing to perfection.

Just pitiful.

Edit: Just to clarify then I am not regarding the book or movie as fact. I am also not demeaning the book. I am, however, saying that given whatever qualities the book may or may not have had, the movie loses any and all of them.

Tags: ,

Drawing trees in LaTeX

Wednesday, February 21st, 2007 | LaTeX | No Comments

Last time we looked at how we could import graphics in the document using the graphics package. Today, we will look at how we can create vector graphics of trees from inside our LaTeX documents. As there are many aspects of the natural sciences that requires high quality drawings of trees, graphs, etc., it should come as no surprise that there are several packages for LaTeX trying to solve this issue. Some of these are:

There are advantages and disadvantages to all the packages, naturally, mfpic depends on metapost, which takes a certain mindset to use, pstricks works only with latex and not with pdflatex, xypic is primarily for diagrams and graphs, but can also be used for other things, but my definite favourite is pgf, as it works with both latex and pdflatex and generates good-looking output, at least in my opinion.

The pgf package is split in two: an easy-to-use frontend called TikZ and the backend called pgf. Today we’ll be looking exclusively at the frontend and try to draw simple trees with it.

First, let us look at an example of a tree:

\begin{tikzpicture}
    \tikzstyle{every node}=[circle,draw]
    \node {1}
        child { node {2} }
        child {
            node {3}
            child { node {4} }
            child { node {5} }
        }
        child { node {6} }
    ;
\end{tikzpicture}

What is happening here should be fairly self-evident, but let us run over it quickly. The call to \tikzstyle indicates that every node should be drawn, shaped as a circle. As for the tree, we have the root node with a 1 written in it. This root note has three children, of which the middle children has two further children. This gives us the following result (click on the image for the original PDF):

Figure 1

Another useful feature of TikZ is that you can name nodes so you can refer to them later on:

\begin{tikzpicture}
    \tikzstyle{every node}=[draw,circle]

    \node (root) {1}
        child { node {2} }
        child { node {3} }
        child { node (rightmost) {4} }
    ;

    \tikzstyle{every node}=[]

    \draw[-latex,color=red]
        (rightmost) .. controls +(southeast:1cm) and
                                +(right:3cm) ..
            node[near end,above right,color=black] {back}
        (root);

\end{tikzpicture}

In addition to figure 1, we can see that to name nodes we add a (name) after the node command. Once we’ve specified the actual tree, we reset the global style settings for nodes as we don’t want our edge labels having a visible circle around them. The last draw command uses TikZ’ syntax (which is alike to METAPOST’s syntax) for drawing Bézier curves and the embedded node statement is for placing an edge label. The controls statement says that the first Bézier control point is placed 1cm to the south east of the (rightmost) node, and the second Bézier control point is placed 3cm to the right of the (root) node. Thus we can draw lines between nodes easily without explicitly having to state their absolute placement.

The southeast and right in the control nodes are called anchor points in TikZ, and there are plenty other of these. There are, in fact, so many means of customising nodes that it’s impossible to cover it all here. Instead, use the PGF manual. It is very thorough and example-based, so you should be able to find solutions for pretty much everything.

Using the above code snippet we get the following result:

Figure 2

Before we leave the topic of drawing trees with TikZ, let’s look at the different forms of trees one can draw: trees growing downward (we’ve already seen these), trees growing upward, sideways, and trees where the edges fork down rather than go straight down, or where the edges curl down. There are plenty of possibilities. As the last example, let us look at the traditional fork down:

\begin{tikzpicture}
    \tikzstyle{every node}=[draw,rectangle]

    \node {1}
        [style=edge from parent fork down]
        child { node {2} }
        child {
            node {3}
            child { node {4} }
            child { node {5} }
        }
        child { node {6} }
    ;

\end{tikzpicture}

This requires that you add \usepackage{pgflibrarytikztrees} to your preamble, otherwise the fork down isn’t available. Once you’ve done that, this is the result of compiling the drawing:

Figure 3

There is plenty more to the node aspect of TikZ. Indeed, it can also be used to create graphs quite elegantly, and, naturally, TikZ doesn’t limit itself to just trees and graphs, it’s a quite versatile vector drawing language inside LaTeX. In future posts we’ll look at some more of these features.

Tags: ,