.cls file next to main.tex that declares itself with \NeedsTeXFormat{LaTeX2e} and \ProvidesClass, builds on a base class with \LoadClass, and defines your layout overrides.
If you only need to pick an existing standard class (article, report, book, or beamer) rather than write a .cls file, see the Document classes reference. If you want reusable macros or styling on top of a standard class without changing its document structure, write a .sty package instead—see Create a LaTeX package.
Step 1: Write a minimal .cls file and load it from main.tex
A custom class usually extends article, report, or book instead of defining every sectioning and float command from scratch. Put four elements in the .cls file:
\NeedsTeXFormat{LaTeX2e}declares the required LaTeX format.\ProvidesClass{name}[YYYY/MM/DD description]identifies the class;nameshould match the filename without.cls, and the optional date lets LaTeX warn about outdated versions.\LoadClass[options]{base}loads the base class inside your.clsfile.\RequirePackageloads supporting packages (use\RequirePackagerather than\usepackageinside class and package files), followed by your custom commands and\endinput.
.cls files, @ is already a letter, so internal commands such as \@title, \@author, and \@date work directly without \makeatletter.
techreport.cls
main.tex
Ready to use this syntax? Continue in the browser editor when you want to adapt the example in a real project.Open LaTeX Cloud Studio
Step 2: Declare class options and forward unknown options
A bare\LoadClass[11pt,a4paper]{article} ignores options passed by the user to \documentclass[...]{techreport} (and calling \ProcessOptions\relax without \DeclareOption* triggers an Unused global option(s) warning). To support both custom class options and standard base-class options:
- Define custom options with
\DeclareOption{name}{code}. - Catch all other options with
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}. - Run
\ProcessOptions\relaxbefore\LoadClassso forwarded options are queued before the base class loads.
article, you can replace \DeclareOption*, \ProcessOptions\relax, and \LoadClass with \LoadClassWithOptions{article}.
groupreport.cls
main.tex
compact is handled inside groupreport.cls to tighten the geometry margins, while 12pt is forwarded to article through \PassOptionsToClass.
Step 3: Save the .cls file where TeX finds it
TeX searches the directory of the main .tex file before system texmf trees. Keeping techreport.cls or groupreport.cls in the same folder as main.tex ensures every collaborator and build environment uses the exact same class without installing files locally.
In LaTeX Cloud Studio, projects hold multiple files (including .cls and .sty files), and the compiler places all project files into the build directory beside main.tex on TeX Live 2026 (full distribution), so standard base classes and supporting packages such as geometry, titlesec, and fancyhdr are already available.
Common mistakes
- Mismatched class name and filename: Saving
\ProvidesClass{myreport}intechreport.clsemits aYou have requested document class ..., but the document class provides ...warning. - Calling
\LoadClassbefore\ProcessOptions\relax: Options queued with\PassOptionsToClassare not applied if\LoadClasshas already executed. - Using
\LoadClassinside a.styfile: LaTeX raisesTwo \LoadClass commandswhen the package is loaded after\documentclass(or\LoadClass in package fileif loaded beforehand via\RequirePackage); use\LoadClassinside.clsfiles, not packages. - Putting document content inside the
.clsfile: Keep boilerplates and sample sections in a.textemplate file; reserve the.clsfile for layout rules and macros.
Try it in the editor
Start from the Basic Article template in LaTeX Cloud Studio, replacemain.tex with the complete example, and add techreport.cls or groupreport.cls alongside it in the project.
