Thursday, 1 November 2007

Passwordless ssh

It is very convenient to use ssh to login into different workstations or for instance our Beowulf cluster elegast without having to re-type your password all the time. It is possible to setup things in such a way that this is possible. Here's the howto.

First you need to generate a so-called RSA key. Type
ssh-keygen -t rsa

This will create two files: id_rsa and The first should be kept secret, the second is public. You should now login into the remote machine. If the file ~/.ssh/authorized_keys exists, append the contents from the file to it. If it does not exist, create the directory ~/.ssh (with permissions rwx for yourself and no permissions for group and others) and the file authorized_keys (with permissions rw- for yourself and r-- for group and others) with as its contents the file

You should now be able to do passwordless ssh logins.

Bash programming

The standard shell under Linux is called Bash (the GNU Bourne Again SHell). Even though people are generally used to do a lot of stuff using graphical user interfaces, the command prompt can be very convenient for some tasks. Here are a few simple examples of how to get things done using your keyboard rather than your mouse.

Command line use by example

To convert all .gif files in a directory to .jpg, type
for file in *.gif; do convert ${file} ${file%gif}png; done

To find all .tex files in a directory including the subdirectories, type
find . -name "*.tex"

To filter out those files that contain the word "dimension", use
grep dimension `find . -name "*.tex"`

The code between the backquotes (`) is evaluated first and the output it generated is listed as if you typed it at the end of the command. In Bash you can also use $(command) as an alternative to the backquotes, which has the benefit that it can be nested. For example to get the number of bytes of all tex-files that contain the word dimension, you can say
du -s -k $(grep -l dimension $(find . -name "*.tex"))

To make the search on "dimension" case insensitive, use
grep -i dimension `find . -name "*.tex"`

To count the number of occurences, use
grep -i dimension `find . -name "*.tex"` | wc -l

which might be written shorter - but less illustrative - as
grep -c -i dimension `find . -name "*.tex"`

I'm sure you can use these examples to do powerful text searches yourself.

To rename a bunch of .gif files in a directory to new names like 001.gif, 002.gif etc., you could type

for f in *.gif; do
mv $f $(printf '%03d' $l).gif

This example also shows how to use if statements. A simple for loop can be programmed as
for (( n = 1 ; n < 9 ; n++ )); do echo $n; done

Writing scripts

If you have many commands that you use more than once, you can also create a text file in your favourite editor, type #!/bin/bash as the first line, and then put some shell commands. If you save the file and make it executable with chmod (see below), you have written a shell script and can simply execute all command by typing the script's name. This is like creating a Matlab script versus typing commands in the Matlab command window. In bash scripts, you can use a couple of funny looking variable names that have special meaning:

Variable Meaning
$0 name of the script
$# number of arguments given on the command-line when calling the script
$1 first argument given to the script
$* all arguments
$@ all arguments
$$ PID of the script

The difference between $* and $@ is subtle. Usually the latter does what you think it will do, while the first one has a slightly different semantic meaning. If you say "$*" it will expand to the single string "$1$IFS$2$IFS$3...", where IFS is an environment variable that contains a space by default but might have another value, e.g. the character ':'. When you say "$@" it will expand to the list of strings "$1" "$2" "$3"..., which is usually what you mean.

Parentheses in mathematical formulas

If you use \left( and \right) in LaTeX, it will automatically scale the parentheses for you to match the size of whatever you put between them. Sometimes LaTeX doesn't do a good job though, and you'll have to help the program. Here's an overview of the commands you can use for creating parentheses in different sizes:

  • (, )
  • bigl(, bigr)
  • Bigl(, Bigr)
  • biggl(, biggr)
  • Biggl(, Biggr)

Wednesday, 31 October 2007

Font sizes in LaTeX

To write text in different sizes in LaTeX, you can use the following standard size-changing commands (from p. 170 in The LaTeX Companion):

  • \tiny
  • \scriptsize
  • \footnotesize
  • \small
  • \normalsize
  • \large
  • \Large
  • \LARGE
  • \huge
  • \Huge

Tuesday, 23 October 2007

Source code in LaTeX

If you want to include some source code into a LaTeX-document, you can of course use the verbatim environment. It can be useful to refer to an external file rather than copy & paste the source into the LaTeX-file.

To refer to an external file (which has the advantage that you do not need to apply modifications in two places) can be done by using the moreverb package: insert
at the beginning of your document. I use the following macro

You can now use
in your document if you want to include the source text in the file ex5.m.

Monday, 11 June 2007

TU/e campus software

Always forget the link for campus software like I do? Find the list at this page.


I use my MacBook every single day, both at home and at university. Although you can specify more than one outgoing mail server in Apple mail, it is a bit annoying that you have to change the setting every time you change location. Enter MarcoPolo. This is quite a new program, but I use it on a daily basis and am very happy with it. MarcoPolo guesses at which location you currently are and can do a numer of things based on this guess. For me it changes outgoing mail server, default printer and, at university, switches off wifi.

It's free, it works great and, if you need this functionality, I strongly recommend it. Of course it also has builtin Growl support!

Visit MarcoPolo's website.


This is another type of application that you may not be familiar with. Growl is a program that shows notifications, little messages pop up on your screen. The great thing is that programs can let you know some task is completed, new mail has arrived, hardware was added to your system etc etc. This all happens without interfering with what you were doing. The messages do not distract, are yet informative and above all: different programs let you know stuff in a consistent way.

Many programs have Growl support built in; for some you can install little helper scripts or programs. I have installed GrowlMail and HardwareGrowler.

The program is free and super useful, so go get it!

Thursday, 7 June 2007


Every so often I need to measure data from a picture or pdf file. I keep searching for the perfect onscreen set of rulers. I found one a while ago that allowed me to first set up the scale with a few mouse clicks and then do the measurements. Alas, I have lost track of that app.

However, this RealBASIC app seems to be quit up for doing the job, and better still it runs equally well on Windows as on Apple. (RealBASIC should even run on Linux, no?) Check it out at:

Journler: how to organize things

Yesterday, I already discussed how to make more use of Spotlight with SpotInside. Spotlight is great for finding things, and you can find things even after you forgot where you have put things. I still tend to put things together in subfolders of subfolders, but sometimes wonder if things should go into my Programming/C++ folder or in my Work/SomeProject folder. In the end things tend to get scattered around anyway.

Wishing I had a Mac at my disposable the whole day, I would use this program: It lets you make a journal of things you collect. For me, when working on a project there is a lot of files on the periphery of the actual research or coding that can get lost. Scientific articles with interesting infomation, but how to store that knowledge. I tend to carry a lot of notes and articles with annotations. But these are all in paper, and that's hard to backup, or in half a year: hard to find.

With this fabulous program, you can make notes, and store all kinds of files with those notes. This means I could store a PDF together with my own notes about why this article was useful to me or what idea I got from it, in a digital form. Digital for me means backup-able, re-findable, re-usable.

Unfortunately having a Mac only at night, I cannot properly use to program, lest a sync all the files I generated or used during the day anyway. But that would mean I already would have organized them, and I need this program for that...

Early evaluation

Things I miss from a wiki-type solution instead of this blog:

  • possibility to edit (extend, change) other people's posts. Comments are available, but less visible and not suitable for e.g. typo's in the original post
  • ease of editing. Typing HTML codes is more work than wiki markup
  • not possible to see how some things (including pictures, making lists etc.) are done because you do not get to see the source of other people's messages
  • no list of recent changes

Advantages are obviously that we have a nicer link to the site and that we do not need to run our own server. Also, the user interface for blogger is localized and gets improved by Google over time.

Wednesday, 6 June 2007

QuickSilver - must have

Yeah, let's make this an Apple fan-boy blog! Inspired by Bas's previous two posts on Apple software, I thought I'd mention QuickSilver. This is a must have program, and it's free too!

QuickSilver's website is quite obscure, as is the program's documentation. You get a very good impression of what you can do by this post though. Check it out. You don't want to do without it once you've installed it on your Mac!

SpotInside: usable spotlight queries

MacOS X comes with a handy desktop search built right in. However, choosing what you are looking for from a long list of results can be quite awkward. On my ageing Mac Mini — a real Mac being a PowerPC! — also the search-as-you-type feature of spotlight makes it painfully slow, to the point of unusable.

A better way to search the results is offered by SpotInside. It shows the contents of almost everything, makeing it a treasure to find what you are looking for.

References in LaTeX using bibtex

If you use LaTeX often you will soon find that you should keep track of references with bibtex rather than specifying them time and time again in a bibliography-environment in each document separately. Here's a short intro on working with bibtex.

Somewhere in the beginning of your text document, you tell LaTeX which style to use for the references, e.g.


You can just cite papers and books with "\cite" as you do now. However, at the end of the document, you write


instead of the whole thebibliography environment you use now. That's all.

Now, use "latex mytext" on your file twice, next run "bibtex mytext" and finally twice more "latex mytext". You don't have to do this every time - just when you have used new citations in your text, you need to run
"bibtex" again. (Explanation: bibtex actually generates the thebibliography environment for you, including all references you actually use. See the file mytext.bbl for the generated file.)

I've enclosed a small example, see test.tex:



% The following command changes the way your list of
% references will look, as well as how the citations in
% the text will look. Unquote "apalike" to get similar references as
% in my PhD thesis.


Here is a reference to the first entry in my bibliography file

If you would like to refer to a theorem or page in a reference,
use something like \cite[p.~100]{RANA9804} or \cite[Th.~4]{RANA9804}.

If you use the \verb=cite=-package, lists of references will be
put in a nicer form, such as \cite{RANA9804,RWTH152,NAVW}.



Here's the bibtex file martijn.bib:

% Sample bibtex file

author = "Martijn J. H. Anthonissen and Bas van 't Hof and Arnold A. Reusken",
title = {A finite volume scheme for solving elliptic boundary
value problems on composite grids},
month = feb,
year = 1998,
institution = {Eindhoven University of Technology},
address = {Eindhoven},
number = {RANA 98-04}

author = "Martijn Anthonissen and Bas van 't Hof and Arnold Reusken",
title = {A Finite Volume Scheme for Solving Elliptic Boundary
Value Problems on Composite Grids},
month = feb,
year = 1998,
institution = {Institut f\"ur Geometrie und Praktisch Mathematik, RWTH Aachen},
address = {Aachen},
number = {Bericht Nr.~152}

author = "M. J. H. Anthonissen and B. van 't Hof and A. A. Reusken",
title = {An Iterative Finite Volume Discretization Method for Solving Elliptic Boundary
Value Problems on Locally Refined Grids},
journal = {Nieuw Archief voor Wiskunde},
volume = 17,
pages = {111--123},
year = 1999

References in LaTeX

A quick LaTeX-tip on the authors field in an item in a bibtex-file. You should always use spaces in
between initials, so e.g.

author = "C. R. Traas and H. G. ter Morsche and R. M. J. van Damme",

If you do not include the spaces, bibtex thinks the first author has first name "C.R." rather than understanding that you mean he has initials "C" and "R".

This makes a difference depending on which bibliography style you use.

Shell scripts

The following script is not an example of great programming, but shows some of the standard commands available in the UNIX shell:

for FILE in *.gif
do if test $l -ge 100
then mv $FILE $l.gif
elif test $l -ge 10
then mv $FILE 0$l.gif
else mv $FILE 00$l.gif

A standard loop can be programmed via

for (( n=1 ; n<9 ; n=$((n+1)) )); do echo $n; done

TU/e Dial-in

If you are ever in the sad situation that you want to use an old-fashioned telephone modem to access the internet, you can use the TU/e dial-in server. The telephone number is 06760 04321. Log in using your NT account.

Using the shell

Never underestimate the power of the UNIX shell! The following one-liner converts a batch of files from gif to jpeg for you

for file in *.gif; do convert ${file} ${file%gif}png; done

Note that the %gif removes gif from the file name for you. If you are trying to create such a one-liner it is very convenient to use echo to first print commands before actually executing them, so

for file in *.gif; do echo convert ${file} ${file%gif}png; done

is harmless but gives you an indication of what will happen.

Index in LaTeX

If you want to add an index to a LaTeX document (say, a thesis), the simplest option to mark a word (e.g. convection is to use \index{convection}. More advanced uses include:

  • \index{dimensions!rule!width} - this is for subitems
  • somewhere in your text you put \index{domain decomposition|(}, then you write a lot of stuff on this topic and you end with \index{domain decomposition|)} - this is for a page range
  • \index{delta@$\delta$} - this tells LaTeX that it should treat the letter as the word "delta" when compiling the index
  • \index{topic|see{some other topic}} - for a cross-reference

Brackets in LaTeX

If you use \left( and \right) in LaTeX it will automatically make the brackets larger, depending on what you put in between. Sometimes it doesn't do a good job and you should manually resize the brackets. These are, arranged from smaller to larger, your options:

  • (, )
  • \bigl(, \bigr)
  • \Bigl(, \Bigr)
  • \biggl(, \biggr)
  • \Biggl(, \Biggr)

Tuesday, 5 June 2007

Vienna RSS reader

Surfing from website to website to quench the thirst for nerdy news can be quite consuming as interesting websites as, and move more and more into the Web 2.0 era and their pages take longer and longer to load. If, on top of that, you decide to start a blog to replace an unfortunately and most stupidly perished snipsnap wiki that you and (much more so) a friend had filled with information about all the computing bits and pieces of a numerical analyst's life, then the daunting task of visiting even more website can become quite frightening.

Of course, what one needs is a decent RSS reader and while Safari displats feeds quite nicely a real RSS reader can safe a lot of time. On MacOS, I prefer Vienna ( opensource and complete.