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.
Procedure for a format, which has a class preloaded. The class is named theclass
in the following.
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
\LoadClass{article}
\endinput
theclass.ini
file for the format generationThe 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
% Load class
\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}{%
This format has already loaded the class\MessageBreak
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@\[email protected]\endcsname'\MessageBreak
is available in this format%
}%
}%
}
% Format identification
\begingroup
\edef\x{%
\noexpand\typeout{%
Class \theclass@name\space \@nameuse{ver@\[email protected]}.%
}%
\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
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.)
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
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.
mylatexformat
package which helps in compiling a custom format based on a document preamble loading specific classes and packages.