[Tex/LaTex] LaTeX document without \documentclass

document-classesdocumentclass-writing

I need to create a really simple document template for other people to fill in and compile (e.g., they need to provide a name and email address). I could distribute it as a .cls file and a template .tex file, but I think it might be easier to just distribute it as a single file.

It appears that one can compile a document without a \documentclass without any warnings. For example, despite not having a \documentclass line, the following is a complete MWE:

\renewcommand\normalsize{\fontsize{10pt}{12pt}\selectfont}
\begin{document}
Hello world
\end{document}

Where the entire "class" is \renewcommand\normalsize{\fontsize{10pt}{12pt}\selectfont}. What are the drawbacks of defining the entire "class" within the .tex file and not using a \documentclass line?

EDIT

To add a little more about what I am doing. I created a custom class that was not based on any other class. I then took David Carlisle idea

and changed

\documentclass{myclass}

to

\documentclass{article}
\makeatletter
%  your definitions
\makeatother

but this caused conflicts of things that were defined in both myclass and the article class. It probably would have been better to use the minimal class, but I realized that I didn't need the \documentclass{article} before I thought about the minimal class.

Best Answer

If you look at minimal.cls you will see it does a bit more than just set the normal font size:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{minimal}[2001/05/25 Standard LaTeX minimal class]

\renewcommand\normalsize{\fontsize{10pt}{12pt}\selectfont}

\setlength{\textwidth}{6.5in}
\setlength{\textheight}{8in}

\pagenumbering{arabic}  % but no page numbers are printed because:
\pagestyle{empty}       % this is actually already in the kernel

In particular things are likely to go very wrong if you don't set \textheight and \textwidth.

However there is no advantage to not using a real class such as article and many disadvantages.

If you just want to distribute a single template file and no class file use a format like

\documentclass{article}


\makeatletter

 %  your definitions

\makeatother

\begin{document}

\end{document}

Looking at the edited question, if your custom code does set up everything then you could just stick it at the top as you said, the problems with minimal then don't apply. Perhaps better though would be to use a form

\begin{filecontents}{myclass.cls}
% your definitions
\end{filecontents}
\documentclass{myclass}
\begin{document}
...
\end{document}

That way the file can easily be switched between assuming myclass is already installed and including it inline. Such ad-hoc distribution of local class and package files was one of the main motivations for adding filecontents to LaTeX2e.

Related Question