16 May 2006

Some of my LaTeX tricks

Every mathematician of the last 20 years should have their personal bag of LaTeX tricks. Here's a couple of mine:

  • Graphics. This, in particular, is an area where everyone has their own tricks. My standard procedure is as follows:
    • Create some graphic in XFig, making sure that all text is marked special. (You can do this automatically by editing your .xfigrc file.)
    • Using TransFig, convert this file into four formats: pstex, pstex_t, pdftex, pdftex_t. There's a catch here: you need to make sure that myfigure.pdftex_t version includes myfigure.pdf, not myfigure.pdftex, which is the default. I guess this counts as a bug. This chore is usually done by a script for me:
      #!/bin/sh
      # Convert all fig files to four other formats, using fig2dev.
      for FILE in *.fig; do
      FILE=`basename $FILE .fig`
      if [ $FILE.fig -nt $FILE.pstex ]; then
      fig2dev -L pstex $FILE.fig $FILE.pstex
      fi
      if [ $FILE.fig -nt $FILE.pstex_t ]; then
      fig2dev -L pstex_t -p $FILE.pstex $FILE.fig $FILE.pstex_t
      fi
      if [ $FILE.fig -nt $FILE.pdf ]; then
      fig2dev -L pdftex $FILE.fig $FILE.pdf
      fi
      if [ $FILE.fig -nt $FILE.pdftex_t ]; then
      fig2dev -L pdftex_t -p $FILE.pdf $FILE.fig $FILE.pdftex_t
      fi
      done
    • Then in my LaTeX file, I have this code in the preamble:
      \usepackage{ifpdf}
      \ifpdf
      \pdfcompresslevel=9
      \providecommand{\myinput}[1]{\input{#1.pdftex_t}}
      \usepackage[pdftex]{graphicx}
      \else
      \providecommand{\myinput}[1]{\input{#1.pstex_t}}
      \usepackage{graphicx}
      \fi
      and whenever I want to include the file myfigure.fig, I just write \myinput{myfigure}.
    This has several nice properties: you can use LaTeX math constructs in figures (just surround them with dollar signs) and it looks great in both PDF and DVI.
  • I'm very proud of the following piece of code:
    \newcounter{storedequation} % To store the equation number when we
    % temporarily change it.
    \let\storedtheequation=\theequation
    \newenvironment{lettereqns}[1]{%
    \setcounter{storedequation}{\value{equation}}%
    \setcounter{equation}{0}%
    \renewcommand{\theequation}{#1\arabic{equation}}}{%
    \setcounter{equation}{\value{storedequation}}%
    \renewcommand{\theequation}{\storedtheequation}}
    Now we have an environment lettereqns, with one parameter, which makes all equations in it be numbered (P1), (P2) etcetera if the parameter is P.

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home