Will reusing \sbox-ed cmds reduce DVI/PDF size?
No, saveboxes created with \sbox
and friends do not reduce the final file size. The content is written to the output file every time it is used in the document.
I actually wrote a LaTeX package storebox
which provides "storeboxes" which work like saveboxes but only store the content once in the PDF. However, this only works with pdflatex
in PDF mode, not with DVI, because it uses a feature of the PDF format.
As Martin said, standard LaTeX save-boxes \sbox
, \savebox
and lrbox
environment repeat the DVI, PS and PDF code on every \usebox
.
Package xsavebox
provides \xsbox
, \xsavebox
, xlrbox
and \xusebox
, which, apart from box naming, are used in the same way as the standard LaTeX commands, but insert the box content only once as a PDF XObject. Repeated usage of \xusebox
inserts references to the object. This works for all common workflows, including dvips
+ps2pdf
.
E.g. \xsbox{My Box 1}{Hello world!}
... \xusebox{My Box 1}
or \xsbox{MyBoxOne}{Hello world!}
... \theMyBoxOne
Of course, this does not make sense for boxes with little content as in the example because some overhead is introduced. But it may reduce the PDF file size for repeated TikZ graphics, used e.g. as watermarks, and alike.