# Own cls to fmt conversion

Is it possible to convert my own .cls to .fmt conversion using PdfTeX?

NOTE: Our peoples are frequently change/updations in class file (source .cls file). So that I would like to convert non-editable class format.

-
look at the mylatexformat package which helps in compiling a custom format based on a document preamble loading specific classes and packages. –  David Carlisle Sep 2 '13 at 12:51
Did this help? The question is still unanswered. –  Johannes_B Feb 25 at 18:20
Are there any news here? <- for later google search –  Johannes_B Apr 7 at 15:04
Still i have not found the solution. Do you have any ideas? –  Balaji Apr 8 at 8:56
If the class is frequently changed, then the class should be improved by adding features and easier configurations, fixing bugs, improving documentation, ... –  Heiko Oberdiek Jul 2 at 12:42

Procedure for a format, which has a class preloaded. The class is named theclass in the following.

## The class file

Because the class is already loaded in the format, global/class options cannot be specified any longer. Configuration can be implemented by a \theclasssetup command as done by many packages and some classes, e.g. \sisetup of package siunitx or \hypersetup for some of the options of package hyperref.

A dummy class file theclass.cls for testing:

% File: theclass.cls
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{theclass}[2015/07/02 v1.0 Class for something]

% Implementation of the class

\endinput


## theclass.ini file for the format generation

The new format file consists of LaTeX and the class. The file theclass.ini contain the commands for the format. LaTeX is not loaded, because the available LaTeX formats can be reused. But the class needs to be loaded and \documentclass redefined to allow normal LaTeX documents that can be processed with the format with or without the class preloaded.

% File: theclass.ini
%
% Check for e-TeX
\expandafter\ifx\csname eTeXversion\endcsname\relax
\begingroup
\catcode\{=1
\catcode\}=2
\catcode\^=7
\newlinechar=10 %
\def\space{ }
\def\MessageBreak{^^J\space\space}
\errmessage{%
The eTeX extension is missing.\MessageBreak
It can be enabled by option -etex\MessageBreak
or starting the first filename with a star *'.\MessageBreak
The format generation is aborted%
}
\endgroup
\csname fi\endcsname % end \ifx
\csname @@end\endcsname % for the case a LaTeX format is already loaded
\end % end job
\fi

\NeedsTeXFormat{LaTeX2e}
\documentclass{theclass}\relax

% Now we have to redefine \documentclass to get valid user documents.
\makeatletter
\renewcommand*{\documentclass}[2][]{%
\def\reserved@a{#2}%
\ifx\reserved@a\theclass@name
\def\reserved@a{#1}%
\ifx\reserved@a\@empty
\else
\ClassWarningNoLine{theclass}{%
and does not support global options.\MessageBreak
The following options are ignored:\MessageBreak
\@spaces[#1]%
}%
\fi
\expandafter\theclass@datecheck
\else
\ClassError{theclass}{%
This format has already loaded the class theclass'\MessageBreak
and cannot be used with other classes.\MessageBreak
LaTeX run is aborted%
}\@ehd
\expandafter\@@end % abort job.
\fi
}
\newcommand*{\theclass@name}{theclass}
\newcommand*{\theclass@datecheck}[1][]{%
\@ifclasslater{theclass}{#1}{%
}{%
\@latex@warning@no@line{%
You have requested,\on@line,
version\MessageBreak
#1' of class\space\theclass@name,\MessageBreak
but only version\MessageBreak
\csname ver@\theclass@name.cls\endcsname'\MessageBreak
is available in this format%
}%
}%
}

% Format identification
\begingroup
\edef\x{%
\noexpand\typeout{%
Class \theclass@name\space \@nameuse{ver@\theclass@name.cls}.%
}%
\noexpand\typeout{%
Format created at \the\year/\two@digits\month/\two@digits\day
\space by class author.%
}%
}%
\expandafter\endgroup
\expandafter\everyjob\expandafter{\the\expandafter\everyjob\x}
\makeatother

% Generate format
\dump
\endinput


## Format generation

This is shown for TeX Live (2015) for pdflatex. Since the format for pdflatex is already available, it is reused by &pdflatex. The special character & usually needs to be escaped on a command line, e.g. \&pdflatex (bash) or "&pdflatex". Option --ini enables iniTeX mode. In this case option --etex is not given, because it is inherited from the imported format file of pdflatex.

pdflatex --ini "&pdflatex" theclass.ini


This generates the format file theclass.fmt. (In the past the extension was .efmt with eTeX extensions.)

## Usage

Test file:

\documentclass{theclass}
% or \documentclass{theclass}[2015/07/02]
\begin{document}
Hello Word!
\end{document}


The new format theclass.fmt can be loaded with & (should be supported by all TeX compilers):

pdflatex "&theclass" test


Or option --fmt (supported by TeX Live):

pdflatex --fmt=theclass test


Also pdftex could be used, but it uses the wrong search paths for plain format instead of LaTeX. This can be fixed by overwriting the program name:

pdftex --progname=pdflatex --fmt=theclass test


## Installation

The format file can be found in the current directory or installed in a texmf (TDS) tree. The format file theclass.fmt for engine pdfTeX is installed in:

TDS:web2c/pdftex/theclass.fmt


The root can be the home tree (TEXMFHOME) or a local tree (TEXMFLOCAL). The latter (or MiKTeX) requires the update of the file name database. The programs texhash or mktexlsr` can be used in TeX Live for this purpose.

-
I hope you get many upvotes for your effort. –  Johannes_B Jul 2 at 19:28
As an answer to the question, @Johannes_B is surely right. But I worry that the question asked is not the right one. In that sense.... That is, I entirely agreed with your comment on the question but that is not, as it were, reflected at all in the answer.... –  cfr Jul 2 at 20:14