LaTeX Beamer Theme Previews

May 19, 2009

Update (09/07/2010): It was brought to my attention that the help message printed by beamerizer referenced \include instead of \input. I updated the the help message to now use \input which is the better choice. Thanks to ArkanoidX for pointing this out 🙂

I have been using LaTeX beamer for a little over a year now to do my “PowerPoint” like presentations for math and computer science classes. I really like beamer a lot and I find it easy to put together a nice looking presentation that is not bogged down in special effects and gimmicky animations. One of my main problems with beamer is that I never know what theme to pick because I never know what the themes look like ahead of time. This is what made me think that it would be nice to have a script that automatically builds my presentation with every possible theme and puts them in one giant pdf file.

It turns out that by using Python and some nice Linux tools it is fairly easy to achieve this. I call the little script I wrote “beamerizer” and it takes a directory of LaTeX themes and a LaTeX source file. Then, it builds that source file with every possible theme. It’s a pretty simple idea, but it gets the job done. I have also used this script to produce a nice sample document that was built using the standard LaTeX themes. Both the beamerizer script and that sample document are included in this post. Hopefully this will help someone out who needs to see all the different beamer themes 🙂 .

Beamerizer Python Script: beamerizer.tar.gz (requires that “gs” and “pdflatex” be installed)

Theme Preview File: BeamerThemePreview.pdf

(For those of you who are interested: all beamerizer really does is generate a pdf file for each theme and then use the “gs” command to concatenate all the pdf files together)

Python 2.5 and encryption — PyCrypto under Windows

July 20, 2008

[Edit: 8-13-08] – Upon request I have provided a link to an installer for PyCrypto-2.0.1 that is compiled for Python 2.5. You can download it here . I didn’t post it originally because I was not sure how long I could provide a link for. This one should be good for about a year … 🙂 .

Note: The steps listed here will only work on Python 2.5 and above as that is when they added support for allowing MinGW to compile code

I mentioned in a previous post that I was looking for a way to get public/private key encryption in Python and I was having a bugger of a time until I found ezPyCrypto. I don’t know if I have mentioned this before, but I have been an Linux user for about 4 years now. Specifically Gentoo Linux ,and I would never run another OS now that I have been a Linux user. At any rate that’s not the point of this post. Since the script I was developing had to run on Windows I needed to install PyCrypto (it’s a dependency for ezPyCrypto). Well this would be trivial except that PyCrypto has C code that needs to be compiled. There are binary builds on the PyCrypto site for both Python 2.3 and 2.4, but not 2.5 which I am running. I wasn’t going to let this stop me however. The rest of this post will explain what you need to do in order to get PyCrypto working under Windows with Python 2.5. After completing this you will also be able to build your own installer that you could package with your scripts to let people who don’t want to install a C compiler run your code 🙂

The first thing you are going to want to do is install MinGW . MinGW will give you a nice C and C++ compiler for Windows. Just follow the instructions on their site and you will be good to go. After you have MinGW installed you will probably want to add entries to the Windows PATH variable so that when you are in a terminal you will be able to directly access MinGW. [As a note I still run Windows XP so these instructions will be done with that in mind] Doing this is quite simple:

  1. Right Click My Computer –> Properties –> Advanced –> Environment Variables.
  2. You will see User and System variables. If you want all users to use MinGW edit the Path entry in there. Otherwise add a Path variable under User variables.
  3. Go to the Path variable from step 2. Add an entry to the Path that points to MinGW’s bin directory. For me this was “C:\MinGW\bin” but it all depends on where you installed MinGW. Note: Entires in Windows Environment variables are separated by ‘;’
  4. Click ok a bunch of times

While you are changing environment variables you will want to add the main directory for Python to your path. For me this was: “C:\Python25”. This made my final User Path entry: “C:\MinGW\bin;C:\Python25”

Now that you are done changing environment variables you will want to reboot your computer so that Windows gets your changes. Really… you will regret it if you don’t reboot!

Now download PyCrypto and unpackage it. This turned out to be problem enough because not many people keep programs around that open .tar.gz files. Since am a Linux user I just unpacked them in Linux and transferred them to Windows (I run Windows XP under VirtualBox ). However, if that is not an option you can download and install IZarc Archiver. IZarc has been my favorite [Windows] extraction tool for a long time and it supports just about every archive format imaginable.I would recommend extracting the contents of PyCrypto to your desktop. Now is when the first starts!

First, open up a terminal. We will only be using a few commands and you don’t have to be a terminal wiz kid to do this. I normally open a terminal by going: Start –> Run –> “cmd” –> Press Enter

Now that you have a terminal up you want get to the PyCrypto directory. To move between directories in the terminal we use the “cd” command.


So, for example here is the command I used to get to where I had PyCrypto:

cd C:\Documents and Settings\Jinto\Desktop\pycrypto-2.0.1

Of course that command will only work for you if your user name is Jinto and you extracted it to the desktop exactly like I did 😉 So modify it to fit your needs. Once you are in the pycrypto directory do a quick:

dir /w

To make sure you see files. Specially make sure is there. We need to run that setup script and tell it to build the libraries. To do this issue the following command:

python build -c mingw32

If all goes well it should build without any troubles and all that is left is to install it by issuing the following command:

python install

You should be all set to use PyCrypto now, or to install ezPyCrypto which uses PyCrypto. As a bonus feature if you are looking to make an executable installer for PyCrypto you can run the following command:

python bdist_wininst

This will leave you with a .exe file located in the “dist” folder.

I hope this helps everyone get PyCrypto running under Windows. For those of you Linux users who think I am leaving you out check your distro specific respository system they probably already have a package for PyCrypto!

Reading all the Documentation…

July 19, 2008

So apparently when people the time to write something down they wrote it down for a reason. I happened to have missed this simple fact recently when I was working on some Python scripts. I was trying to separate the scripts into different folders based on what they did. Simple enough, but then I ran into the issue of certain scripts needing to go around folder boundries. Of course, Python supports this feature using it’s import system.

This is where my trouble was. I was reading the article about how import works from the standard Python docs. So I read as much as I thought I needed and skipped over, what I thought at the time, to be unimportant. As it turns out the ability to do relative imports using ‘..’ is a feature of only Python 2.5 *sigh*. Alright, so I could have just installed Python 2.5, but I didn’t want to limit this code to running on Python 2.5 for no good reason. So I went back and changed the code to using absolute imports which took around 30 minutes because there were a decent number of files to play with.

So how did I miss this in the documentation? Well I managed to skim over the part which mentions this is only for Python 2.5 (I blame myself for this, btw). I take this as a lesson to pay closer attention when reading documentation. It may have taken me an extra 5 or 10 minutes to read all the documentation about imports and Python… but I will would have saved half an hour of my time if I had taken the extra effort 🙂

BROWNIES! — The Programmer’s Moment

July 8, 2008

There I was… testing my Python scripts to remotely adminster the radio station computers. I had been coding for a few hours trying to add support for remote admin logins. This required having the server send a public encryption key, letting the client get the potential password from the user, encrypting it with the key, sending it back to the server, having the server decrypt the potential password. Then… I saw it: “Password is:brownies”  shining brightly in the terminal running on the server. Proof of success at long last!

It is that feeling that I call ‘The Programmer’s Moment’ it’s a feeling of overwheling success because you just spent x amount of time on a feature, and you are finally convinced it is going to work like you planned. I am sure other professions experience this same sense of accomplishment, but I experience this most frequently when I am coding. It’s that feeling that makes long nights (or days) staring at a screen worth anything at all. It can motivate you to continue coding and keep you from giving up on a project that seems hopeless.

Here is a little screen shot of that terminal with such simple text that brought some happiness to this crazy coder 🙂

Finally... got the password being sent over the network

Finally... got the password being sent over the network

Python and public/private key encryption

July 5, 2008

Edit (7/20/08): If you are looking to get PyCrypto running under Windows with Python 2.5 I wrote a short guide located here . There are already installers for Python 2.3 and 2.4 on the PyCrypto Homepage

Edit (7/10/08): After noticing that this got some hits on google I rearranged the content so that the first part explains how I got public/private key encryption in python and the second part explains why I wanted encryption in the first place.

I was looking for an easy way to do public/private key encryption in python and I found it!

Enter ezPyCrypto! This package was actually able to generate and export a public key as a string AND import it back in. I should also mention that ezPyCrypto is merely a wrapper for PyCrypto. I have to say ezPyCrypto was quite uh… easy. Here is an example of how you would make a 1024 bit RSA key and export it to a string. It also demonstrates how to import that key and use it to encrypt a message:

from ezPyCrypto import key

myKey = key(1024) #defaults to RSA, 1024 is bits to encrypt with

#Just calling exportKey will export only the public key
publicKey = myKey.exportKey()

#print publicKey  

#Then to load it back in to a new key
myNewKey = key(0)

#Testing time!
testEnc = myNewKey.encString("cheesecake tastes yummy")

#You should see 'cheesecake tastes yummy'
print myKey.decString(testEnc)

Look at how easy that is! I am quite pleased that I will be able to continue my work, and have some good encryption. The one thing I will say is that ezPyCrypto does not seem like it has seen much development in a while, but oh well. As long as it works when it needs to I will not complain 🙂 Also I only tested this with python-2.5 so your mileage may vary. On to the back story…

So today, among other things, I was looking for some good python libraries to do public/private key encryption. I am trying to write a few scripts that help with the administration of the computers I work on for my college’s internet radio station. I started out writing them all in perl, but now I have most of them written in python. Currently I have written a small backend which starts up the basic services that the radio station requires. At present that consists of: shoutcast server, darkice, a script to monitor the listener counts, and lighttpd. This backend is capable of accepting clients over the network and displaying the basic running status of all these services (IE: running or not). Now, I would like to add the ability to remotely control the services. Hence I would have to have some way of authenticating users who want to log in.

Lets take a step back here. Some of you might be wondering why I don’t just administer everything with ssh. Indeed, this is how I did it for a year, and for someone like me (I loves me a good terminal) this was not a problem. However, I have to face the reality that someone will probably take over the station (at some point or another) who is not at one with bash. This is why I decided to start this project to help ease them into administering the servers, which rarely die anyway. Python and the Tkinter libs were great for this because they would be fully cross platform. Although I hate to admit it, I think the next admin will probably be a Windows user. I think being able to run the server from their dorm will go a long way in helping them accept the job.

Back to the main problem. To authenticate I don’t plan to have anything too breathtaking. The backend will be run as a normal user and I plan to use PAM to authenticate against the user that is running the backend. So I need to be able to send the password over the network! There are plenty of guides to public/private key encryption and a quick google search will provide an explanation better than I will ever be able to give as to how they work. I was able to find a few options. The first is the PyCrypto package. This package seemed quite sufficient but the lack of reasonable documentation for it made me have second thoughts. This isn’t something I want to mess up because we are sending sensitive data across the network. I had a look at the source code but got tired of trying to make sense of it.

Next I found a package called yawPyCrypto (yet another wrapper for python crypto). That seemed quite promising. I was able to work out a simple example where it would generate a 1024bit RSA key pair, and I could encrypt and decrypt a string with it. Only one problem… I could not successfully export and import the string from yawPyCrypto. This meant the server would not be able to the send the client its public key… LAME. Again, I poked around the source code, but I didn’t see anything obvious, and I was not about to reinvent the wheel here.

Then I discovered ezPyCrypto, which as you read from above, solved all my problems 🙂 I should also mention that on my Ubuntu machine I had to play around with the source code in ezPyCrypto to get it to import properly (remove references to variables it couldn’t find). Yeah… sounds stupid, but I was confident that what I was playing with was not related to public/private key encryption which is all I wanted.

I already fear that no matter how much I automate things there will be a problem. That is the way it goes however. I am hoping that I can polish off these scripts soon so I will not have to worry about radio station stuff until the beginning of the school year. I will most likely have more to say about these scripts and maybe a summery of everything I have done with them. That’s all for now though 😀