# Recreate the conditions of the document preamble while loading a file in the document body

While in the document body I like to temporary switch back to the mode active in the LaTeX preamble, i.e. spaces between macros should be ignored. I don't mind whether I get the ! LaTeX Error: Missing \begin{document} or not. I'm aware that this is something which is normally not done. The switch will be done by a package for loading size files.

Details: This is a follow-up question for my question Switching to different font size(s) locally. I like to load a file which is normally only loaded in the preamble inside a local scope in the document body. The problem is that it contains some spaces between macros which are ignored in the preamble but not the document. I can't set the catcode of the space to 'ignore', because there might be spaces inside macros which should stay spaces. Ignoring all line endings by setting \endlinechar=-1 helps, but doesn't catch all spaces. I also tried to wrap the \input with \ignorespaces .. \unskip, but this removes only the first and last space, but keeps other spaces.

I currently don't understand how the preamble mode is implemented. Apparently the typesetting mechanism of TeX is trip-wired. It would be great if answers could include some explanation how this is actually done.

• In the first line you mean ... While in the main body? – Yiannis Lazarides Dec 1 '11 at 13:14
• @YiannisLazarides: Sorry, should be 'body' not 'preamble'. – Martin Scharrer Dec 1 '11 at 15:05
• @MartinScharrer I'm not really sure what you mean here. The preamble is from a TeX point of view 'before' the first paragraph. You can try adding some definitions, etc. in between document body paragraphs and get the same effect. The error in the preamble is raised by setting \everypar to give an error. (\nullfont is also selected.) – Joseph Wright Dec 1 '11 at 15:19
• I guess you want to skip spaces within a paragraph rather than at the ends? – Joseph Wright Dec 1 '11 at 15:20
• @JosephWright: As I figured out myself in the meantime \nullfont is what I was looking for. I just have to make sure that the \normalsize inside the particular files does not revert it. I might post a self-answer in a while. – Martin Scharrer Dec 1 '11 at 15:35

There's really no preamble mode. When TeX starts, it's in vertical mode, where spaces have no effect; of course this doesn't mean that spaces are ignored: space "commands" that reach TeX's stomach while in vertical mode have no effect; spaces which are part of a macro definition will have effect or not according to the mode TeX is when the macro is expanded.

LaTeX starts by setting \everypar to issue an error and sets the current font to be \nullfont, but this hasn't any effect apart from avoiding to typeset text (which usually happens anyway, if text sneaks in in the preamble).

• Thanks, that saved me a self-answer. I got it working with \nullfont. I should have thought about it. TikZ also uses \nullfont to avoid any text inside tikzpictures to be typeset, except in nodes of course. – Martin Scharrer Dec 1 '11 at 17:00

I am not sure if this is what you are looking for, but here is my take:

Firstly, it is quite possible to use any preamble command in the body of the document using,

\let\@preamblecmds\relax


Spaces can be removed by using \zap@space. This is a delimited macro, so you will probably need to redefine it to make it suitable for author commands.

\documentclass{book}
\makeatletter
\let\@preamblecmds\relax
\begin{document}
\zap@space
\usepackage{lipsum}
\lipsum[1]  \@empty
\end{document}

• The commands in this case are not \@onlypreamble, so \@preamblecmds is not an issue, but it is good to mentioned it. I woudln't have thought about it. However, I'm not sure about \zap@space, does it really go into the file? – Martin Scharrer Dec 1 '11 at 15:11
• @Martin I am not sure, I thought maybe is a good strategy to place your code into a package and then rather use it this way, perhaps with some cosmetic changes. You can give it a try. – Yiannis Lazarides Dec 1 '11 at 15:15
• \zap@space doesn't expand anything, so \zap@space\usepackage{lipsum} \@empty will simply give \usepackage{lipsum}. – egreg Dec 1 '11 at 16:43
• @egreg I was anxiously waiting for your answer:) – Yiannis Lazarides Dec 1 '11 at 16:47
• Let me find a place on the train! :) – egreg Dec 1 '11 at 16:50