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)