Archive for April, 2014

Using latexdiff to Highlight Revisions in a LaTeX Project

April 21, 2014 Leave a comment

Typically research papers are put together as LaTeX projects. I was under the impression that it is a challenge to keep a visual track of who made what changes; typically there are more than one authors on the paper and we try to learn from the experienced writers. But then I came across a useful tool, latexdiff, which opened the door for many possibilities.

What latexdiff does is that it highlights, in color, the differences between two LaTeX files. Consider a trivial example below. Latexdiff compares the two LaTeX files (original.tex and revised.tex) and generates a LaTeX file as output (diff.tex), which can then be compiled into pdf to view the output.

latexdiff original.tex revised.tex > diff.tex
pdflatex diff.tex

An example is shown below, where red color highlights the text that was deleted and blue color highlights the text that was added.

latexdiff example output

When collaborating, the LaTeX project includes multiple files that are pulled into the primary LaTeX file. This can be done using the flatten option.

latexdiff --flatten original.tex revised.tex > diff.tex

I’ll leave it to you to explore the documentation for other possibilities.

The tool can also be used along with version control systems (e.g., svn). Below is a crude bash script that pulls an old version from the svn repository and compares it to the version in your working directory.

# Version: 0.01
# Author:  Umar Kalim

if [ $# -ne 2 ] ; then
  echo "Usage: $0 <svn revision no.> <filename>"
  exit 1


mkdir tmp
echo "exporting svn repo $svn_revno"
svn export --force -r $svn_revno . tmp

echo "generating diff"
latexdiff --flatten tmp/$filename $filename > diff.tex

echo "compiling output with highlights"
pdflatex diff.tex

echo "cleanup"
rm -rf tmp
Categories: best practices Tags:

Tack Sharp Portraits

April 15, 2014 Leave a comment

Until few months back, I used to wonder: why is it that my portraits aren’t tack sharp? I would feel that I could have eeked out more sharpness. However I wasn’t sure what was it that I was doing wrong. I would make sure that I:

  • Use spot focusing and choose a focus point so that I could aim for the eyes,
  • Choose a shutter speed that is fast enough to freeze motion when I want it to,
  • Choose an aperture so that I could blur the background,
  • Choose the lowest possible ISO,
  • Try to adjust my exposure settings to expose for highlights and
  • Choose a focal length greater than 50mm.

However, irrespective of the output, I would always feel that the portrait could have been sharper. I had seen stunning portraits (with the same lens) and I knew it could be done. Yes, the glass matters, but my Tamron 17-50mm f/2.8 wasn’t too shabby.

After much research, I found that not all apertures of the lens capture images with the same sharpness. (What? How can this be true? This called for a serious investigation.)

I googled for a lens-test chart. To test the lens, I stuck the chart to a wall. After arranging sufficient ambient lighting, I setup the camera on a tripod and switched to aperture priority mode. After setting the ISO at 100, manually focusing on the chart with live view and using a release cable to trigger the camera, I took photographs for all aperture settings at different focal lengths.

The results were astonishing. See the pictures below at 17mm. With all other parameters fixed (except for shutter speeds, which is understandable) the photograph at f/2.8 is not as sharp as the one at f/4.0. Similarly, the one at f/4.0 is not as sharp as the one at f/5.6. However I started to lose sharpness at the other extreme too. I observed the same behavior at all focal lengths, though with slight variations. Nevertheless, the trend was the same. Sharpness was poor at extreme apertures, which in my case was f/2.8 and f/32.

f/2.8, 1/400 sec, 17mm, ISO100 f/4.0, 1/200 sec, 17mm, ISO100
f/5.6, 1/60 sec, 17mm, ISO100 f/22, 1/4 sec, 17mm, ISO100

The lesson was that by stopping down once (f/4.0) I would get a pretty good image. Stopping down twice (f/5.6) would result in a much more sharp photograph. From there on I would observe diminishing returns, until the sharpness started to deteriorate.

Therefore, your f/1.4 may not produce pictures as sharp as you would have expected it to produce at f/1.4. While it is important to consider other aspects — e.g., avoid camera shake, making sure that you’ve focused where you intended to and choosing other exposure settings — avoiding extreme apertures is important to obtain tack-sharp photographs.

I have not tested the same with L series lenses. I would expect similar trends though.

There is another aspect to this discussion; I also realized that we should not confuse the lack of sharpness due to extreme aperture settings with the blurry feel of photographs that have a narrow depth of field. When we choose a small aperture (say f/16), we are increasing the depth of field; when we choose a wider aperture (say f/2.8), we are narrowing the depth of field. Depending on your focal plane, a photograph with a large depth of field may have a “feel” of being sharper than a one with a narrow depth of field. However, the discussion above is not with reference to the overall feel of the photograph, but instead about the sharpness of the subject(s) that fall within the region that is in focus.

Categories: photography

Password Reconstructors

April 14, 2014 Leave a comment

Disclaimer: This post is inspired by emails exchanged between myself and Dr. Mark Gardner (Virginia Tech). The term “password reconstructor” has been coined by him. The software mentioned below is developed by Richard B. Tilley.

Most of us are familiar with the best practices of choosing our passwords. When following these best practices — such as not using the same password for different websites; using alphabets, numbers and symbols — it is impractical to memorize all our passwords. Subsequently we use password managers such as Lastpass, 1Password, KeePass, or similar software. Now, with the news of the heartbleed bug everyone has been forced to change their passwords. This change of all the passwords has not been fun for me.

After discussion with several colleagues, I realized that I can do away with the problem of managing my passwords. There is something called a “password reconstructor”, where you are not required to remember, store or manage hundreds of passwords; you do need to remember one phrase though. But that is not a challenge for us, after all we’ve been memorizing passwords that look like Egyptian hieroglyphs.

So what are these password reconstructors? and how do they work?

The idea is that you use a secret phrase or a master password along with labels to generate your passwords. The phrase would act as your secret key and the label would indicate the purpose of the password. For example, you may use the phrase “intelligence is imagination” and the label “bank” to generate a password for your bank account. Similarly, you would use the same phrase with the label “amazon” to generate the password for your amazon account.

As the password constructors use cryptographic hash algorithms, the smallest of differences in the phrase or label would result in substantially different passwords. For example, below are two passwords generated by slightly different labels.

phrase:intelligence is imagination; label:bank; password:JBB1H4O1G0Nur3.H0k
phrase:intelligence is imagination; label:Bank; password:p5ZMIXL1OuHaIZ.H0k

Note that I used the same phrase, but I changed the first alphabet of the label — the first uses “b”, while the second uses “B”. The passwords generated are altogether different.

These passwords were generated by software available here. It does not generate passwords with symbols or punctuation. Therefore the author chose to add a four-letter suffix “.H0k”. This allows the password to be compliant with the requirements of websites that ask for at least one character from the upper and lower case, numbers and punctuation.

So there you go. We do not need to store any password. We do not need to painstakingly think of a combination of words with weird characters, later to be prompted that the password provided does not meet the website’s requirements. All we need is one secret phrase, and a label to obtain a strong password.

The software developed by Brad is available for OSX, Linux and Windows. The source code is available too.

I am grateful to Mark for bringing this software to my attention and thankful to Brad for publicly sharing the software and the code. I’ve setup a copy of the Javascript version here.

Categories: best practices

Ghazal: Dard Se Mere Hae Tujhko Beqarari Haae Haae!

April 14, 2014 Leave a comment

I came across this beautiful ghazal, “dard se mere hae tujhko beqarari haae haae”, by Mirza Asadullah Khan Ghalib, sung by Rahat Fateh Ali Khan. I thoroughly enjoyed listening to the verses and felt like sharing it with others.

Unfortunately, those who do not understand the language Urdu would not be able to follow the poetry. For those who do understand Urdu, I’ve tried to translate the difficult-to-understand words and phrases.


Dard ho dil main to dawaa kijiye,
Dil hi jab dard ho to kiya kijiye!

Ham ko fariyaad (request) karni aati hae,
Aap sunte nahi to kiya kijiye!

Ranj (sorrow) uthaanay se bhi khushi ho gi,
Pehle dil dard aashna (familiar) kijiye!

Maut aati nahi kaheen Ghalib,
Kaab tak afsos zeest ka kijiye!

Dard se mere hae tujhko beqarari (restlessness) haae haae,
Kiya huwi zaalim teri ghaflat-sheari (callousness) haae haae!

Apni hasti hi se ho jo kuch ho,
Agahi gar na sahi ghaflat hi sahi!

Tere dil mein gar na tha aashob (agitation) e-gham ka hosla,
Tu ne phir kiyun ki thi meri gham-gusaari (commiserate) haae haae!

Kiyun meri gham-khargi (share sorrow) ka tujhko aiya tha khayal,
Dushmani apni thi meri dost-daari (fellowship) haae haae!

Umr bhar ka tu ne paeman-e-wafa (sworn loyalty) bandha to kiya,
Umr bhar ko bhi to nahi hae paedaari (certainty) haae haae!

Zahar lagti hae mujhe aab-o-hawa-e-zindagi,
Yaani tujh se thi ise nasaaz-gaari (inappropriateness) haae haae!

Zindagi apni jab is shakal se guzri Ghalib,
Hum bhi kiya yaad karein ge ke Khuda rakhte the!

Gul-fishaani (lavish with flowers) hae, naz-e-jalwa (beauty) ko kiya ho gaya?
Khaak per hoti hae teri lalakaari (stringing of flowers) haae haae!

Sharm-e-rusawaae (fear of shame) se ja chupna naqaab-e-khaak (veil of ashes) mein,
Khatam hae ulfat (love) ki tujh per parda-dari (privacy) haae haae!

Khaak mein namoos-e-paeman-e-muhabat (respect for the benchmarks of affection) mil gae,
Uth gai se dunya se rah-o-rasm-e-yari (custom of fellowship) haae haae!

Ishq mujhko nahi wehshat (agony) hi sahi,
Meri wehshat teri shohrat (popularity) hi sahi!

Ishq ne pakra na tha Ghalib abhi wehshat ka rang,
Reh gaya dil mein jo kuch zauq-e-khari (experience of anguish) haae haae!

Dard se mere hae tujhko beqarari haae haae,
Kiya huwi zaalim teri ghaflat-sheari haae haae!


Categories: poetry Tags: