Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
1  
For one, inability to use \usepackage. –  cyberSingularity Jan 21 '13 at 14:49
    
I thought \documentclass was mandatory :P –  Willian Paixao Jan 21 '13 at 15:00
    
It might not be good LaTeX style, but Daniel's code actually works ;) –  Stephan Lukasczyk Jan 21 '13 at 15:01
    
Me too, which is why I asked. –  StrongBad Jan 21 '13 at 15:13
    
texdoc source2e and search for \normalsize is used to produce an error, so if you define it you can run a classless document. –  Yiannis Lazarides Jan 21 '13 at 15:15
show 1 more comment

3 Answers

up vote 13 down vote accepted

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.

share|improve this answer
    
I tried exactly this before asking. The problem I ran into was conflicts with the article class and my class defining the same macros. I would have needed to change many \newcommand's to \renewcommand's. I therefore think the minimal class is probably better in this situation. –  StrongBad Jan 21 '13 at 15:23
3  
No, I promise you, it isn't. minimal is the smallest class I could make that would let you test the new (at the time) package loading mechanism but if you use it for actual documents things will go wrong. Math isn't set up, font size commands are not set up, figures/tables are not set up, more or less anything that any package that you load expects has not been set up. –  David Carlisle Jan 21 '13 at 16:25
    
see edited answer. –  David Carlisle Jan 21 '13 at 16:57
    
If you look at mininmal.cls... Should be minimal. –  Faheem Mitha Jan 21 '13 at 17:33
    
@FaheemMitha thanks Werner fixed it. –  David Carlisle Jan 21 '13 at 18:41
add comment

I need to create a really simple document template for other people to fill in and compile.

I am not sure what you after, as to why the user needs to compile. The minimal check that LaTeX does to see if a class is defined is to produce an error if \normalsize has not been redefined see source2e, ltfntcmd.dtx.

If you really want to go minimalistic go pure TeX.

 J. Smith, myemail@goom.com
 \bye
share|improve this answer
add comment

As I've tested some quite basic environments that came in my mind, there is pretty much no functionality at all. All environments and commands that are not included in plain TeX won't work. So you have no possibilities to produce tables or lists with LaTeX. If this works for your special purpose, it's fine.

As you've mentioned, there is not even an \usepackage available, one could not do very much. It's just up to you if the functionallity you get by this very reduced code is working.

Maybe you try some pretty small document classes like minimal or standalone. With your code it's just one extra line, to load it, but you earn much more functionallity

share|improve this answer
    
I thought macros like \renewcommand were part of LaTeX and not plain TeX? –  StrongBad Jan 21 '13 at 15:13
    
Daniel, you are right. But some plain TeX stuff works, if you try e.g. $\alpha$ ;-) –  Stephan Lukasczyk Jan 21 '13 at 15:18
2  
@StephanLukasczyk That isn't plain TeX stuff, it is LaTeX stuff that has similar name/definition to the definition in plain. \alpha is defined in LaTeX by \DeclareMathSymbol{\alpha}{\mathord}{letters}{"0B} and in plain by \mathchardef\alpha="010B Actually with the default latex font setup these come to the same thing, but the actual sources of plain tex are not used at all in latex. –  David Carlisle Jan 21 '13 at 16:32
    
Thank you @DavidCarlisle, I didn't realize that yet, again I've learned something. –  Stephan Lukasczyk Jan 21 '13 at 22:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.