Summary

Writing your own packages (.sty) and classes (.cls), @makeatletter, custom environments, and advanced compilation.

Prerequisite: Lessons 01–04 (setup, basics, templates, modularization).

1. Writing packages (.sty)

A package lets you share styles and commands across documents.

% mystyle.sty
\ProvidesPackage{mystyle}[2026/03/17 v1.0]
 
\RequirePackage{geometry}
\RequirePackage{graphicx}
 
\newcommand{\mycommand}[1]{\textbf{#1}}
 
\endinput

2. Writing classes (.cls)

% myclass.cls
\ProvidesClass{myclass}[2026/03/17 v1.0]
\LoadClass{article}
 
\RequirePackage{geometry}
\RequirePackage{titlesec}
 
\titleformat{\section}{\Large\bfseries}{\thesection}{1em}{}

3. @makeatletter and internal commands

\makeatletter
\def\@my@thing{...}
\makeatother

4. Creating and redefining environments

\renewenvironment{quote}
  {\begin{center}\itshape}
  {\end{center}}
\newenvironment{mybox}[1]
  {\begin{center}\fbox{\begin{minipage}{0.9\linewidth}\textbf{#1}\\}}
  {\end{minipage}}\end{center}}

5. Special lists and custom indexes

\listoffigures / \listoftables / \listof{lol}{Title}, or custom lists with enumitem/tocloft.

6. Advanced compilation

latexmk -pdf -pvc for watch mode, xelatex/lualatex for better Unicode/system font support, make/arara for complex build pipelines.