18

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?

  • Tidied up a bit ;). – cfr May 11 '17 at 1:32
  • 1
    Mostly the LaTeX way is to use packages, like setting the page size using geometry. There is also the beamer way and the KOMA way. BTW, the counter page or count \c@page still use register \count0. Also, you can use the plain package to ease your transition. – John Kormylo May 11 '17 at 4:53
  • My biggest gripe was replacing \over with \frac (which I was convinced was introduced by a Battlestar Galactica fan just to use the word frac). – John Kormylo May 11 '17 at 4:58
  • @JohnKormylo Yes that's a good point—in fact that's what the conversation with @-cfr earlier was about. I've edited the question to clarify that that's not what I'm looking for. – ShreevatsaR May 11 '17 at 4:58
  • 1
    I don't think there is much existing documentation taking this point of view as (unlike in 1985) there are to a first approximation no readers for such a document. The vast majority of people learn latex first and only learn plain to construct simpler debugging examples and test cases or to understand the examples in the texbook. So at that level they need plain (or tex primitive) descriptions of latex constructs from an implementation level, not a simple user guide for plain tex authors. – David Carlisle May 11 '17 at 6:59
18

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.


About your specific points in the list, here's my two cent.

  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.

  • Thanks for an answer! I understand your answer as recommending what good LaTeX style is. (And I agree.) But the question I intended was rather: TeX itself is IMO simple to understand, at least in the way that assembly/machine language is simple to understand: it may be hard to get things done in it, but it is revealing of what's going on underneath: you know all that it is: a paragraph builder, a page builder, a “mouth” for macros… boxes and glue, this and that. It's just a tool that is transparent (though could be better). LaTeX is much more (structure etc.) and that's of course its strength… – ShreevatsaR May 11 '17 at 7:49
  • … Concretely: in the linked Q, I looked at a page, saw all that should go on the page, thought about how to use the tool (TeX) to achieve that output, and simply used the tool. (Of course, lacking experience, I may not have done things well, but at least I was able to understand the tool enough to accomplish something.) What would be the equivalent in LaTeX? First step would be: study the package ecosystem… but suppose I realized I had to write a package myself, now what? How does one know how to accomplish such things using the tool (LaTeX)? – ShreevatsaR May 11 '17 at 7:53
  • @ShreevatsaR The main defect of plain TeX is indeed it doesn't provide enough high level structures and users tend to use ad hoc solutions. I was looking at the source of the TeXbook and saw something like \raise.5ex\vbox{\hrule width 1em} which should instead be a macro defined once and for all. LaTeX is meant to relieve the user from going too deep in the “assembler code”. – egreg May 11 '17 at 8:19
  • 3
    my name isn't Frank:( – David Carlisle May 11 '17 at 8:45
  • 2
    @ShreevatsaR That's the main difference between Plain TeX and LaTeX: you usually don't have to reinvent the wheel, because somebody already has. – egreg May 12 '17 at 8:05
2

Perhaps my suggestion won't satisfy the "concise" requirement of your question, and still it's not at all clear to me what exactly do you want; but fwiw, I doubt there is an easy way to transition from Plain to LaTeX hacker as you mean to do. Afaik there is no LaTeX Programming Manual for LaTeX2e, and the one planned for LaTeX3 is still fairly elementary. So, in the meanwhile, I recommend to you to find a copy of Winter Snow's TeX for the Beginner, where the author occasionally compares some Plain hacks with their LaTeX counterparts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.