Sunday, December 31, 2006

Including Code Samples in Blogger Posts

To include code samples as nice as mine, do the following. Of course, the following instructions are blogger specific. Also, the code was copied from All about Linux.

Go to your template and select "Edit HTML". Add the following code to the section entitled Posts.
.post pre {
background-color: #efefef;
font-family: 'andale mono','Courier New', Monaco, monospace;
font-size: 1.25em;
padding: 1em 1em;
width: 90%;
border: 2px dotted #ddd;
overflow: auto;
Now if you want to include some code in your post, then just do the following.
<pre><code>Include code here.</code></pre>
You will have to replace HTML characters (like <>) with the appropriate decimal codes. There are plenty of sites with character tables.

Saturday, December 30, 2006

Subversion for Document Management

I am going to use subversion and ssh for document management and off-site document storage. Subversion is a revision control system. It will allow me to work on the project from any computer since I can download the project files, work on them, and then upload the changes. Moreover, Subversion will keep track of the revisions, allowing me to revert to older versions if necessary. This post describes how to use subversion for document or small project management. See the work cycle section of the Subversion Book for a more detailed exposition. [I recommend using ssh-keys and ssh-agent on your main computer so you don't have to type your ssh password several times per session; see the post on creating and using ssh-keys.]

Setup. Install Subversion. Both on your client machines and on the server (ask your sysadmin). On Ubuntu:
apt-get install subversion
Below the subversion server will be called, and the username will be username. I ssh'd to and ran the following command to create a Subversion repository where Subversion will store the projects.
svnadmin create ~/subversion-repo
Create Project. To create a new project, create a new directory and populate the directory with files that you will need.
mkdir brilliant-paper
Import Project. Import the project into your subversion repository with the following command.
 svn import -m "My Brilliant Paper" brilliant-paper svn+ssh://

Now delete your project directory. (You will download a working copy in the next step.)
 rm -rf brilliant-paper/*
Work Cycle. The following steps describe how to use Subversion to work on the project.
  1. Download Project. Sit down at a computer, any computer, install Subversion if necessary, and download the latest version of the project. Either:
    • download the project, if is hasn't been downloaded before:
      svn checkout svn+ssh://

    • or update the project if you've already downloaded a version of the project: in the project directory run,
      svn update
  2. Make changes.
    • You can edit any files that exist and subversion will detect those changes.
    • If you want to add a new file, then use the add command.
      svn add newfile
    • Similarly, you can delete, copy and move files or directories.
      svn delete filename
      svn copy filename copyname
      svn move filename newname
  3. Examine Changes. Nothing above makes changes to the project in the repository. Before you commit any changes you might want to examine the changes you have made. Use the 'svn status' and 'svn diff' commands. If a file has changed and you want to revert to a previous version, then revert to the most recent version of that file in the repository with the command 'svn revert filename'.
  4. Commit Changes. Commit your changes with the commit command.
    svn commit -m 'Write a summary of your changes here.'
  5. Check Commit. In the top of your project directory run the status command.
    svn status
    If there is no output, then all changes have been committed. If there is some output, then there are files that have been changed or added, but not committed for some reason. See the help page to decode the output: svn help status

SSH-Keys to simplify SSH Logins

By creating an ssh key you can login to a remote machine multiple times with only one password.

Setup: Create the ssh-key.

Create the ssh-key with the following command. Hit enter; pick a good passphrase.
ssh-keygen -t rsa
Copy the resulting public key to the remote machine:
scp ~/.ssh/
Enter you password.

Using ssh-agent.

The following command adds your new ssh key to your 'keyring'. You will be prompted for the passphrase.
[If the above command fails, then ssh-agent is not running. Start it with eval `ssh-agent`.]

Now you won't be prompted for the passphrase again until the next time you log in. You can ssh into the remote machine using ssh as usual without being prompted for a password.

Wednesday, December 20, 2006

LaTeX Editing on the 13.3" Macbook (on Linux)

Here is my configuration for LaTeX editing on the 13.3" Macbook (running Linux). I configured gvim and xdvi so that the former occupies the left half of the screen and the latter occupies the right half of the screen. I then use a program that watches the tex file for changes; when I save any changes, the file is compiled and the xdvi window is updated. (One such program is atchange.)

My ~/.gvimrc file sets the window position and geometry of the gvim window.
set lines=39 columns=73
winpos 0 0
My ~/.Xresources file sets the window position, geometry and other options for xdvi.
xdvi*paper: us
xdvi*expert: true
xdvi*pixelsPerInch: 300
xdvi*mfMode: ljfour:600
xdvi*thorough: true
xdvi*background: light yellow
xdvi*shrinkFactor: 7
xdvi*geometry: 590x745-0+0
xdvi.sideMargin: 2cm
xdvi.topMargin: 2cm
xdvi.mainTranslations: #override\
Shift<key>space: up-or-previous()\n\
<key>space: unpause-or-next()\n\
<key>j: down(0.015)\n\
<key>k: up(0.015)\n\
<key>l: right(0.015)\n\
<key>h: left(0.015)
My ~/.vimrc file sets the textwidth, syntax-highlighting and some other options.
" enable syntax highlighting
syntax enable

" hightlight search
set hlsearch

" set textwidth to 70 to cause wrapping
set textwidth=70

" autoindenting
set ai

" 50 lines of command lines history
set history=50

" .viminfo file with 50 lines of registers
set viminfo='20,\"50

" show the cursor position all the time
set ruler

" turn on speel cheqing
set spell
Finally, check out the LaTeX Suite package that provides several useful tools for LaTeX editing with vim.

Enable Shift-Space in XDvi for Page-Up

I use evince and xdvi for document viewing and I want the page navigation to be same: while both use Space for page down, the page up keys are difference (evince uses Shift-Space; xdvi uses Delete). This is how to set Shift-Space to act as page up for xdvi.

Add the following lines to ~/.Xresources (or ~/.Xdefaults).
xdvi.mainTranslations: #override\
Shiftspace: up-or-previous()\n\
space: unpause-or-next()\n
Then run the following command
xrdb ~/.Xresources
You're all set.

Some notes.
  1. The order is important. The translation table is searched from top to bottom, so if the line beginning space... appeared before the line Shiftspace..., then both Space and Shift-Space would trigger unpause-or-next().
  2. There are many other options for xdvi (and other programs) that can be set in ~/.Xresources. See the man page for xdvi for more information.