Archive for February, 2011


Inserting output from external command into a buffer in Emacs

I recently found a keyboard shortcut for Emacs that I think can prove to be very helpful at times. The keyboard shortcut enables you to run an external command and insert its output into the buffer you are currently editing. An example of when this can be useful is putting a date marker in a file, to document when it was written/saved/modified/etc.

The keyboard shortcut is this: C-u M-!

For example, I might run the command date to insert the current date into the buffer. Or I might prefer my dates formatted in a way more familiar to my locale: date +'%F %R %Z'. (This makes the date format as YYYY-MM-DD HH:MM TZ, where TZ is the current “alphabetic time zone abbreviation”, e.g. 2087-02-26 06:00 CET.)

Another example is to include the directory listing of a certain folder into the current buffer. The command to run would then be ls.

Very handy indeed!


Installing LaTeX packages in your home directory

I was recently in a position where I wanted to use a LaTeX package, but it was not installed on the computer system I was working on. The computer system was at my workplace, at Umeå University. I had a conversation with the systems administrator and he told me that updating the entire TeX distribution would require a lot of work, but that I could place the package in the current directory, with my document, and it would hopefully compile.

I hoped so too. But of course, this being the real world, such luck is rare with computers. So I decided to dive into how I might install a LaTeX package locally, in my home folder. I finally managed to find a solution, and I will detail this below.

This “how-to” will not cover how to create a package, or even how to download ready-made packages or whatever. I had the package that I required installed on my computer at home, so I just copied and pasted that over to the work computer. This tutorial will only cover how to make LaTeX look for packages elsewhere than the default package path.

LaTeX automatically looks to see if there are any package installations in $HOME/texmf/. That search path is the default value of the environment variable TEXMFHOME. This is very nice and handy; what this means is we can use “$HOME/texmf” as a folder to chuck packages into. However, I prefer to have files that I never really intend to open in hidden folders (folders whose name starts with “.” (dot)). So the next step I took was to create a folder where I can put packages, in my home directory (“$HOME”).

> mkdir $HOME/.texmf

After that, I went and added a command to my .bashrc file that will change the value of the TEXMFHOME variable to be that of the newly created folder. This way, LaTeX will search for packages in that folder instead. The following lines were added to the .bashrc file.

# LaTeX stuff
export TEXMFHOME=$HOME/.texmf

I usually use pdflatex to compile my LaTeX documents, so if you use some other program, the environment variable you need to change might be different. I compile my LaTeX documents on the command line, so if you use another system, you might have to find another way to export your environment variable, or even use the specific application settings in your editor, if your editor supports compiling LaTeX documents.