LaTeX is capable of most things but not always in the most obvious manner. Here are some useful tricks that you might struggle to find in the documentation. I’m not trying to teach you LaTeX there are two routes to that 1) read Leslie Lamport’s LaTeX book (or something similar) and 2) deconstruct other peoples documents and then try writing your own.

Dynamically Including Program Listings

You have written the perfect program and want to include it your report. Well you could do

-- Copy and paste your program to here --

However what happens when you suddenly find that your program has a bug or would be even better with some tweak. Then you would have to delete the copy from your report and repaste the new version. In preference you can use the verbatim package. This allows you to have a file printed in verbatim format (ie. looking like a typewriter) at the chosen point of your report.

At the head of your document (somewhere before


put the line


Then in the relevant location put


Now if you change your program rerun LaTeX will produce your report with the updated program.

Rotating Tables and Figures

You want to include the amazing results that you achieve with the program you wrote. No problem, just put them in a table. Unfortunately with all the conditions and outputs that you need to include you find that the table is to wide for the page. You need to find a way to show it in landscape format whilst leaving the rest of your document alone. Enter the rotating package. As before put


in the head of your document. This allows you to rotate text, tables and figures in every manner that your liable to want. To create the table use the sidewaystable instead of table. For example (lifted from the file rotating.tex in the package documentation).

Context   &Length   &Breadth/   &Depth   &Profile   &Pottery   &Flint   &Animal   &Stone   &Other    &C14 Dates \\
  &         &Diameter   &        &          &          &        & 
\multicolumn{10}{|l}{\bf Grooved Ware}&\\
784 &---   &0.90m &0.18m &Sloping U &P1    &$\times$46  &  $\times$8  &&$\times$2 bone&  2150$\pm$ 100 BC\\
785 &---   &1.00m &0.12  &Sloping U &P2--4 &$\times$23  &  $\times$21 & Hammerstone &---&---\\
962 &---   &1.37m &0.20m &Sloping U &P5--6 &$\times$48  &  $\times$57* & ---&     ---&1990 $\pm$ 80 BC (Layer 4) 1870 $\pm$90 BC (Layer 1)\\
983 &0.83m &0.73m &0.25m &Stepped U &---   &$\times$18  &  $\times$8 & ---& Fired clay&---\\
\multicolumn{10}{|l}{\bf Beaker}&\\
552 &---   &0.68m &0.12m &Saucer    &P7--14 &---        & --- & --- &--- &---\\
790 &---   &0.60m &0.25m &U         &P15    &$\times$12 & --- & Quartzite-lump&--- &---\\
794 &2.89m &0.75m &0.25m &Irreg.    &P16    $\times$3   & --- & --- &--- &---\\
\caption[Grooved Ware and Beaker Features, their Finds and Radiocarbon
Dates]{Grooved Ware and Beaker Features, their Finds and Radiocarbon
Dates; For a breakdown of the Pottery Assemblages see Tables I and
III; for the Flints see Tables II and IV; for the Animal Bones see
Table V.}\label{rotfloat2} \end{sidewaystable} 

This method puts the table on a page on it’s own. This is probably what you want if your table is that wide. If however you don’t want it on a separate page this can be achieved using the sideways and rotcaption in conjunction with the standard table command. See the examples file (/usr/local/tex/texmf/doc/latex/rotating/examples.tex on my system) for details.

There are a couple of points worth noting. The table will not appear rotated when you look at the resultant dvi file. You need to convert it to postscript to see it. This happens automatically when you print it but should you want to preview it use the command dvips [filestem] -o. So for the file report.dvi enter dvips report -o. The other is that if you intend to print the final report two sided then it if you include twoside in the document class definition then the table should be oriented the correct way depending on whether the page is odd or even. So for example


The command sidewaysfigure works similarly. If you use the epsfig package to include eps files then there is another method for rotating the diagram without changing the caption. This can be achieved by, for example:

    \epsfig{figure=test.eps, angle=67}

If you don’t have the rotating package installed locally you should be able to find it a CTAN repository, e.g.

Maths Tricks

If you have to type much in the way of maths it is worth investigating the AMS-LaTeX packages. Being designed by the American Mathematical Society they cover pretty much anything you are ever likely to need if it isn’t provided by the standard LaTeX commands. There is very full documentation should be available on your system (/usr/local/tex/texmf/doc/latex/amslatex/amsldoc.dvi on my installation).

If you have tried to include text in an equation environment then you’ll have found that the result is italicised and there are no spaces (unless you explicitly include them). The best way to do this is to use the amstext package (so \usepackage{amstext}) and then you can write

\$f(x)=\sum_{n>o}{\frac{x}{n^2}}=3 \text{ if the moon is full and } x < 5\$

and other such pearls of wisdom. If you need a maths symbol and don’t know it or have the manual handy look at the file /hame/iangl/public/latex_maths.dvi which includes most of them (I think).

For a quick way to preview equations you can use one of the online LaTeX renders like this one

Doing wordcounts

There is no particularly good way (that I know of) to do wordcounts of a LaTeX document. However within certain limits (which you’d have to be particularly obtuse to violate) the following works reasonably.

detex [filename] | wc -w

And that’s all folks.