# [texhax] fmt to cls conversion

Fri Jun 22 08:11:19 CEST 2012

On Thu, Jun 21, 2012 at 10:53:16PM +0100, Philip TAYLOR wrote:

> Reinhard Kotucha wrote:
>
> >I fear that it's impossible.  TeX evaluates (expands) macros before
> >dumping a format file.  With other words, if the source file contains
> >the expression
> >
> >   3 + 4
> >
> >, the format file contains only the number 7 and there is no way to
> >find out whether it was 3 + 4 or 5 + 2 in the source code.
> >
> >The purpose of a format file is to avoid that all calculations have to
> >be done at runtime.  Hence it only contains the results of such
> >calculations and macro expansions.
>
> Isn't that something of an over-simplification, Reinhard ?
> Leaving aside the highly dubious assertion that "if the source
> file contains the expression 3 + 4, the format file contains
> only the number 7" (3 + 4 is /highly/ unlikely to involve macro
> expansion),

Of course, a source file can even contain calculations, e.g.

\setlength{\textwidth}{210mm}

All you have after format generation is the result.
The information, how the result was calculated, is lost.

> consider something as simple as the following :
>
> 	\def \foo {\bar \baz}
> 	\dump
>
> In the format file, the macro \foo will be defined but /not/
> expanded.  If the user at run-time then interrogates \foo :
>
> 	\message {\meaning \foo}
>
> he will be provided with the original definition, which may well
> help him enormously with his task of re-creating the format source.

The following example contains three different definitions of \foo
with the same output of \meaning:

\def\fooshow{%
\immediate\write16{[\meaning\foo]}%
}
\def\foo{\bar \baz }
\fooshow
\edef\foo{\string\bar\space\string\baz\space}
\fooshow
\edef\foo{\expandafter\noexpand\csname bar \string\baz\endcsname}
\fooshow
\csname @@end\endcsname\end

That means, the right catcodes has to be guessed and the
derived definition needs to be verified by comparing (\ifx)
with the definition in the format.

Also the format could have disabled \meaning to make
reverse engineering more difficult.

Yours sincerely
Heiko Oberdiek