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.
New commands, except for the last character (which can also be a *), should consist only of letters.
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.
The command used to define new commands is \newcommand
.
\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.
\newcommand{\nbs}{\nobreakspace} \newcommand{\GTn}{Game theory\nbs}Output:
Game theory is a part of economics.
\newcommand{\Name}[Number]{Definition}
\newcommand{\GTB}[1]{\GT \ Sheet No.#1} \GTB{2}Output:
Game theory Sheet No.2
Note: Only 9 elements are possible as arguments!
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}
\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
Occasionally, it's necessary to change the properties of an existing command. This is done with the command:
\renewcommand{Command}{New Definition}
\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.
Procedure: \DeclareMathOperator{\Name}{Name}
Note: Only in the preamble is possible, meaning before \begin{document}
!
Declare \DeclareMathOperator{\Det}{Det}