Text files and me - Part 3

I ended the second installment of this odd memoir in the early 2000s. I was using Linux, editing my files mostly in NEdit, and generating paper reports for my clients though a combination of SGML and groff. This episode will cover my switch to LaTeX.

You may recall from last time that an important reason for my choosing troff/groff over LaTeX in the first place was troff’s superior ability to put text at specific locations on a page; this was important to me because my reports at the time usually included photographs—actual 3×5 prints that I would paste down onto the pages of a report—that needed precisely located captions.

Around 2000, though, I started using a digital camera and realized that inserting the images directly into my reports was much better than printing them out separately and physically pasting them in, as I had done with the photographic prints. This meant that LaTeX was a contender again. It could keep the captions and images together, and with a little extra coding I could even get the captions of portrait-oriented photos to appear alongside the images rather than below them.

Of course, “a little extra coding” quickly led to a 400-line style file that

The last two deserve a little explanation.

I first ran into LaTeX when I was an assistant professor in the late ’80s. When organizing conference sessions, I’d get submissions from the various people who were going to present papers. Back then, many of the submissions were still typewritten, but most were laser-printed from word processors. A few were clearly laser-printed with nicely laid-out equations, but they didn’t look like any word processor output I’d ever seen—mainly because of the font. The font was a spindly thing I didn’t recognize, so thin that it looked like the paper was printed with gray ink instead of black. It was Computer Modern, and I thought it was the ugliest thing I’d ever seen.

Computer Modern sample

(Computer Modern sample from Pmx at Wikipedia.)

I’ve since come to realize that the ugliness of Computer Modern in the ’80s was mostly due to the low resolution of the standard laser printers of the time. Ten-point Computer Modern does look like crap at 300 dpi, but it’s much better at 600 dpi and above.

Still, I didn’t really want my reports coming out in Computer Modern. I spent more time than I care to think about learning how LaTeX deals with fonts. OT1, T1, Cork, the Beebe font naming convention—once upon a time, I was conversant with all of these things, and I put together a system for choosing among four different font sets as my mood and tastes changed:

Optima sample

(Optima sample from GearedBull at Wikipedia.)

I chose to define a new float type specifically for photos because I wanted to distinguish plots and drawings, which would be interspersed with the body text, from photographs, which would be printed on special paper in their own section at the end of the report. This is similar to the way many books are published, with special “plates” sections.

I’m no great TeX programmer. I basically just lifted the code for figures out of the standard LaTeX article.cls file and changed a few things here and there.

tex:
 1:  % Define a float for plates. These are taken directly from the
 2:  % article.cls and report.cls definitions for the figure environment
 3:  % with the word "figure" replaced with "plate," "lof" with "lop,"
 4:  % and the ftype set to 4 instead of 1.
 5:  \@ifundefined{@makechapterhead}
 6:  { \newcounter{plate}
 7:    \renewcommand \theplate {\@arabic\c@plate}
 8:    \def\fps@plate{tbp}
 9:    \def\ftype@plate{4}
10:    \def\ext@plate{lop}
11:    \def\fnum@plate{\platename\nobreakspace\theplate}
12:    \newenvironment{plate}
13:                   {\@float{plate}}
14:                   {\end@float}
15:    \newenvironment{plate*}
16:                   {\@dblfloat{plate}}
17:                   {\end@dblfloat}
18:    \newcommand\listofplates{%
19:        \section*{\listplatename}%
20:          \@mkboth{\MakeUppercase\listplatename}%
21:                  {\MakeUppercase\listplatename}%
22:        \@starttoc{lop}%
23:        }
24:    \newcommand*\l@plate{\@dottedtocline{1}{1.5em}{2.3em}}
25:    \newcommand\listplatename{List of Plates}
26:    \newcommand\platename{Plate}
27:  }
28:  { \newcounter{plate}[chapter]
29:    \renewcommand \theplate
30:         {\ifnum \c@chapter>\z@ \thechapter.\fi \@arabic\c@plate}
31:    \def\fps@plate{tbp}
32:    \def\ftype@plate{4}
33:    \def\ext@plate{lop}
34:    \def\fnum@plate{\platename\nobreakspace\theplate}
35:    \newenvironment{plate}
36:                   {\@float{plate}}
37:                   {\end@float}
38:    \newenvironment{plate*}
39:                   {\@dblfloat{plate}}
40:                   {\end@dblfloat}
41:    \newcommand\listofplates{%
42:        \if@twocolumn
43:          \@restonecoltrue\onecolumn
44:        \else
45:          \@restonecolfalse
46:        \fi
47:        \chapter*{\listplatename}%
48:          \@mkboth{\MakeUppercase\listplatename}%
49:                  {\MakeUppercase\listplatename}%
50:        \@starttoc{lop}%
51:        \if@restonecol\twocolumn\fi
52:        }
53:    \newcommand*\l@plate{\@dottedtocline{1}{1.5em}{2.3em}}
54:    \newcommand\listplatename{List of Plates}
55:    \newcommand\platename{Plate}
56:  }

The nice thing about outright theft like this is that I got a lot of well-debugged functionality with my new float. The plates are, for example, automatically numbered. My reports are seldom long enough to require chapters or a table of contents, but when they are the plate numbers get chapter number prefixes, and I can easily generate a List of Plates for the frontmatter.

I’ve been using this style file for a decade or so—first writing in LaTeX directly and later writing in Markdown that gets converted to LaTeX—and it works very well for me. Except in special cases, like sideways figures, I really don’t have to think about formatting at all; the formatting rules I like (and spent a lot of time thinking about ten years ago) get applied automatically.1 I can’t post it all here or on GitHub because it includes company-specific information, but I’ve often thought there may be some benefit to replacing the private information with generic placeholders and letting other use and improve it.

I should mention that the most valuable LaTeX reference book I have is Kopka and Daly’s Guide to LaTeX. It’s great not only for writing in LaTeX (which I don’t do much of anymore) but also for programming in it. I have Knuth’s TeXbook, Lamport’s ur-LaTeX book, and the absurdly huge LaTeX Companion, but Kopka and Daly is what I pull off the shelf when I need a question answered quickly. I don’t know how I would have written my style file without it; the file is littered with comments like “See Kopka & Daly C.3.1” so I can go back to the original source of my code.

This turned out to be a bit longer post than I planned. My switch back to the Macintosh and the move to Markdown will have to wait until the next post in this pulse-pounding series.


  1. Occasionally, I find myself working for a client with odd ideas about how engineering reports should be formatted. “I’d like you to change all the section numbers to letters,” was one request. I politely but firmly refuse. The whole point of doing all that work ten years ago was to never have to do it again, and I will not sink any time into one-off formats. I’m sure these clients think me a bit eccentric for resisting something they must view as trivial, but in a strange way the refusal gives me additional authority. Firm conclusions are important in my line of work, and there’s nothing firmer than a guy who insists that his sections be sequenced 1-2-3 instead of A-B-C.