Archive for the ‘School’ Category

Xfig and PDFLaTeX (or LaTeX)

August 22, 2008

Although the GUI for Xfig is a little outdated, in my opinion it is the best software to use for academic vector-based diagrams. It allows the use of LaTeX equations in conjunction with the figure.

Screenshot of Xfig in action!

Screenshot of Xfig in action!

What I prefer is to make a .pdf of the figure through pdflatex and then include the image to the document of interest. The directions parallel the following website:

http://graphics.stanford.edu/lab/howto/xfig_latex.html

When adding LaTeX expressions to a figure use the $…$ to switch to math mode when necessary. Make sure you set the flag on the text to “Special Text” using the “Text Flags” menu on the bottom. Then export the figure from Xfig using the “Combined PS LaTeX (PS and LaTeX part)” to the default name.

Create a driver file (e.g., this case my default export name was fig1 thus I use fig1.tex) containing something like:

\documentclass{article}
\usepackage{epsfig}
\usepackage{color}
\setlength{\textwidth}{100cm}
\setlength{\textheight}{100cm}
\begin{document}
\pagestyle{empty}
\input{fig1.pstex_t}
\end{document}

Then run:

latex fig1.tex
dvips -E fig1.dvi -o fig1.eps
epstopdf fig1.eps

Note that you can change the name “fig1.eps” to anything that you want. I have included the driver file in the path ~\Work\TEX\driver\fig1.tex. There is something wrong with my version the Xfig export so when you export just export it to the name that the file is saved as (e.g. do not enter a new filename). Then change the driver file appropriately.

Some key notes about using Xfig.

  1. It’s always tough to figure out what scale you should draw these things on especially since the units on the border don’t mean all that much. My rule of thumb is to put down an arrow using the “polyline” function and then judge your sizes from then on.
  2. I find it impossible to pan side to side, this will get all your nerves. Zooming in and out is a pain too.
  3. Get a mouse. The middle mouse click is so useful.
  4. Xfig does not make good “3D” drawings (to my knowledge). Does anyone know an alternative?
Example of what you can do with Xfig! This is a diagram I made for my research.

Example of what you can do with Xfig! This is a diagram I made for my research.

Merging (concatenating) and splitting PDF files

August 7, 2008

In an attempt to merge PDF files from chapters of a book I started a google search of the methods to do this. There are several ways to do this but the easiest way (for OS X) is to use the JoinPDF. It seems simple enough and it does splitting for you too!

Other methods exist, but are a little more complicated. I assume that taking the Imagemagick route isn’t all too painful though…

For Windows tryout PDFMerge.

IP printing in OS X

July 30, 2008

Nearly everyone who uses OS X knows that one department where the OS is lacking is in the realm of IP printing and IP printing support. For most of us in an academic infrastructure, this is usually how we connect to our printers. But when you look at the configuration of such a printer, you are either only left with a handful of options or you have to follow a maze to find options. But luckily, the underlying printing system is managed by CUPS (Common Unix Printing System). Depending on your version of cups you can easily access all your printers, queues, and options in one convenient place… in your web browser! CUPS has a nice user interface that can be accessed in your web browser by typing the following into your web browser of choice

http://localhost:631

Check it out, it is pretty neat. It’s a nice and tidy place for all your printing needs… now if only OS X could just capture this and translate it into their Preferences pane.

Screenshot of the web interface for CUPS 1.3.x.

Screenshot of the web interface for CUPS 1.3.x.

MATLAB – filling the “contour” function

July 25, 2008

This is a stupid post but I am just putting it here because I will forget how to fix this in the near future. So the problem with the contour function is that if you want to fill all the contours, it never fills the contour at the lowest limit in which you are interested in, i.e. it will leave an image with a disgusting white splotch where it should really be dark blue.

Look at that ugly white. This is because 'contour' doesn't know any better!

Look at that ugly white. This is because 'contour' doesn't know any better!

A quick fix to this is to set the background of an image as the color that the white areas are supposed to be. To do this, you should run the following lines:

[contours, h_w] = contour(x, y, w, w_level, line_color);

% Here is a nice fix to fill the last contour on a filled plot
set(gca, ‘Color’, [0 0 .5]); % Set background color of “axes”
set(h_w, ‘Fill’, ‘on’); % Set contour filling on
set(gcf, ‘InvertHardCopy’, ‘off’); % Prints background color when printing

Of course, if you change the default color scheme from jet to something else, you will need to change the ‘Color’ accordingly. You should have a resultant picture like this.

Ah, much better.

Ah, much better.

This is just really a temporary fix, someone should really dive into the code and fix this!

Using ImageMagick to convert a series of images to animated GIF

July 24, 2008

I use this a lot for research. I have a series of images in a postscript type format (e.g. EPS or PDF) and then I want to turn the time series of data into an animation. For this i use ImageMagick because it is a really nice command line tool for Unix operating systems to do batch type operations. You can even pipe it to C code! (Make sure you have it installed because it is not usually distributed with a bare Linux OS)

To do a simple conversion of images to an animated GIF we invoke the following

>convert -verbose -delay 20 -loop 0 -density 200 *.pdf output.gif

and we get a nice GIF file. This takes the files named *.pdf in the order that they are listed and makes a GIF out of them with a 20 hundreths of a second delay between each frame. The -loop 0 flag makes it loop indefinitely. You can put 3 in there to loop 3 times etc. The -density 200 flag specifies a DPI of 200 for the image. This is only really used when converting postscript images.

Animation of flow over a cylinder (vorticity) made from MATLAB + ImageMagick.

Animation of flow over a cylinder (vorticity) made from MATLAB + ImageMagick.

Compiz + MATLAB solution

July 24, 2008

MATLAB and Compiz do not mix (I am using Ubuntu 8.04). If you just installed MATLAB, in all likelihood MATLAB shows a window with nothing in it. For some reason MATLAB does not use the right JAVA toolbox or something along those lines. So we have to edit the launch file to do this. So add

export MATLAB_JAVA=/usr/lib/jvm/java-6-sun/jre/

to the /PATHTOMATLAB/bin/matlab lauch file so that it looks something like this:

#!/bin/sh

export MATLAB_JAVA=/usr/lib/jvm/java-6-sun/jre

#
# Name:
# matlab script file for invoking MATLAB
#
# …

MATLAB should run much better. In my experience, it is much better than the export AWT_TOOLKIT==MToolkit trick. MATLAB will still be fickle with Compiz in place (well, anything will be fickle with Compiz running). The best solution, if you use MATLAB a lot, is to just not use Compiz or any other eye candy.

Compiz and MATLAB 2007 running at the same time!?!

Compiz and MATLAB 2007 running at the same time!?!

GNU Screen

July 22, 2008

Possibly the most useful tool ever if you do a lot of remote computing. Here’s a quote from Wikipedia:

GNU Screen is a free terminal multiplexer developed by the GNU Project. It allows a user to access multiple separate terminal sessions inside a single terminal window or remote terminal session. It is useful for dealing with multiple programs from the command line, and for separating programs from the shell that started the program.

I use it mostly for running command line utilities that take forever to run (e.g. academic programs that do “work” for me). This allows me to remotely log in, start screen, start a program, detach screen, and log out. When I come back to check on how the program is running, I can log back in, attach an already running screen, and check on it again. Once I am done then I detach.

Here are useful commands:

>screen, starts a screen session on the host.
>screen -r, reattaches to a previous session.
>screen -r blah.host, reattaches to a specific previous session.
>exit, destroys the current screen session.
>screen -x, attach to a non detached screen.

In addition, you can hit CTRL+a and type one of the following to send specific commands to screen:

c, create new screen.
n, next screen.
A, rename screen.
d, detach screen.
", lists screens. Interactive.
0-9, select certain screen.