A normal TeX file looks something like this (MWE):


In this case, one must have two files in order for the document to be compiled : the document itself and the documentclass file (here, article.cls).

Is it possible to include (in some way or another) the information of the documentclass (article.cls) file inside the .tex file in order to have only one file compilable by itself ?

So far, I have tried copy-pasting the contents of the documentclass in lieu of \documentclass{article}, but I got the error

! LaTeX Error: Command \@ already defined.
    Or name \end... illegal, see p.192 of the manual.

when compiling.

Someone else has asked a somewhat similar question here but it consisted of not having any documentclass information at all, instead of having it stored inside the same file as the TeX document.

Thanks in advance if anyone has a solution or a workaround.

  • 3
    that error means you forgot \makeatletter but the simplest way is to put the class file as: \begin{filecontents}{temp.cls}...\end{filecontents} \documentclass{temp} Aug 1, 2022 at 21:41
  • 2
    ... oh which is exactly what I suggested in the linked answer 10 years ago. At least I am consistent Aug 1, 2022 at 21:45
  • 1
    Indeed, using \begin{filecontents}… works. Thank you.
    – beaniehat
    Aug 1, 2022 at 22:04