Stage 1 · Foundations 6 / 48 ≈ 16 min read

How to Use a LaTeX Template Without Breaking It

A LaTeX template is not a document with styles applied; it is code that runs before yours, and it is why editing one feels risky. Here is what the class and package files actually do, the order LaTeX searches for them, which lines of a shipped file you are allowed to touch, and the five breakages that account for almost every stuck submission.

    What a template is made of

    A LaTeX template is a set of files that reprogrammes the formatter before your text is read. The .cls file is the document class: it decides page geometry, fonts, heading sizes, and which commands exist at all. A .sty file is a package, loaded inside your document with \usepackage, and it adds or overrides behaviour. A .bst file does the same job for the bibliography, and it is a separate language entirely (BibTeX's own), which is why fixing a reference style never involves TeX commands.

    The distinction between class and package is the most useful thing to internalise, because the two failure modes look similar and are fixed differently. \documentclass{llncs} says "there is no document until this program runs"; if that file is absent, LaTeX stops immediately with ! LaTeX Error: File `llncs.cls' not found. A missing .sty produces the same shape of message one line later. The remedy in both cases is to make the file findable — not to edit your prose.

    "Findable" has a precise meaning, and the lookup order explains the most common template miracle: putting the file next to the .tex made it work. LaTeX searches the working directory first, then any extra paths in TEXINPUTS, then your personal tree (TEXMFHOME), then the distribution tree. That is why a class file emailed to you by a supervisor works the moment you drop it in the project folder, and why a .cls installed deep in the distribution can be shadowed by an older copy sitting beside your source.

    kpsewhich is the instrument that turns this from folklore into a check: run kpsewhich myclass.cls in the project directory and it prints exactly which file LaTeX would use, or nothing at all. Use it before you suspect a bug in the template.

    Which copy of a class or style file LaTeX actually loads, and where to install a file you were sent the request \documentclass [conference]{venue} search order, first hit wins 1 · the folder you are compiling in ./venue.cls ← v1.0, sent by email 2 · TEXINPUTS / TEXINPUTS.$format set by an editor, a project or CI 3 · TEXMFHOME — your own tree safe place for a template you reuse 4 · TEXMFLOCAL, then TEXMFDIST texlive/2025/texmf-dist ← v2.3 the trap this creates Two copies on one machine. LaTeX loads the one nearest your file, which is the older one, and never mentions it. kpsewhich venue.cls → ./venue.cls ← the answer is the diagnosis delete, rename or version the shadowing copy, then prove what the run used with the file list from \listfiles. "Works on my machine, wrong layout on theirs" = this box. Same rule for .sty, .def, .cnf and .bst files. where to install a template you keep using kpsewhich -var-value TEXMFHOME # C:\Users\you\texmf or ~/texmf <TEXMFHOME>/tex/latex/venue/venue.cls <TEXMFHOME>/tex/latex/venue/venue.sty <TEXMFHOME>/bibtex/bst/venue/splncs04.bst mirror the distribution's own layout inside tex/type/package/ — that is what makes the lookup succeed without a TEXINPUTS edit then: mktexlsr MiKTeX: refresh the file name database. skipping this is the #1 follow-up
    Files are searched in a fixed order, so a copy in the project folder always wins over the version installed with the distribution.

    Read the template before you edit it

    Templates arrive as a zip: a .cls, a couple of .sty files, one or two .bst files, a sample document usually called template.tex or sample.tex, and a readme that people never open. The first action is to compile the sample exactly as shipped, with no changes, and confirm you get the PDF the publisher shows on their page. If that fails, nothing else you do matters — you have a missing-file or wrong-engine problem.

    Then read three lines. Line one, \documentclass[...]{...}: the option list is a contract. Journal classes read options like conference, final, draftcls, twocolumn, 10pt, and changing them changes the page count, sometimes the acceptance of your submission. Line two is the package list between \documentclass and \begin{document}: this is the set of things the template assumes, and it is a clue about which commands are legal in the body.

    Third, find the commands the class requires. Some are inherited from article — \title, \author, \maketitle, \begin{abstract}. Many are invented by the template: \keywords{...}, \institute{...}, \classification, \ead{a@b.edu}, \setcopyright{}. A required-but-empty one is what makes a submission desk reject a PDF with a blank first page; an invented one used with the wrong class is what makes ! Undefined control sequence. appear on line 4 of a file you did not write.

    The sample file usually marks the boundary with a comment such as % %% Put your text here, or by wrapping the demonstration material in \iffalse ... \fi so that it is read as skipped text. Find that boundary, and treat it as a fence.

    The method that keeps you out of trouble

    Work in a fixed order and every template problem becomes a small problem. (1) Unzip into its own folder, no renamed files. (2) Compile the sample untouched. (3) Replace the sample's body text with your own, section by section, recompiling after each section, so that a failure has a fifteen-second suspect window. (4) Move your own packages into the one place the template allows, immediately after its own \usepackage block and before \begin{document}. (5) Only at the end, deal with the bibliography.

    Two rules prevent most damage. Do not delete a line you cannot explain. A mysterious \renewcommand{\footnotemark} or \setlength{\textfloatsep}{9pt} is load-bearing in a way you will discover at 2 a.m. Do not add vertical spacing. No \vspace, no empty \line, no \\ between paragraphs: the page count in a two-column class is a limit somebody checks, and manual nudges propagate into the next three pages.

    If you need behaviour the template does not offer, add it as a new macro rather than editing the class. Put \newcommand{\dn}[1]{\textcolor{red}{#1}} in your preamble instead of hunting through the .cls for a colour definition to change. When you later have to prove your source is the unmodified template — and some venues ask — a diff that touches only your own file is an easy conversation.

    Keep the pieces the template needs as separate files rather than pasting them into the main document: one \input{preamble-local} if the class permits it, your figures in fig/ with \graphicspath{{fig/}}, your references.bib beside the class. A template plus three of your own files is a project; a template with 400 lines pasted into the sample is a fossil record.

    Which parts of a shipped LaTeX template you may edit and which you must leave alone a shipped main file, band by band \PassOptionsToPackage{dvipsnames}{xcolor} yours — the only \documentclass[conference,10pt]{venue} theirs — options too \usepackage{amsmath} ... (their package list) theirs — read it \usepackage{your-needed-package} % after theirs yours — before \begin \title{}\ \author{}\ \keywords{}\ \begin{abstract} fill in, do not restyle \section{Introduction} As shown in Figure~\ref{fig:a}, ... \begin{figure*}[t] ... \caption{} \label{} \end{figure*} \begin{equation} ... \label{eq:k} \end{equation} ... your whole text, figures, tables, maths ... yours two-column page? widen a float with the starred form, never shrink text \bibliographystyle{venue}\ \bibliography{refs} style is theirs venue.cls venue.sty splncs04.bst never edit these the three verdicts write here freely your prose, your macros, your own packages added after theirs your figures in a tracked folder fill in only the title block, the abstract, the keywords — structure fixed by the class, contents entirely yours do not touch the class line, its options, its package list, the .cls / .sty / .bst files, and the page geometry Need something outside the green band? define a new macro in your preamble — or ask the editor.
    The traffic light of a shipped file: the preamble and the class own the layout, you own the body and your own macros.
    % main.tex —— the shape nearly every journal template forces on you.
    % Rule of thumb: the preamble belongs to the template, the body belongs to you.
    \documentclass[twocolumn,10pt,a4paper]{article}   % <- the venue's line: do not edit
    
    \usepackage[T1]{fontenc}
    \usepackage{amsmath,amssymb}
    \usepackage{graphicx}
    \usepackage{booktabs}
    \usepackage[numbers,sort&compress]{natbib}       % many classes want this exact form
    \usepackage{caption}
    \captionsetup{font=small,labelfont=bf}           % the venue's caption style
    \usepackage[colorlinks=true,citecolor=blue]{hyperref}  % load it last
    
    \begin{document}
    
    \title{A Two-Column Example That Mimics a Conference Class}
    \author{A. Student\thanks{Department of Something, University of Where.
            Email: \texttt{a.student@example.edu}}}
    \date{\today}
    \maketitle
    
    \begin{abstract}
    \noindent
    The abstract is a single paragraph with no indentation, no displayed
    equations and no citations in most templates. Fill it in; do not restyle it.
    \end{abstract}
    
    % ============================================================
    %  EDIT BELOW THIS LINE -- everything above belongs to the template.
    % ============================================================
    \section{Introduction}
    Write here. Keep the sectioning commands the class provides, and add
    no \verb|\vspace| to push things around: page count is the reviewer's
    business, not yours.
    
    A displayed formula in one column of a two-column page has about
    0.47 of the text width to live in, so this one needs splitting:
    \[
      \underbrace{\sum_{i=1}^{n} \left(x_i - \bar{x}\right)^{2}}_{\text{one line}}
      \;=\;
      \underbrace{\sum_{i=1}^{n} x_i^{2} - n\bar{x}^{2}}_{\text{the other}}
    \]
    
    \section{Conclusion}
    Cite with \verb|\cite| and never type a reference by hand:
    an unnumbered bracket is the fastest way to look sloppy~\cite{knuth84}.
    
    % ============================================================
    %  EDIT ABOVE THIS LINE.
    % ============================================================
    \begin{thebibliography}{9}
      \bibitem{knuth84} D.~E. Knuth, \emph{Computers and Typesetting}, 1984.
    \end{thebibliography}
    
    \bibliographystyle{unsrtnat}   % the class may demand a specific .bst
    \bibliography{references}      % harmless if references.bib is absent
    \end{document}

    Options, and the clash that follows from them

    An option can only be seen once. Packages store the options they were loaded with, and if the class already did \RequirePackage{xcolor} and you then write \usepackage[dvipsnames]{xcolor}, LaTeX refuses to load it a second time with a different option set and prints ! Option clash for package xcolor. The message names the package, which is the whole diagnosis; the rest is knowing the trick below.

    The trick is to declare the option before the class ever sees the package. Write \PassOptionsToPackage{dvipsnames}{xcolor} as a line above \documentclass. Now the package is loaded once, with the union of the options, and the clash disappears. The same line fixes the far more annoying variant where the option is silently ignored because a second load attempt did nothing.

    The second common clash is geometry. A class that sets its own margins has usually already loaded geometry; if you add \usepackage[a4paper,margin=2cm]{geometry} you get an option clash, or worse, you get the paper you wanted and a desk rejection because the running heads moved. If the template does not load geometry and you still want different margins, you are modifying the template, not using it — decide which game you are playing.

    A third family is plain missing features: \usepackage{cleveref} after hyperref, \usepackage{enumitem} when the class redefines \labelitemi, or amsthm in a class that already defines theorem environments. The general load-order rules are few and worth memorising: inputenc/fontenc early, hyperref near last, and cleveref after hyperref. Everything else can go in any order.

    \bigl\lVert \mathbf{A} \bigr\rVert_{2} = \sigma_{\max}(\mathbf{A})
    \bigl\lVert \mathbf{A} \bigr\rVert_{2} = \sigma_{\max}(\mathbf{A})
    Nothing here is exotic: \bigl, \bigr and \lVert are all amsmath/amssymb. If a class ships without them, the same line fails with Undefined control sequence — a missing package, not a missing skill.

    The five things that actually go wrong

    1. File `something.sty' not found from a file you were not sent. The template depends on a package the publisher assumed you have. Find the owner (tlmgr search --global --file "/something.sty", or the MiKTeX Console search), install it, and if you must, place a copy in your own tree and rebuild the database. Do not copy it into the distribution tree, and never paste the package source into your document.

    2. ! Undefined control sequence. on \keywords, \institute or \affil. The command belongs to the shipped class and you are compiling against the wrong one — because your \documentclass line still says article, or because the class file is not next to the file you are actually building, or because you edited a copy in a subdirectory while your editor compiles the one in the root. This is a file-location problem wearing a syntax-error costume.

    3. The title page comes out wrong: authors jammed together, no affiliations, a \thanks that vanished. Multi-author blocks are the least standardised part of LaTeX. In article you separate authors with \and, not with a comma and not with \\; a class using authblk wants \author[1]{...} and \affil[1]{...}; LNCS wants \and and \institute{...}. Copy the pattern straight from the shipped sample rather than inventing one, and put accents in names as \'e-style or correct UTF-8 — a broken é in an author list is a very expensive typo to notice after the proceedings are printed.

    4. References come out as [?]. Four causes, in order: you compiled once instead of the required LaTeX → BibTeX/Biber → LaTeX → LaTeX; the \bibliographystyle{...} line names a .bst that is not installed; the \bibliography{...} path is wrong; or the citation key is misspelled and the real message is in .blg. Note that [?] for every citation is a pipeline problem, while [?] for one is a key problem — that distinction saves an hour.

    5. The document is one page too long, or a figure will not fit. In a two-column class, a single-column display has roughly half your text width to live in, so long formulae must be split across lines with \begin{aligned}, or promoted to a two-column float using \begin{figure*} and \begin{table*}, which span both columns and float to the top of a page. Never resize text to buy space: shrink the figure, not the font, and never set a font size the class does not offer.

    \sum_{i=1}^{n} \left( x_{i} - \bar{x} \right)^{2} = \sum_{i=1}^{n} x_{i}^{2} - n\bar{x}^{2}
    \sum_{i=1}^{n} \left( x_{i} - \bar{x} \right)^{2} = \sum_{i=1}^{n} x_{i}^{2} - n\bar{x}^{2}
    \tilde{a} \quad \hat{b} \quad \bar{x} \quad \vec{v} \quad \dot{y} \quad \Gamma
    \tilde{a} \quad \hat{b} \quad \bar{x} \quad \vec{v} \quad \dot{y} \quad \Gamma
    # 1. Can the engine see the file at all? (print the path, or nothing)
    kpsewhich myconference.cls
    kpsewhich splncs04.bst
    kpsewhich -var-value TEXMFHOME       # your personal tree
    kpsewhich -var-value TEXINPUTS       # extra search path, if any
    
    # 2. Which files does the run actually read? (-recorder writes .fls)
    latexmk -pdf -recorder -interaction=nonstopmode main.tex
    grep -i "cls\|sty" main.fls | sort -u | head -40
    
    # 3. TeX Live: find the package that owns a missing file
    tlmgr search --global --file "/splncs04.bst"
    tlmgr install <the-package-name-it-prints>
    
    # MiKTeX: search the package list in the Console, install it, then
    # Maintenance -> Refresh file name database.  Skipping the refresh is why
    # a clearly-installed file is still reported as not found.
    initexmf --update-fndb
    
    # Put a received template in your OWN tree, never inside the distribution:
    #   <TEXMFHOME>/tex/latex/myconference/myconference.cls
    #   <TEXMFHOME>/bibtex/bst/myconference/splncs04.bst
    # then run  mktexlsr   (TeX Live) or refresh the FNDB (MiKTeX).

    Writing your own class is cheaper than you think

    If you are fighting a template weekly — a thesis with a house style, a lab report series, exam papers — write a small class instead of a preamble you paste around. A class file is ordinary LaTeX with five extra lines at the top: \NeedsTeXFormat{LaTeX2e}, \ProvidesClass for the name and version, \DeclareOption for each option you accept, \ProcessOptions, and \LoadClass to inherit from article or report. Everything after that is the same \setlength and \renewcommand you already know.

    The listing on this page is a complete, loadable example of that: two options of its own, a wildcard that forwards anything unknown to article, a personal-tree install path and a \linespread tweak. Read it as a template for your own; the pattern \DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}} is the one line that makes a derived class behave sanely.

    Put it where LaTeX will find it without you thinking: either next to the document, or in your personal tree at <TEXMFHOME>/tex/latex/myconference/myconference.cls, where TEXMFHOME is the path kpsewhich -var-value TEXMFHOME prints. On TeX Live run mktexlsr afterwards; on MiKTeX refresh the file name database. From then on \documentclass{myconference} works in any project on that machine, and your five theses finally share one definition of the margins.

    The payoff is reproducibility, which is what a template is really for. A class file can be versioned, reviewed and diffed; a preamble copy-pasted across six documents drifts, and the drift shows up as the sixth document having different spacing three weeks before the deadline.

    % myconference.cls —— a real, loadable class file in twenty lines.
    % Keep it in the same folder as main.tex and \documentclass{myconference}
    % will find it: the current directory is searched before anything else.
    \NeedsTeXFormat{LaTeX2e}
    \ProvidesClass{myconference}[2025/03/01 v1.0 Tiny conference style]
    
    % ---- our own options, declared BEFORE the fallback ----
    \newif\if@poster
    \@posterfalse
    \DeclareOption{poster}{\@postertrue}
    \DeclareOption{tightlines}{\AtEndOfClass{\linespread{0.97}\selectfont}}
    
    % ---- anything we do not know gets forwarded to the base class ----
    \DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
    
    \ExecuteOptions{a4paper}
    \ProcessOptions\relax
    
    \LoadClass{article}
    
    % ---- the actual "look" of the template ----
    \RequirePackage[T1]{fontenc}
    \RequirePackage{microtype}
    \RequirePackage[margin=2.2cm,columnsep=1.4em]{geometry}
    \setlength{\parskip}{0.35em}
    \setlength{\parindent}{0pt}
    
    \if@poster
      \pagestyle{empty}
      \setlength{\parskip}{1em}
    \fi
    
    \renewcommand{\section}{%
      \@startsection{section}{1}{\z@}{-1.2ex}{0.6ex}{\normalfont\large\bfseries}}
    
    \endinput

    Overleaf templates, and when to stop

    An Overleaf gallery template is the same set of files plus a server that decides the engine. Two project settings matter: Menu → Main document, because a template zip contains four .tex files and only one of them has \documentclass in it, and Menu → Compiler plus TeX Live version, because a class written for XeLaTeX produces broken output under pdfLaTeX and a project pinned to an old TeX Live can fail on a package that needs a newer one.

    Uploading your own template is just that: upload the zip, set the main document, and check the compiler. Keep a latexmkrc file in the project root if you need a specific engine flag or max_print_line; Overleaf reads it, and so does latexmk locally, which means the same file can carry the build rules for both places.

    The mirror-image mistake is over-customising. Every change you make inside the class is a change you must defend, and a venue that says "use our template unmodified" means the page geometry, the fonts and the caption style. If you need a longer title block, the fix is \linebreak inside \title{} or a shorter title, not a redefinition of \maketitle. If the template genuinely cannot express what you need, say so to the editor — that conversation is short, and the one with the proceedings office about a non-conforming PDF is not.

    A reasonable stopping rule: budget one hour of template-fighting. If the sample compiles and your content does not, the problem is one file or one option, and the diagnostics near the top of this page will name it. Beyond that you are no longer using a template — you are writing one, and you should decide deliberately whether the deadline allows it.

    Lesson cheat sheet

    One key line of code from each section — jump to it or copy it straight from here.

    Section Key code
    \documentclass[twocolumn,10pt,a4paper]{article} % <- the venue's line: do not edit
    \bigl\lVert \mathbf{A} \bigr\rVert_{2} = \sigma_{\max}(\mathbf{A})
    # 1. Can the engine see the file at all? (print the path, or nothing)
    \NeedsTeXFormat{LaTeX2e}

    Common mistakes

    • Renaming \documentclass{article} to the shipped class but leaving the class file in a subfolder, then reading File `venue.cls' not found as a bug in the template.
    • Editing the .cls or .sty directly to change one font size, and discovering at resubmission time that the diff now touches the publisher's code.
    • Ignoring ! Option clash for package xcolor by removing the \usepackage line — the option you wanted then silently never applies; the fix is \PassOptionsToPackage above \documentclass.
    • Separating multiple authors with \\ or a comma instead of \and, so the title page stacks every name on one line.
    • Buying page space with \vspace{-6pt} and a smaller font, which breaks the venue's line grid and is visible in the first three seconds of review.
    • Copying the shipped sample, keeping its \bibliographystyle and then wondering why references never appear — the style file named there is often not the one the class installs.
    • Compiling a XeLaTeX-only template with pdfLaTeX because that is the editor default; the symptoms are wrong fonts, not a clear error.

    Questions about this lesson

    What is the difference between a cls file and a sty file in LaTeX?
    The .cls is the document class, loaded once by \documentclass, and it defines the whole page and the commands your document may use. A .sty is a package, loaded with \usepackage, which adds or adjusts behaviour. Classes may themselves load packages, which is where option clashes come from: whoever loads a package first gets to choose its options.
    Where do I put a class file I was sent?
    Either in the same folder as the file containing \documentclass, which always works because the working directory is searched first, or in your personal tree under the folder kpsewhich reports for TEXMFHOME and then rebuild the file database. Never install it inside the distribution tree, where an update can remove it.
    Why does my template say keywords undefined?
    Because \keywords is invented by the template class and you are compiling against a standard class instead. Check the \documentclass line, check that the shipped .cls is in the folder you are building from, and check in your editor which file is actually the main document.
    Can I change the margins of a journal template?
    You can, and you should not. The page geometry is what the reviewers and the production department are calibrating for, and changing it changes your page count. If a figure or an equation genuinely does not fit, resize the figure or split the equation; if the whole document cannot fit, that is a message for the editor, not a geometry line.
    How do I use a local template on Overleaf?
    New project from upload, choose the zip, then set Menu -> Main document to the file that contains \documentclass and set the compiler the template needs. Do not reorganise the files into folders until it compiles: many templates use relative paths for figures and style files.
    Why are all my citations showing as [?]?
    Every citation broken means the bibliography step never ran or the style file is missing; one citation broken means that key does not match your .bib file. Run latexmk, which sequences LaTeX, BibTeX or Biber and the two follow-up passes for you, then read the .blg file rather than the .log for these problems.

    Live playground: edit the LaTeX, see it render

    The preview updates as you type — break it on purpose to see how errors look.

    KaTeX error
    Try an example

    Keep reading

    Three ways into the same idea: the notation itself, the lesson that teaches it, and an article that applies it.