## 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.
•  Untick 'Sync automatically', 'Sync attachment files...'
• Set Data Directory Location under 'Advanced'.
• Copy citation from web page into clipboard; Choose 'Import from clipboard'.
• 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...'.
• 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
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.

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

A URL list
wget -c -w 15 -i 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

### Solving equations in MATLAB

syms a b c x - declare variables
solve('a*x^2 + b*x + c') - solve equation

## 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.

## Tuesday, March 22, 2011

### List of Tech Tools/Packages/Projects

disco - distributed computing framework based on the MapReduce paradigm

## 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.)

## 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)