\sbox
is a short form of \savebox
in the same way that \mbox
is a short form of \makebox
for the common case where you do not need to specify any lengths and want the natural size of the box. \setbox
is the underlying TeX primitive so it does not read its arguments as a normal macro (like the comparison between \hbox
and \mbox
) and it is not safe to use with colour commands unless you take extra precautions to insert extra groups, that the LaTeX versions do automatically.
Added note: One other important difference I forgot before, it is implicit in the examples below but not highlighted. \sbox\boxa{aa}
is like \setbox\boxa\hbox{....}
so it supplies the \hbox
. So if you need to save vertical material you need to save a vbox in an hbox, whereas with \setbox
you can do \setbox\boxa\vbox{aaa \par bbb}
however there is not much difference between a vbox and an hbox containing a vbox, unless you start using unboxing primitives, so this difference isn't a major one in practice.
UPDATE examples added as requested (the source is more informative than the output)
\documentclass{article}
\tracingonline2
\showboxdepth10
\showboxbreadth10
\usepackage{color}
%these are the same except the latex version \newsavebox
%checks that the name is not already used.
\newbox\boxa
\newsavebox\boxb
\begin{document}
\setbox\boxa\hbox{abc}
\sbox\boxb{abc}
The above look the same but see
%\showbox\boxa
%\showbox\boxb
\begin{verbatim}
> \box26=
\hbox(6.94444+0.0)x15.27782
.\OT1/cmr/m/n/10 a
.\OT1/cmr/m/n/10 b
.\kern0.27779
.\OT1/cmr/m/n/10 c
! OK.
\end<verbatim}
\begin{verbatim}
> \box27=
\hbox(6.94444+0.0)x15.27782
.\pdfcolorstack 0 push {0 g 0 G}
.\OT1/cmr/m/n/10 a
.\OT1/cmr/m/n/10 b
.\kern0.27779
.\OT1/cmr/m/n/10 c
.\pdfcolorstack 0 pop
\end{verbatim}
The LaTeX version has extra specials inserted so that colour acts like
fonts and stays with the box.
If you \emph{use} colour in the box it gets more serious
\setbox2\vbox{{% stop this broken test leaking to the page
\setbox\boxa\hbox{ab \color{red}c}
%\showbox\boxa
\begin{verbatim}
> \box26=
\hbox(6.94444+0.0)x18.33336
.\OT1/cmr/m/n/10 a
.\OT1/cmr/m/n/10 b
.\glue 3.33333 plus 1.66666 minus 1.11111
.\pdfcolorstack 0 push {1 0 0 rg 1 0 0 RG}
.\OT1/cmr/m/n/10 c
\end{verbatim}
See the box just contains a color push and the color pop is not saved
in the box but happens at the point of the save, so the colour stack
is corrupted which depending what you are doing can crash your printer
or just get the wrong colours or\ldots.
\setbox\boxa\hbox{{ab \color{red}c}}
%\showbox\boxa
\begin{verbatim}
> \box26=
\hbox(6.94444+0.0)x18.33336
.\OT1/cmr/m/n/10 a
.\OT1/cmr/m/n/10 b
.\glue 3.33333 plus 1.66666 minus 1.11111
.\pdfcolorstack 0 push {1 0 0 rg 1 0 0 RG}
.\OT1/cmr/m/n/10 c
.\pdfcolorstack 0 pop
\end{verbatim}
see that fixed it and the pop and push are now matched.
\sbox\boxb{ab \color{red}c}
%\showbox\boxb
\begin{verbatim}
> \box27=
\hbox(6.94444+0.0)x18.33336
.\pdfcolorstack 0 push {0 g 0 G}
.\OT1/cmr/m/n/10 a
.\OT1/cmr/m/n/10 b
.\glue 3.33333 plus 1.66666 minus 1.11111
.\pdfcolorstack 0 push {1 0 0 rg 1 0 0 RG}
.\OT1/cmr/m/n/10 c
.\pdfcolorstack 0 pop
.\pdfcolorstack 0 pop
\end{verbatim}
Latex gets it right.
}}% this box not put into the page so the colour stack is not
% corrupted.
Even without colour there are differences
\setbox\boxa\hbox{aa\verb|\relax|}
%\showbox\boxa
\begin{verbatim}
> \box26=
\hbox(6.94444+0.8333)x41.49976
.\OT1/cmr/m/n/10 a
.\OT1/cmr/m/n/10 a
.\hbox(0.0+0.0)x0.0
.\OT1/cmtt/m/n/10 \
.\OT1/cmtt/m/n/10 r
.\OT1/cmtt/m/n/10 e
.\OT1/cmtt/m/n/10 l
.\OT1/cmtt/m/n/10 a
.\OT1/cmtt/m/n/10 x
\end{verbatim}
%\sbox\boxb{aa\verb|\relax|}% commented out as it makes an error.
\begin{verbatim}
! Missing } inserted.
<inserted text>
\end{verbatim}
\end{document}
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.
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.
You never (with no exception) change \@outputpage
, unless your name is Frank and you're German (plus some other strict conditions).
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.
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.
Best Answer
\box
also clears the box register. Use\copy
instead.I would use
\hfill
instead of\hss
. Then TeX will throw an overfull\hbox
warning, if the place is not sufficient.A centered version can be achieved via
\halign
:Smaller space between letters
The following example uses different methods to reduce the space between the letters. The first boxes 0, 2, 4 (even numbered boxes smaller than ten are scratch boxes for local assignments) keep the distance between the baselines constant. Box 0 is the unmodified version. Box 2 shrinks the
\baselineskip
according to egreg's comment. The extreme is in box 4, where the maximum letter height is measured with the result that the two "t"s are in touch.The boxes 6 and 8 keep the distance between the letters constant. Because of
\baselineskip=0pt
, TeX switches to set\lineskip
instead. It's default value is1pt
. Box 8 finally does not leave any space between the letters.