StartLaTeX faqLaTeX for Beginners F.A.Q.LaTeX topicsLaTeX courseSearch

Introduction to New Commands

When introducing a new command in LaTeX, it's essential to avoid using existing names. As an alternative, consider using the German name or capitalizing the command.

For example, \neueseite as a new command analogous to the \newpage command.

Naming New Commands

New commands, except for the last character (which can also be a *), should consist only of letters.

Location

The user is free to define new commands wherever they wish. An exception is the Beamer class, where the new command must be defined before the document begins or in every frame where it's used.

\newcommand

The command used to define new commands is \newcommand.

Defining New Commands:

\newcommand{Name}{Definition}

For example, defining an abbreviation:

Input:
\newcommand{\GT}{Game theory}
\GT is a part of economics.
Output:
Game theoryis a part of economics.

Nested Commands

Input:
\newcommand{\nbs}{\nobreakspace}
\newcommand{\GTn}{Game theory\nbs}
Output:
Game theory is a part of economics.

Defining Commands with Arguments

New commands with additional arguments can be defined: \newcommand{\Name}[Number]{Definition}

Abbreviations II

Input:
\newcommand{\GTB}[1]{\GT \ Sheet No.#1}
\GTB{2}
Output:
Game theory Sheet No.2

Note: Only 9 elements are possible as arguments!

Defining Commands with Options

When defining new commands, they can also be equipped with options. If no argument is passed, the default value will be taken.

Command: \newcommand{\Name}[Number][Default]{Definition}

Abbreviations III

Input:
\newcommand{\Studium}[1][Economics]{Major: #1}
\Studium from ... to \\
\Studium[Computer Science] from ... to \\
\Studium[Engineering] from ... to \\
Output:
Major: Economics from ... to
Major: Computer Science from ... to
Major: Engineering from ... to

Changing Commands with \renewcommand

Occasionally, it's necessary to change the properties of an existing command. This is done with the command:

\renewcommand{Command}{New Definition}

Example

Input:
\newcommand{\City}{The most beautiful city is Cologne!}
\City \\
\renewcommand{\City}{The most beautiful city is Duesseldorf!}
\City \\
Output:
The most beautiful city is Cologne!
The most beautiful city is Duesseldorf!

The \renewcommand can be applied not only to custom commands but also to the standard LaTeX commands. For example, the chapter command has been changed here.

Defining Mathematical Operators

Procedure: \DeclareMathOperator{\Name}{Name}

Note: Only in the preamble is possible, meaning before \begin{document}!

Example

Declare \DeclareMathOperator{\Det}{Det}

Contact   Privacy Policy   disclosures

accept decline

This website uses cookies and pixel tags to ensure you get the best experience on our website. By using this website, you consent to the use of cookies.learn more about cookies see also our privacy policy