This post is dedicated for a nice function that creates new commands: \newcommand . This newcommand must be defined before \begin{document} and must be used in Math or Text enviroment depending on the definition. The usage of \newcommand can be summarized as follows;
\newcommand{\NAME}[NUMBER]{DEFINITION}
Now we will continue with examples:
\newcommand{\NAME}[NUMBER]{DEFINITION}
- NAME: Name of the new command,
- NUMBER: How many parameters new command,
- DEFINITION: What this new command does. If you have parameters you are using, you can refer to them by #1, #2 where numbers indicate the sequence of parameters given.
Now we will continue with examples:
- \newcommand{\be}{\beta}
...
Let $\be$ be a number.
Outcome: Let β be a solution. - \newcommand{\name}{Murat}
...
They call me \name{}.
Outcome: They call me Murat.
Note: When you are using newcommand for text only without any parameters, then do not forget to use {} at the end. For example; "\name is" will be compiled into "Muratis" but not "Murat is". - \newcommand{\fct}[1]{f(#1)}
...
Let $\fct{x}$ be a function.
Outcome: Let f(x) be a function. - \newcommand{\dis}[2]{||#1- #2||}
...
The distance between x and y is $\dis{x}{y}$.
Outcome: The distance between x and y is ||x − y||.
Note: The reason of this post to show how helpfull newcommand function can be. For example, you wrote a document and started using Euclidean distance like this example. But then, you wanted to change your distance from Euclidean to any distance function. Then all you need to do is changing the definition of \newcommand{\dis}[2]{||#1- #2||}. For example: \newcommand{\dis}[2]{|#1- #2|}, \newcommand{\dis}[2]{dis(#1,#2)}. So, you don't need to go over all of you document and change them one by one.