Computing

Tips, tricks, and scripts

Comparing files

wdiff

Use wdiff to compare your original file and your collaborator's edits:

wdiff -l original.tex edited.tex | less
and you'll see word-by-word differences.

latexdiff

Use latexdiff to compare two LaTeX files, for example, your original file, and your collaborator's edited version. Running:

# My tex files commonly use the class file aastex, which includes
# the amsmath and hyperref packages.  When they are included in this
# way, latexdiff should be made aware of them via the command-line:

latexdiff old.tex new.tex --packages=amsmath,hyperref > diff.tex
pdflatex diff
pdflatex diff
results in a document with differences highlighted.

Emacs Ediff-mode

Use Emacs' Ediff-mode to compare two files, for example, your original LaTeX file, and your collaborator's edited version. In Emacs, type M-x ediff-files, or select menu item Tools->Compare (Ediff)->Two Files. A small window appears. Use this window to navigate and merge the two files (? for help).

LaTeX

PDF comments

Insert PDF comments with the pdfcomment package:

...
\usepackage{pdfcomment}
...
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam ipsum
dolor, scelerisque eu consectetur at, laoreet sed erat. Integer non
fermentum enim. Maecenas adipiscing placerat vestibulum.
\pdfcomment{Looks like Latin to me.}
...
Your pdflatex compiled document will get a nice balloon with comment text in your PDF file.

Aligning images

Using Hugin to align images of the Moon

Hugin is a tool for stitching together digital photos to create seamless mosaics. Using Hugin, we can automatically align images of the moon through feature detection:

  1. Convert your images to some standard image format, e.g., PNG or TIFF. Make sure your file names don't have extra dots in them (e.g., img0788.a.png should be img0788_a.png). Greyscale images didn't work for me, so I converted them to RGB.

  2. Load the images into Hugin. Since there isn't any camera lens information in your images, Hugin will prompt you for some information. Enter the smallest field of view possible: 1 degree. This isn't true for most of my telescopic images (1 to 5 arcminutes is more typical), but as long as your mosaic isn't too big, this shouldn't matter.

  3. Let Hugin identify features. Go to the Images tab and select Create Control Points. I had trouble with a set of 142 images crashing Hugin, but half that many was OK.

  4. Save the project to a PTO file. Force every image to have its own set of lens parameters, then tell Hugin to only fit x and y offsets to align images. To do this, use sed to modify the PTO file (replace file.pto and file2.pto with your filenames):

    Hugin v0.8(?) and earlier:

    cp file.pto file2.pto
    sed -i 's/v=0/v1/; s/Va=0/Va1/; s/=//g' file2.pto
    sed -i 's/^v p\([0-9]*\).*/v d\1 e\1/' file2.pto

    Hugin 2010.1.0 (others?):

    cp file.pto file2.pto
    sed -i 's/v=0/v1/g' mm6.pto
    sed -i 's/=0/0/g' mm6.pto
    sed -i 's/^v p\([0-9]*\).*/v d\1/' mm6.pto
    sed -i 's/^v y\([0-9]*\).*/v e\1/' mm6.pto
    sed -i '/^v r\([0-9]*\).*/d' mm6.pto
    sed -i '/^v [de]0$/d' mm6.pto
  5. Open the edited PTO file with Hugin. Open the Optimizer tab and select Optimize Now! You should get a good fit with small residuals. At this point you can delete bad control points add new ones, etc. I won't describe that stuff since the Hugin tutorials do a fine job of that.

  6. I prefer to mosaic data outside of Hugin so I can be sure to preserve the image photometry, plate scale, etc. Save the PTO file and quit Hugin. The offsets are the d and e parameters in the file. Since my images where all PNG files, I can easily grep, awk, and sed them out. Your mileage may vary:

    Hugin v0.8(?) and earlier:

    grep png file2.pto | awk '{print $22, $23, $32;}' \
      | sed 's/d//; s/e//; s/n//; s/"//g' \
      > offsets.list

    Hugin 2010.1.0 (others?):

    grep png file2.pto \
      | awk '{print $24, $25, $36;}' \
      | sed 's/d//; s/e//; s/n//; s/"//g' \
      > offsets.list
  7. Finally, mosaic your images with your favorite program. I found that the offsets needed to be multiplied by -1, but otherwise it worked great for my Lunar mosaics.

Copyright © Michael S. P. Kelley 2024