Friday, September 23, 2011

A `best practice' for writing papers in LaTeX

To handle complexity and versions, I do the following when I start writing a paper in LaTeX.
  • Create new directory Conf1.
  • Within this, create a new file Conf1.tex, and two new directories: tex and images.
  • Conf1.tex contains: document class, title, author, bibliography style, etc., which are specific to the conference/journal. This is followed by \input{tex/main}.
  • Create main.tex in directory tex. The tex directory contains all the LaTeX code, and could have further subdirectories if required (e.g., I usually have a directory for Experiments, another for Algorithm, etc.). All tex files are included in the paper by adding \input{tex/subdir/abc.tex} to main.tex in the appropriate place.
  • All package inclusions (\usepackage{}), command declarations, etc. required for the paper are included in tex/include.tex.
  • The first line of main.tex is \input{tex/include} followed by \begin{document} and \maketitle. Include all your LaTeX code after this. End with \bibliography{tex/biblio} followed by \end{document}, where tex/biblio.bib is the bibliography file.
  • All images are stored in the directory images.
Some things to note:
  • You can use git/svn to do versioning. Until I get used to them, I am using the following method. When I have a significant frozen version, I copy the directory tex to texN where N is 1,2,3.... The timeline of versions from the earliest to the current is tex1, tex2, ..., texN, tex.
  • I put the .bib file into tex because I found the bibliography changes as the paper develops.
  • On the other hand, images usually accumulate. So, only the directory tex needs versioning.
  • In order to use the material for another conference/journal, follow the steps above to create Conf2 and Conf2.tex. Then copy images and tex from Conf1 and compile. Your first draft of Conf2.pdf is ready!
  • I read somewhere that using PDFLaTeX gives more compact files, also avoids some font problems which arise due to DVI to PDF conversion when using LaTeX. I also had problems using Beamer with LaTeX. 
  • If you decide to use PDFLaTeX, remember that it does NOT accept images in .eps format. I found that .png files did not render text well on conversion. Creating / converting all images in / to .pdf format (using Inkscape) worked for me.
  • I use Inkscape for most drawings, and Gimp for screen capture (and also for format conversion).

Friday, September 2, 2011

Find and Replace across multiple files in Linux

For example, do this (Courtesy Rushi):
find mydir -name "*.tex" | xargs sed -i 's/foo/bar/g'
This replaces `foo' by `bar' in all .tex files in the directory mydir and its subdirectories.

This is useful for changes to latex code stored in a directory structure, since
find: gets the correct recursive file listing
-i: edit the files in place
/g: replace all occurrences in the file (globally)
foo: is a regular expression (POSIX.2 BRE)

[search tex]

Wednesday, July 20, 2011

Applying for a passport: Tips

Here are some tips for anyone applying for a passport in India. (Note: Some of these tips are specific to Bangalore.)
  • Apply for passport online at www.passportindia.gov.in
    • I found some bugs in the online form; so I downloaded the editable pdf (called eForm) from the site and filled it up. You need Adobe Acrobat Reader for this (Evince etc. might not work).
    • Print out the application receipt; it has all the main details of the application, and has to be shown at the entrance.
  • Book an appointment slot online at your preferred Passport Seva Kendra (PSK). Slots become available for online booking at 8 am. Login at 7.56 am and start trying. [Thanks to Prasad, for the update on the new times!]
  • Documents required:
    • Use the site to find out. But, dont stop there. Call the toll-free number to check if the rules have changed recently. 
      • E.g. I was asked for two adress-proofs, instead of one. I had to go back home, just for that. If you are using an annual bank statement as proof, ensure it has the seal and signature from the bank. I used the annual statement that comes by post, which is printed on the bank letter-head, and has no explicit seal or handwritten signature. (They finally accepted it, but only reluctantly. Also, in the spirit of bargaining, they kept the original statement itself, rather than a photocopy.)
  • At the PSK
    • Try to get a 9 am appointment. Later slots tend to get crowded by slowpokes from earlier slots, and it all snowballs.
    • Try to go earlier than the mentioned reporting time. There is a single queue at the entrance, where people are redirected to counters, and the earlier you get to a counter, the earlier you get a token, and the earlier you will come in the rest of the queue.
    • Do not carry laptops/USB sticks, or other electronics (cell phones were allowed when I was there), as you might have to leave them outside.
    • Steps
      • Go to counter (there are separate ones for Tatkaal and Normal; ask at entry, the Tatkaal counter might be less crowded). Get your documents checked. Get the token number. It will be printed on a small sheet. Keep this safe; you need it till the end.
      • Go inside, and wait for your token's turn. Large displays will indicate when it is your token's turn, and also the counter to go to.
      • First, you go to an A-counter, get the docs checked and pay the money. You get two copies of the receipt, one for you, and one that goes with the file. Keep both safe.
      • Then you again wait, looking at the displays, and go to a B-counter, where your documents are checked again. Finally you go to a C-counter, where your documents are checked again. The official stamps your old passport (if any), and tells you to leave.
      • Look for a counter where you get the acknowledgement for the passport application. Show your copy (the Applicant's Copy) of the receipt and get the acknowldegement. Go to the exit, return the token to the security guy, and leave.
    • I was there from 11am till 4pm. I got hungry, and ate a burger there. I had some stomach problems after that. You might want to take some food and water when you go there.
    • It can be a long wait. You could carry a book or something to kill the time, but you have to watch the displays alertly. I dont know what happens if you miss the chance.
    • When I was coming out the PSK at 4pm, the police were carting away two-wheelers parked in the 'No Parking' area in front of the PSK. Ensure you park your vehicle in a safe place before you enter the PSK.

Monday, July 11, 2011

Marriage Registration Procedure

In India, in order to register your marriage, do this:
  • Get the following (with photocopies)
    • identity proof (for both husband and wife)
    • age proof (for both husband and wife)
    • address proof (for both husband and wife)
      • only one of these needs to be within the jurisdiction of the registrar office you are going to.
    • marriage proof (photograph of the ceremony, or the wedding invitation)
    • Three witnesses
      • Any 3 witnesses will do, but there should be at least one from the husband's side, and one from the wife's side.
      • They should come with their photo ID.
    • 5 Photos
      • Should be a joint photo of husband and wife.
      • B5 size (double of passport size) 
  • Find out the location of the Sub-registrar office in the area of your residence (there might be problems of jurisdiction; call and confirm if that office is the right one).
  • Call them and confirm that the list above is correct and sufficient.
  • Find out when the office opens, and go there early (usually 10 to 10.30 am).
  • You will have to spend some time filling forms. (They are also available online. You could print them out, fill them at home, and take them there. But the rules/forms might have changed in the meantime. So, don't expect that things will go smoothly.)
  • Submit all forms and documents; wait while they make the marriage certificate.
  • They will ask for "Charges/Fees", but may not give the receipt; be careful about that. You could ask beforehand if they are going to give you a receipt for the whole amount that they quote as "charges".

Friday, July 8, 2011

Location of LaTeX packages

Directories where latex looks for packages:
/usr/local/share/texmf/ls-R...
/var/lib/texmf/ls-R-TEXMFMAIN...
/var/lib/texmf/ls-R-TEXLIVE...
/var/lib/texmf/ls-R...

Command to update tex about where to look for packages : texhash <new locn>

To add a .sty file where latex can find it, do
$ kpsewhich -var-value=TEXMFHOME
/home/gtholpadi/texmf
$ cp mystyle.sty /home/gtholpadi/texmf/tex/latex/local
"tex/latex/local is usually reserved for stuff installed on individual machines" (from here).

Wednesday, June 29, 2011

Using Zotero

  • Install Zotero add-on in Firefox.
  • Go to Zotero Preferences.
    • Set username, password under 'Sync'.
    •  Untick 'Sync automatically', 'Sync attachment files...'
    • Set Data Directory Location under 'Advanced'.
  • Copy citation from web page into clipboard; Choose 'Import from clipboard'.
  • Add note; add attachment (stored copy of file).
  • In the note, add a line containing labels or search terms for which this paper should be found.
  • Drag and drop paper into 'Research'; delete the entry under 'Import Wednesday...'.
  •  Read paper; edit note.
  • Click the sync button.

Sunday, May 22, 2011

Using tar and gzip

To tar a list of files/directories, do
tar -cf mytar.tar file1 file2 dir3 file4
To add more files to this, do
tar -rf mytar.tar file5 dir6 dir7
To list the contents of the tar, do
tar -tf mytar.r
To delete files from the tar, list the contents, do
tar --delete -f mytar.tar file1 dir2
using the exact path as given in the `list contents' step.

To compress the tar, do
gzip -c mytar.tar > mytar.tar.gz
To decompress the file, do
gunzip -c mytar.tar.gz > mytar.tar

To extract files from the tar, do
tar -xf mytar.tar file2 dir3
To extract everything, do
tar -xf mytar.tar

To simultaneously tar and compress, do
tar -czf mytar.tar.gz file1 dir2 file3
To simultaneously decompress and extract, do
tar -xzf mytar.tar.gz
(Note: Additions, using tar -rf, are not allowed for compressed tar files)

Friday, May 20, 2011

Using wget

Full Site
To download a full website, do
wget -c -w 15 --mirror -p -k -P /path/to/dir http://my.website.com -a my.log
This will download the entire website, waiting 15 seconds between retrievals. It will copy everything needed to show the page correctly (-p), convert links for local viewing (-k), store the files in /path/to/dir (-P), and write (append) messages to my.log (instead of the console). If stopped in between, run this command again, and it will start where it left off (-c).

Add --spider at the end to do a dry run first.
Add --random-wait to vary the wait time (for sites that block automated downloading).
Add --limit-rate=20k to limit download speed to 20 kilobytes per second (an example politeness limit; use your discretion).

Courtesy: this, this and this.

Small part of site
To download a small part (e.g. a given page and its first-level links) to the current directory, do
wget -c -w 3 -a my.log -r -l 1 -p -k http://somesite.com/interesting/link.html
This will download the page link.html and all links in it (-r), but will not recurse further to links of links (-l 1).

A URL list
To download a list of files specified by URLs, do
wget -c -w 15 -i urls.txt
This will download all URLs listed in the file urls.txt.

Thursday, April 21, 2011

Backup and Restore using rsync

I backup my data onto a second hard disk in my PC, like this:

rsync -av --delete /disk1/my/data /disk2/backup > backup.log 2> backup.err

This creates a folder called data in /disk2/backup and copies the contents of the folder /disk1/my/data to it.

If I rerun this command, it will copy only the changed files/directories from /disk1/my/data into /disk2/backup/data.

Restore is simple; /disk2/backup/data is like a mirror. Just browse and copy back whatever is needed.

Note: Using /disk1/my/data/ (with the trailing slash) instead of /disk1/my/data does not cause the directory data to be created. The contents of data are copied directly into backup.

For a one-time copy to an external hard disk, I did this:

rsync -avW --no-compress --delete --modify-window=2 /path/to/src  /path/to/dst > bakup.log 2> bakup.err


Compression is useful for network transfers but can be skipped for local copying. The 'modify-window' option was required since the destination was on an NTFS drive, and there could be time stamp issues when copying from ext3 to NTFS. The 'W' option (copy whole files) might speed things up since partial file transfer need not be supported.

Thursday, March 31, 2011

Latex Math Tips

Summations
  • If summations become cramped, use \displaystyle before \sum.
  • If summations should be cramped, use \textstyle before \sum.

Numbering lines of equations using align
  • Use align to number all lines; use align* to switch off numbering
  • In align, use \notag before \\ to switch off numbering for a line
  • In align*, use \tag{...} to number (or rather tag) a line
  • Given a numbered/tagged line, use \label{...} before \\ to refer to the line using \ref{...}.
  • Use \allowdisplaybreaks to allow a single equation block to be split over two pages.
Canceling terms in expressions
  • \usepackage{cancel}
  • Four options: \cancel{...}, \bcancel{...}, \xcancel{...}, \cancelto{<val>}{...} (in math mode)
  • Use \usepackage{ulem}, \sout{...} to strike out text.
Others
  • Use \boxed{} to put a box around equations(to highlight them). Note: If you use it within the align environment, it should not contain the `&'; otherwise it will give an error.
  • Use \newcommand{\myfrac}[2]{\ensuremath{\frac{#1}{#2}}} to define new commands (\myfrac) with many (2) arguments, and specify replacement latex code (\ensuremath...), including references to the arguments (#1, #2, ...). The new command can now be used in normal latex code (\myfrac{a}{b}). Aside: \ensuremath{} forces its contents to be interpreted in a math environment.

Wednesday, March 30, 2011

Thursday, March 24, 2011

Using xargs to redirect to command line arguments

To delete all .bak files in a directory, do
rm *.bak or ls *.bak | xargs rm
Essentially, rm is executed once with the whole of the piped input as argument.

To move the .bak files to another place, do
mv *.bak diffdir or ls *.bak | xargs -I var1 mv var1 diffdir.
Here, mv is executed separately for each file listed by ls. var1 is a placeholder. It is replaced each time by a file, and mv is executed.

To rename the .bak files to .bakup files, do
ls *.bak | xargs -0 -I {} mv {} {}up.
{} is another way of specifying a placeholder. -0 takes care of white space anomalies in the piped input.

Friday, March 11, 2011

Vim Tips

  • To beautify code (or pretty print, or auto indent), type ESC gg = SHIFT-G. This means:
    • ESC --> back to mode
    • gg --> go to first line
    • = --> indenting
    • SHIFT G --> to end of file.
(Courtesy snipplr.)
  •  To search and replace starting from the cursor type ESC :.,$s/foo/bar/gc. This means:
    • ESC --> back to mode
    • : --> command mode
    • .,$ --> from current line (.) till (,) end of file ($)
    • s --> substitute (foo with bar)
    • g --> all occurrences in a line
    • c --> confirm before replacing
 (Courtesy wikia.)

Monday, February 28, 2011

Problem with sound recording in Ubuntu 9.04

Configuration:
Ubuntu 9.04, HDA Intel (Alsa Mixer)

Problem:
I am using a headphone with mic. I have plugged in the mic, in the right socket. It seems that I have configured everything in Alsa Mixer right. But still sound recording does not work.

Solution:
Go to Volume Control -> HDA Intel (Alsa Mixer) -> Options -> Input Source (the first one). If it is 'Mic', change to 'Front Mic'. Try recording; it will fail. Now change it back to 'Mic'. Try recording again; it should work now.

[microphone, audio, voice]

Installing Logitech WebCam C210 on Ubuntu 9.04

The title is deceptive, implying one has to do something. Actually, it works right out of the box!

1. The Logitech Webcam C210 comes with a USB connector. Plug it in.
2. Install Cheese - sudo apt-get install cheese
3. Run cheese. You can now start recording video and taking pictures!

See https://help.ubuntu.com/community/Webcam.

Wednesday, February 23, 2011

Linux commands for gzip and bzip2


These examples are for compressing/decompressing, and preserving the original file.

Gzip-ing and gunzip-ing -
cat abc.txt | gzip > abc.gz
gzip -cd zbc.gz > abc.txt (-d decompress, -c send to console)

and similarly for bzip2 and bunzip2 -

cat abc.txt | bzip2 > abc.txt.bz2
gzip -cd abc.txt.bz2 > abc.txt

Some commands that operate directly on gzip-ped files -
zcat abc | less (abc can be a text file or a gzip-ped file)
zless def (the file need not have extension .gz)
zdiff abc.gz def
zgrep "pattern" abc.gz

and similarly for bzip2, we have bzcat, bzless, bzdiff and bzgrep.

Sunday, February 20, 2011

Opening/Creating .zip files in linux

Opening
To extract contents of abc.zip (keeping original zip file) --- unzip abc
To just list the contents --- unzip -l abc
To extract a specific file def.txt --- unzip -p abc def.txt > mydef.txt (where def.txt was listed in previous step)

Creating
To create abc.zip (keeping original files) --- zip abc def.txt xyz.txt ...
To zip a directory /path/to/dir1 --- cd /path/to; zip -r abc dir1
To add a file to existing zip file abc.zip --- zip /path/to/abc.zip lmn.txt (Do not give /path/to/lmn.txt)

Wednesday, February 9, 2011

Mounting drives using HAL in Ubuntu

Some drives in Ubuntu are mounted using HAL. To change the mount options for these drives, do the following -
  • Run gnome-mount -u -d /dev/sdb1.
  • Run gnome-mount -d /dev/sdb1 --display-settings to view current settings.
  • Run gnome-mount -d /dev/sdb1 --write-settings --mount-options umask=000,opt2,opt3=foo to set the mount options. 
  • If you want to keep the existing options and change/add only a few, then use gnome-mount -d /dev/sdb1 --write-settings --extra-mount-options opt4,opt5=foo.
  • Now mount the drive in the usual way (from Nautilus).
To see complete details about the drives mounted by HAL, run lshal.

(In the /dev/sdb2 example above, remember that umask=000 gives everyone all permissions; so it is the inverse of what you would give for chmod.)

Monday, February 7, 2011

Typing in Indic languages in Ubuntu using ITRANS

(For Ubuntu 10.04, see further below.)

Ubuntu 12.04

I found this tip that made things really easy. To summarize:
  • Install ibus-m17n.
  • Go to System Settings -> Language Support -> Keyboard input method system. Choose `ibus'. Close the dialog.
  • Click on Dash Home. Type ``ibus'' and click on the ``IBus'' icon that appears. A keyboard icon appears in the system tray (top right of screen).
  • Click on the keyboard icon -> Preferences -> Input Method -> Customize active input methods -> Select an input method -> (Now choose your language and input method). Click on Add. (Add as many as you want.) Close the Preferences dialog.
  • Open a new document in gedit. Click on the keyboard icon and select the input method (the default setting will be ``Input method Off'').
  • Start typing in your preferred language.

Ubuntu 10.04

To type in Indic languages in Ubuntu using ITRANS scheme, do the following
  • Go to synaptic; install
    • TrueType fonts for required language (search for language name, e.g. 'kannada')
    • SCIM
    • m17n
    • itrans
  • Run gedit
  • Right-click on editor. Select 'Input Methods' -> 'SCIM Input Method'. The SCIM icon (a keyboard) will appear in system tray (where date etc. are there).
  • Go to 'Kannada'-> 'kn-trans'. (Or to any other language)
  • Go back to editor and start typing in Indic using the ITRANS scheme (see below).

ITRANS Scheme (copied from here)

Vowels (dependent and independent):
-------
a     aa / A       i      ii / I       u     uu / U 
RRi / R^i    RRI / R^I    LLi / L^i    LLI / L^I
e     ai     o     au     aM    aH

Consonants:
----------- 
k     kh     g     gh     ~N
ch    Ch     j     jh     ~n
T     Th     D     Dh     N
t     th     d     dh     n
p     ph     b     bh     m
y     r      l     v / w
sh    Sh     s     h      L
x / kSh     GY / j~n / dny     shr
R (for marathi half-RA)
L / ld (marathi LLA)
Y (bengali)

Consonants with a nukta (dot) under them (mainly for Urdu devanagari):
-----------------------------------------
k  with a dot:      q
kh with a dot:      K
g  with a dot:      G
j  with a dot:      z / J
p  with a dot:      f
D  with a dot:      .D
Dh with a dot:      .Dh

Specials/Accents:
-----------------
Anusvara:       .n / M / .m  (dot on top of previous consonant/vowel)
Avagraha:       .a    (`S' like symbol basically to replace a after o)
Ardhachandra:   .c    (for vowel sound as in english words `cat' or `talk')
Chandra-Bindu:  .N    (chandra-bindu on top of previous letter)
Halant:  .h    (to get half-form of the consonant - no vowel - virama)
Visarga:        H     (visarga - looks like a colon character)
Om:  OM, AUM (Om symbol)


[As shown, many codes have multiple choices, example "RRi / R^i" implies you
 can use either "RRi" or "R^i"]

Friday, February 4, 2011

Setting classpath when compiling/running Java

Set the CLASSPATH environment variable to
- the directories having .class files
- the .jar files which contain relevant .class files

Then run javac and java; it will pick required the .class files from its location.

If you say
export CLASSPATH=dir1
and the .class file is dir1/dir11/abc.class, then you must say
java dir11.abc
to enable java to find abc.class.

Thursday, February 3, 2011

Verifying checksums in linux

Kinds of checksum algorithms - md5, sha1, sha224, sha256 etc.

Given a file abc and a checksum a1b23c using the md5 algorithm, run
md5sum abc | grep "a1b23c"
If the output is "a1b2c3      abc", the check succeeded.
If there is no output, the check failed.

md5sum calculates the checksum for the file abc using the algorithm md5 and prints to console. grep checks if that's the checksum you expected. If the check failed, grep will be silent.

Replace md5sum with sha1sum, sha224sum etc.

Each algorithm uses a certain number of bits for the calculation. The more bits the algorithm uses, the better.

md5 - 128 bits
sha1 - 160 bits
sha224 - 224 bits
sha256 - 256 bits
etc.

Sunday, January 30, 2011

LaTeX 'dash' usage

In LaTeX, use:

hyphen (-) : in compound words [daughter-in-law]
en-dash (--) : in number ranges [pages 31--45]
em-dash (---) : the normal dash in English punctuation
minus ($-$) : the math symbol

Tuesday, January 18, 2011

Reading data from file in matlab

If  the file is nicely formatted (without headers, consistent tab/space separated columns, and nothing else)
  • A = load('filename'); 
Other options include textscan, fscanf etc. - not yet tried them.

Tuesday, January 4, 2011

Linux shell options

Use command shopt to see and set linux shell options.

For example, shopt -s extglob  sets extglob to on. You can now use negative glob expressions in commands, such as rm !(*.dnd) to delete all files except those ending with .dnd.