CorTeX DocsOpen CorTeX
Open CorTeX
Browse all topics

Use LaTeX commands and environments

Read command arguments, optional settings, and begin–end environments without guessing at the syntax.

On this page

LaTeX source becomes much easier to debug once you can see its grammar. Commands perform an action, arguments supply content, environments apply one rule to a region, and packages add definitions that the base format does not provide.

Read commands from left to right#

Most commands start with a backslash. Required arguments use braces and optional settings use brackets:

  • \section{Method} has one required argument.
  • \documentclass[11pt]{article} adds an optional setting before the required class name.
  • \includegraphics[width=0.7\linewidth]{figures/result.pdf} uses a key–value option and a required file path.
  • % starts a comment; LaTeX ignores the rest of that source line.

An option is meaningful only if that command or package defines it. Swapping braces and brackets does not make an argument optional.

Match scope and environments#

Braces also limit scope. In {\small calibration data}, the size change ends at the closing brace. An environment begins with \begin{name} and must end with the same \end{name}.

LaTeX source
\documentclass[11pt]{article}
\usepackage[margin=30mm]{geometry} % page layout package
\newcommand{\dataset}{\textsc{RiverFlow}}
\begin{document}
We evaluated the model on the \dataset{} data set.

\begin{quote}
Reproducible analysis begins with a clearly defined data set.
\end{quote}

The full text is normal size; {\small this qualification is smaller}.
\end{document}
Compiled result
Open in CorTeX

The result has 30 mm margins, a reusable small-caps data-set name, an indented quotation, and a size change confined to one phrase. Put document-wide \newcommand definitions in the preamble so they are available before use. This is an organization choice, not a requirement that every command definition appear there. The empty braces in \dataset{} end the command before the following space; otherwise TeX may consume that source space.

Recognize broken shapes#

These errors often surface on a later line because LaTeX keeps looking for the missing boundary:

Broken source Correct source Why
\textbf{Key result \textbf{Key result} A required argument needs its closing brace.
\begin{quote} ... \end{quotation} \begin{quote} ... \end{quote} Environment names must match exactly.
\includegraphics{width=5cm}[plot.pdf] \includegraphics[width=5cm]{plot.pdf} Options precede required arguments.
50% of samples 50\% of samples An unescaped % comments out the rest of the line.

An “Undefined control sequence” usually means the command is misspelled, its package is not loaded, or its definition occurs too late. Do not add packages at random; identify the command first, then use the undefined-command guide.

Try adding \newcommand{\species}{\textit{E. coli}} to the preamble and using \species{} twice in the example. Compile and confirm both occurrences change together. Then continue with document structure.