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]