Saturday, March 08, 2008

Trees using LaTeX

I feel "better" today, but still my heart quivers in fear of the unknown. I have made my to-do list and it's horribly long, which unsurprisingly isn't inspiring. Now though, we return to complete a chapter of my life about trees and LaTeX!

Once upon a time (in a nursery rhyme) I reported about my inability to create a tree using LaTeX. With some help, synttree was the most appropriate package that I could use. Nevertheless, my stubbornness for wanting to do things a certain way prevented me from using this. After that decision I had \sout{borrowed} stole Dr. C's book on LaTeX and decided to draw the trees using brute force i.e. the "put" command and various others which I read about. I read the book, jotted commands down and then set to work. Alas, if only I have continued "working" but the sheer tediousness of my job prevented me from doing so.

Dr. C had mentioned that he used Adobe Illustrator to draw his images, and then he imports them. Sick of measuring distances, I came across a site where someone mentioned "Star Office" in the same breath as adobe illustrator. I already have open office so thought it was similar to that and decided to google it. Open googling the drawing package for Star Office, I was saddened to see that you have to purchase it. I didn't want to go back and measure anything else! However, it seems that the "powers that be" had made me suffer enough, and I smiled when I saw a 90 days trial available for free. There--you have my confession in words. I downloaded the trial version of Star Office and got down to drawing my tree the way it should be drawn! (Since the date for handing the coursework in has expired, can I put that tree online or not?)

Star Office allows you to convert documents into pdf form. Doing this I then print screened the tree and imported it into TeXnic Centre using:


It did look slightly wonky, but I had my tree and that in no time at all! However upon printing it I realised that the image wasn't very clear, and I had to go over the braces in pen. Dr. C suggested that I embolden them before pasting it, but star office is unfortunately not as good as LaTeX and won't allow you to do a lot of things.

Some time later in the week, as I had discussed the format of the third Galois Group idea, Dr. C had suggested I could use LaTeX and import all individual pdf files into one document. "Wait you can import pdf files into LaTeX?" I had asked surprised. It seems you could and I had assumed that he had imported png files like myself, rather than asking.

So I returned to my desk and got to work. Initially when I imported the pdf file, I realised that the whole page was imported and not just the picture. No amount of scaling worked, and I turned towards google (as always!) After a lot of playing around, I realised that my best bet was to use the "trim" option and crop all parts of the file not required. To use the trim option you have to first write "clip=true" for reasons unknown to me. With a lot of trial and error I got it down to:

%trim=l b r t (l=left b=bottom etc. and you just write what length you want to trim there).

\includegraphics[clip=true,trim=1.6cm 15cm 2cm 1.8cm,keepaspectratio,scale=0.96]{beth.pdf}

The end product this time around was just how I wanted it to be! It's not my fault I wanted it like that... but doesn't it look cool? (Unless of course I made a mistake which I would prefer not to be told of!!)

So, what would I recommend to anyone else wanting to draw trees using LaTeX? If you are not willing to compromise on the way you want your tree, get open office and its drawing package. Yep--I've just looked in my open office directory and realised that it came with a drawing programme too, so you don't need star office. If you have complex mathematics, then open office might be frustrating but it's much better than word. Create your picture and convert it into a pdf file. Then open TeXnic Center and import the file using the above commands. Just simply great. You don't compromise on the quality of the tree you see, and when I printed it out, I had to sit myself down for a second! (Haha, it had that great an effect on me you see...)


Jake said...

The tree looks good. I would have persevered with synttree though. I used that in the syntax is really simple and it made doing the tree fairly quick and easy*. I'll show you the code and the finished product if you like.

*The main difficult part was that for some reason the macro can't parse comments as part of the code so you just have to hope you don't make too many mistakes as they can be hard to spot e.g. like missing $s etc.

Beans said...

Hi Jake,

I think I spent way too long trying to find a suitable package, that would give me exactly what I wanted! (No such package exists it seems!) It would be great if you could show me. At least then there exists a suitable way of constructing the tree in LaTeX, rather than my "loophole".

Beans said...

By the way, (I'll edit this into the post later) but if you are wanting to import pdf or image files into your LaTeX document, make sure that the file is saved where the .tex file is saved. (Otherwise it won't build the document).