It helps to have a real example rather than fake code as in the question:
myfile.tex
\documentclass{article}
\usepackage{tikz}
\usepackage{siunitx}
\usepackage{pstricks}
\makeatletter
% some macros
\makeatletter
\begin{document}
hello
\end{document}
Then the comments in mylatex.ltx should be clear enough except that initex is accessed as pdflatex --ini these days usually
This loads all the packages and makes a format
$ pdflatex --ini \&pdflatex mylatex.ltx myfile
This typesets the document, without needing to load the packages.
pdflatex \&mylatex myfile
The log shows:
This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015) (preloaded format=mylatex 2015.9.23) 23 SEP 2015 12:56
entering extended mode
restricted \write18 enabled.
%&-line parsing enabled.
**&mylatex myfile
(./myfile.tex
LaTeX2e <2015/10/01>
Babel <3.9m> and hyphenation patterns for 79 languages loaded.
CUSTOMISED FORMAT. Preloaded files:
.
article.cls 2014/09/29 v1.4h Standard LaTeX document class
size10.clo 2014/09/29 v1.4h Standard LaTeX file (size option)
tikz.sty 2015/08/07 v3.0.1a (rcs-revision 1.151)
pgf.sty 2015/08/07 v3.0.1a (rcs-revision 1.15)
pgfrcs.sty 2015/08/07 v3.0.1a (rcs-revision 1.31)
everyshi.sty 2001/05/15 v3.00 EveryShipout Package (MS)
pgfrcs.code.tex
pgfcore.sty 2010/04/11 v3.0.1a (rcs-revision 1.7)
graphicx.sty 2014/10/28 v1.0g Enhanced LaTeX Graphics (DPC,SPQR)
keyval.sty 2014/10/28 v1.15 key=value parser (DPC)
graphics.sty 2014/10/28 v1.0p Standard LaTeX Graphics (DPC,SPQR)
trig.sty 1999/03/16 v1.09 sin cos tan (DPC)
graphics.cfg 2010/04/23 v1.9 graphics configuration of TeX Live
pdftex.def 2011/05/27 v0.06d Graphics/color for pdfTeX
infwarerr.sty 2010/04/08 v1.3 Providing info/warning/error messages (HO)
ltxcmds.sty 2011/11/09 v1.22 LaTeX kernel commands for general use (HO)
pgfsys.sty 2014/07/09 v3.0.1a (rcs-revision 1.48)
pgfsys.code.tex
pgfsyssoftpath.code.tex 2013/09/09 (rcs-revision 1.9)
pgfsysprotocol.code.tex 2006/10/16 (rcs-revision 1.4)
xcolor.sty 2007/01/21 v2.11 LaTeX color extensions (UK)
color.cfg 2007/01/18 v1.5 color configuration of teTeX/TeXLive
pgfcore.code.tex
pgfcomp-version-0-65.sty 2007/07/03 v3.0.1a (rcs-revision 1.7)
pgfcomp-version-1-18.sty 2007/07/23 v3.0.1a (rcs-revision 1.1)
pgffor.sty 2013/12/13 v3.0.1a (rcs-revision 1.25)
pgfkeys.sty
pgfkeys.code.tex
pgfmath.sty
pgfmath.code.tex
pgffor.code.tex
tikz.code.tex
siunitx.sty 2015/09/14 v2.6l A comprehensive (SI) units package
expl3.sty 2015/09/11 v6002 L3 programming layer (loader)
expl3-code.tex 2015/09/11 v6002 L3 programming layer
l3unicode-data.def 2015/07/20 v5676 L3 Unicode data
l3pdfmode.def 2015/09/10 v5983 L3 Experimental driver: PDF mode
xparse.sty 2015/09/11 v6001 L3 Experimental document command parser
amstext.sty 2000/06/29 v2.01
amsgen.sty 1999/11/30 v2.0
array.sty 2014/10/28 v2.4c Tabular extension package (FMi)
l3keys2e.sty 2015/09/11 v6001 LaTeX2e option processing using LaTeX3 keys
translator.sty 2010/06/12 ver 1.10
translator-language-mappings.tex
pstricks.sty 2013/12/12 v0.60 LaTeX wrapper for `PSTricks' (RN,HV)
ifpdf.sty 2011/01/30 v2.3 Provides the ifpdf switch (HO)
pstricks.tex 2015/09/11 v2.63 `PSTricks' (tvz,hv)
pst-xkey.tex 2005/11/25 v1.6 PSTricks specialization of xkeyval (HA)
xkeyval.sty 2014/12/03 v2.7a package option processing (HA)
xkeyval.tex 2014/12/03 v2.7a key=value parser (HA)
pst-fp.tex 2015/09/11 v2.63 `PST-fp' (hv)
.
(./myfile.aux)
mylatex.ltxback in 1988 or so when on a pc it could take quarter of an hour just to load the preamble, so not doing that was a big win. – David Carlisle Sep 23 '15 at 12:08myfile2.tex? – Colas Sep 23 '15 at 12:51pdflatex \&mylatex secondfileand it will use the saved preamble not the one in the document (so make sure they are the same:-) You need to be doing this thousands of times to make it worth doing at all, If it saves a fraction of a second each time, you need to do it a lot before you save the time asking about it (I have never used it, but it was useful for some friends on slower machines last century) – David Carlisle Sep 23 '15 at 12:59mylatex.ltxbe on the disk? – Colas Sep 23 '15 at 13:13\pdfmapfilegave me trouble when running it throughmylatexformat. Figured it was worth mentioning. – 1010011010 Sep 23 '15 at 13:26kpsewhich mylatex.ltxand it will tell you, in texlive2015 it is$ kpsewhich mylatex.ltx /usr/local/texlive/2015/texmf-dist/tex/latex/carlisle/mylatex.ltx– David Carlisle Sep 23 '15 at 13:26mylatexalso produced two files in the directory where I executed it:mylatex.fmt(14Mb) and the log. – Colas Sep 23 '15 at 13:52.fmtis the whole point: that is the new format with the packages built in. – David Carlisle Sep 23 '15 at 13:55my latexremember the path of this.fmt?) – Colas Sep 23 '15 at 13:59&when you use it, or put it anywhere in your TEXFORMATS path and and just use&mylatexif you need to save different ones, you can rename it. – David Carlisle Sep 23 '15 at 14:27pdflatex --ini \&pdflatex mylatex.ltx myfile, less compact and more explicit. I need to have a better understand of the processes which are launched by this command (like what is an option, what is a program, is it one command or two, etc.). Thanks! PS: the error I get is /usr/texbin/pdflatex: unrecognized option `--ini &pdflatex mylatexformat.ltx' – Colas Sep 23 '15 at 18:27¬\&or you may need quotes or whatever. the actual command passed to tex has to have&before the format name, the backslash is to hide the&from my commandline (bash shell). Alternatively you can just usepdftexand specify the format as a magic%&mylatexcomment as the first line of each document file. – David Carlisle Sep 23 '15 at 18:52pdflatex \&mylatex /path/to/mylatex.fmt file_1.texdoes not work. Are sure it is the right syntax (then I might have done another error)? – Colas Sep 23 '15 at 19:14&is the format (without.fmt) you havemylatextwice and.fmtat the end, both of which are wrong. – David Carlisle Sep 23 '15 at 19:19pdflatex --ini \&pdflatex mylatex.ltx myfile, where should I put the quote? I am still struggling. – Colas Sep 23 '15 at 22:08[.] \&pdflatex [.]intentional and necessary? Also, ismyfilea variable for<.texFileName>– kando Sep 20 '20 at 01:46