# [Tex/LaTex] LaTeX for plain TeX users

plain-tex

Does there exist some concise documentation showing, for things commonly done in plain TeX, the recommended/idiomatic “LaTeX way” of doing something equivalent? Or if not, what are the most common such things to know?

Background/context: Recently, while answering a question about an unusual page layout, I first wrote an answer in plain TeX, then started trying to make it work with LaTeX. In doing this, I discovered a few things, like:

1. In LaTeX (and with typical document classes I guess), to change the dimensions of the main text area, don't directly change \hsize and \vsize. Instead, it is simplest to change \textwidth and \textheight.
2. To control the page output, don't redefine what \output does with \box255, but what \@outputpage does with \box\@outputbox.
3. To affect the offset of the main text area on the page, change not just \hoffset and \voffset, but also \oddsidemargin, \evensidemargin, \topmargin, \headheight, and \headsep.
4. The page numbering counter is stored not in a TeX count register called \pageno but in a LaTeX counter called page.

These are just examples (and some may be wrong); I'm asking about the general case where someone has written some (relatively straightforward) plain TeX document (understanding what it does), and wants to change it to work with LaTeX. What would be some useful things to know, in this case?

I'm aware that this may not be a question with a perfect answer, so I'd be perfectly happy with any of the following kinds of answers:

• There is such a document, at [location]. Or: there are only a few main things to know, namely [list].

• There is no such document: you simply have to learn the whole of LaTeX by reading [Book1], [Book2], and/or by reading through the LaTeX sources (texdoc source2e).

• There are a few kinds of things, and each of them is covered in a different kind of documentation: [X] for topic [T1], [Y] for topic [T2], …

• If you're using simple plain TeX, the main thing to know is the LaTeX equivalents of facilities provided by the ~1000-line plain.tex. A translation of those into LaTeX is: […].

Edit: It has been pointed out to me that in a LaTeX document one should simply not do any of the above things. And I completely agree!

I should have made this clear earlier, but I was not thinking clearly myself:

• In a LaTeX document, as a “user” of LaTeX, one should not resort to such “raw” typesetting. (So the answer to the above question, if it's being asked as a LaTeX user, is “just don't do that”.) Instead, one expresses one's intentions as some combination of invocations of package-provided commands.

• In a LaTeX package or class, as the author of the package/class, is the only place to fiddle with typesetting. My question is about this part: where can you learn the LaTeX equivalents of such plain TeX commands, to accomplish common typesetting solutions in LaTeX? (I do understand that you should then also provide good commands so that users of your package can express themselves logically/semantically.)

For example, from plain-TeX version in revision 1 of the linked answer, to get something that compiles in LaTeX (let's say I wanted to make it a package), I cobbled together something through a combination of reading source2e.pdf, reading other packages' implementations (poorly commented) of similar solutions, randomly searching the internet and this site, using \show and \message to debug what's going on, and sometimes pure guesswork. My question is: if you want to write a package to accomplish certain kind of typesetting, where would one learn this instead?

First some personal experience: for one of the conference proceedings I was in charge of for the TeXnical aspects, I got several papers to put into shape. One of them was in Word: I asked for a printout and then converted the “saved as text” version line by line following the printout.

Another one was in plain TeX. The conversion was quite easy: I changed the initial macro definitions to use \newcommand or \newtheorem; then I went through the document and the translation to LaTeX was a rather short and easy job.

Much more painful was translating most papers from their authors' concept of LaTeX to the real one.

1. You never use \hsize in a LaTeX document, not even in the preamble (sole exceptions, some tricks with tabularx). Using \textwidth is not “simpler”: would you say that driving on the left side in the UK is simpler? Well, it's the same: setting the text width with \hsize is like driving on the right side in the UK.

2. You never (with no exception) change \@outputpage, unless your name is Frank and you're German (plus some other strict conditions).

3. While it's possible to specify page parameters by explicitly changing \oddsidemargin and friends, it's much better done with geometry. By the way, \hoffset and \voffset should always be zero.

4. The current value of the page number is accessible as \thepage (which changes according to the chosen numbering style). Using \value{page} (or \c@page) should be a very rare need. Besides, one should not use \pageno in plain TeX document, but \folio, that's analogous to \thepage.

Probably your point 2 is about adding structure the the header and footer; this is done with packages such as fancyhdr, scrlayer-scrpage or titleps.

If you use \beginsection and \proclaim, it's not difficult to switch to LaTeX; of course, you'll remove all manually assigned numbers.

Most common plain TeX constructions work also in LaTeX; the manual mentions \line among those having different meaning. Of course, no font selection command will work.

However, the mere fact that a plain TeX macro also works in LaTeX should not mean we can keep it. A typical example is \centerline, that has essentially no place in a LaTeX document (it's not color safe, for instance), but also \root 3\of{2017} should not be used.

Yes, I know that \centerline can in some cases get me simply out of a problem, but such usages should always be buried in macros defined in the preamble.

The well structured plain TeX document I mentioned before, was written in a logical fashion, with consistent markup. The markup was not the same as in LaTeX, but this was not a problem: I just had to make a translation table and apply some search-and-replace.

A badly written document, using plain TeX, AMS-TeX, ConTeXt, LaTeX, Lollipop or whatever format, is just badly written and sometimes it's a pain also making it a valid document for the original format.