**Introduction**

Latex is arguably the most popular typesetting languages in the world today. It is a free software package that was developed by the Leslie Lamport in 1985 to make it easier to create professional articles with mathematical notations. It has a powerful list of packages that can be installed to augment the features and also a very active online community for support. In this article, we describe the process for typesetting the argmax and argmin operators in Latex documents.

Argmax is one of the most important mathematical functions used in machine learning. The operation entails selecting the index of the maximum element of an array. As a typical application, when a classifier outputs an array of probabilities for each of the classes, the argmax function is used to predict the class from the index of the maximum element. Similarly, the argmin function involves selecting the index of the minimum element of an array. It could be used to find the minima of a discrete function.

**Also Read: What is Argmax in Machine Learning?**

**Argmax Latex**

We will describe two ways of writing the argmax function in latex.

*Method 1: Argmax uing the equation environment*

In the base document class article, we can use the the \arg and \max supported Latex commands within the equation environment to generate the argmax function as follows.

\documentclass{article}

\begin{document}

\begin{equation}

\arg \max_{k} P(k)

\end{equation}

\end{document}

The above code produces the following output.

Note that the function name P refers to the probability and the argument k is the class. This expression refers to the decision rule of selecting the class with the maximum probability.

As we can see, the issue with this option is that the argument k is not centered on the word argmax. Moreover, the gap between the words “arg” and “max” may not be desirable. We can correct both these issues by using the amsmath package of latex.

*Method 2: Argmax using the amsmath package*

The amsmath package of latex was developed by the American Mathematical Society as an extension to Latex for multiline equations and complex mathematical notations. It offers the underset environment for centrally aligning the . We define a special command using the \DeclareMathOperator to correct the spacing. Once the command is defined, it can be used within math mode.

\documentclass{article}

\usepackage{amsmath}

\DeclareMathOperator*{\argmax}{argmax}

\begin{document}

\[ \argmax_x f(x) \]

\end{document}

The above code produces the following output.

As we can see, the argument k is not centered and the blank space between “arg” and “max” is now gone. Note that once we define the math operator, it can used repeatedly in the entire document.

**Argmin Latex**

The above two methods can be used to produce argmin as follows.

*Method 1: Argmin using the equation environment*

As with the method above, we can use the \arg and \min supported Latex commands within the equation environment to create the argmin in Latex.

\documentclass{article}

\begin{document}

\begin{equation}

\arg \min_{k} P(k)

\end{equation}

\end{document}

The above code produces the following output.

The problem again is that there is a gap between the “arg” and “min”. Also, k is not centered. Let us see how method 2 can overcome this issue.

*Method 2: Argmin using the amsmath package*

\documentclass{article}

\usepackage{amsmath}

\DeclareMathOperator*{\argmin}{argmin}

\begin{document}

\[ \argmin_x f(x) \]

\end{document}

The output is shown below.

We can use the \DeclareMathOperator to create a new operator for argmin and then reuse it for every occurrence. This approach removes the gap between “arg” and “min”. Also k is nicely centered this time.

**Experiments with Argmax and Argmin in Latex (Code Snippets)**

We combine all the above options for Argmin and Argmax into one Latex file below as an illustrative example.

\documentclass{article}

\usepackage{amsmath}

\DeclareMathOperator*{\argmax}{argmax}

\DeclareMathOperator*{\argmin}{argmin}

\title{Experiments with argmax and argmin}

\begin{document}

\date{}

\maketitle

\begin{equation}

\arg \max_{k} P(k)

\end{equation}

\begin{equation}

\argmax_x P(k)

\end{equation}

\begin{equation}

\arg \min_{k} P(k)

\end{equation}

\begin{equation}

\arg \min_{k} P(k)

\end{equation}

\end{document}

The output produced by the above code is shown below.

**Conclusion**

We presented two approaches for producing argmax and argmin functions in Latex. The first method uses the equation mode and suffers from the issue of the gap. Moreover, the index of the armax and argmin function may not be centered under the operator. On the other hand, the \DeclareMathOperator defines a custom operator that can be used throughout the document and overcomes gap issue and also the index is centered.

Argmax is one of the most commonly used functions in machine learning and Latex can be used to produce professional reports about machine learning projects and research.

**Also Read: Python Argmax**

**References**

Admin. “How to Use the Argument Minimum and Argument Maximum Operators.” *LaTeX-Tutorial.Com*, 13 Oct. 2021, https://latex-tutorial.com/argmin-argmax/. Accessed 7 Mar. 2023.

Alejandro. “Command for Argmin or Argmax?” *TeX – LaTeX Stack Exchange*, https://tex.stackexchange.com/questions/5223/command-for-argmin-or-argmax. Accessed 7 Mar. 2023.

IntroductionLatex is arguably the most popular typesetting languages in the world today. It is a free software package that was developed by the Leslie Lamport in 1985 to make it easier to create professional articles with mathematical notations. It has a powerful list of packages that can be installed to augment the features and also a very active online community for support. In this article, we describe the process for typesetting the argmax and argmin operators in Latex documents.

Argmax is one of the most important mathematical functions used in machine learning. The operation entails selecting the index of the maximum element of an array. As a typical application, when a classifier outputs an array of probabilities for each of the classes, the argmax function is used to predict the class from the index of the maximum element. Similarly, the argmin function involves selecting the index of the minimum element of an array. It could be used to find the minima of a discrete function.

## Table of contents

Also Read: What is Argmax in Machine Learning?Argmax LatexWe will describe two ways of writing the argmax function in latex.

Method 1: Argmax uing the equation environmentIn the base document class article, we can use the the \arg and \max supported Latex commands within the equation environment to generate the argmax function as follows.

\documentclass{article}

\begin{document}

\begin{equation}

\arg \max_{k} P(k)

\end{equation}

\end{document}

The above code produces the following output.

Note that the function name P refers to the probability and the argument k is the class. This expression refers to the decision rule of selecting the class with the maximum probability.

As we can see, the issue with this option is that the argument k is not centered on the word argmax. Moreover, the gap between the words “arg” and “max” may not be desirable. We can correct both these issues by using the amsmath package of latex.

Method 2: Argmax using the amsmath packageThe amsmath package of latex was developed by the American Mathematical Society as an extension to Latex for multiline equations and complex mathematical notations. It offers the underset environment for centrally aligning the . We define a special command using the \DeclareMathOperator to correct the spacing. Once the command is defined, it can be used within math mode.

\documentclass{article}

\usepackage{amsmath}

\DeclareMathOperator*{\argmax}{argmax}

\begin{document}

\[ \argmax_x f(x) \]

\end{document}

The above code produces the following output.

As we can see, the argument k is not centered and the blank space between “arg” and “max” is now gone. Note that once we define the math operator, it can used repeatedly in the entire document.

Argmin LatexThe above two methods can be used to produce argmin as follows.

Method 1: Argmin using the equation environmentAs with the method above, we can use the \arg and \min supported Latex commands within the equation environment to create the argmin in Latex.

\documentclass{article}

\begin{document}

\begin{equation}

\arg \min_{k} P(k)

\end{equation}

\end{document}

The above code produces the following output.

The problem again is that there is a gap between the “arg” and “min”. Also, k is not centered. Let us see how method 2 can overcome this issue.

Method 2: Argmin using the amsmath package\documentclass{article}

\usepackage{amsmath}

\DeclareMathOperator*{\argmin}{argmin}

\begin{document}

\[ \argmin_x f(x) \]

\end{document}

The output is shown below.

We can use the \DeclareMathOperator to create a new operator for argmin and then reuse it for every occurrence. This approach removes the gap between “arg” and “min”. Also k is nicely centered this time.

Experiments with Argmax and Argmin in Latex (Code Snippets)We combine all the above options for Argmin and Argmax into one Latex file below as an illustrative example.

\documentclass{article}

\usepackage{amsmath}

\DeclareMathOperator*{\argmax}{argmax}

\DeclareMathOperator*{\argmin}{argmin}

\title{Experiments with argmax and argmin}

\begin{document}

\date{}

\maketitle

\begin{equation}

\arg \max_{k} P(k)

\end{equation}

\begin{equation}

\argmax_x P(k)

\end{equation}

\begin{equation}

\arg \min_{k} P(k)

\end{equation}

\begin{equation}

\arg \min_{k} P(k)

\end{equation}

\end{document}

The output produced by the above code is shown below.

ConclusionWe presented two approaches for producing argmax and argmin functions in Latex. The first method uses the equation mode and suffers from the issue of the gap. Moreover, the index of the armax and argmin function may not be centered under the operator. On the other hand, the \DeclareMathOperator defines a custom operator that can be used throughout the document and overcomes gap issue and also the index is centered.

Argmax is one of the most commonly used functions in machine learning and Latex can be used to produce professional reports about machine learning projects and research.

Also Read: Python ArgmaxReferencesAdmin. “How to Use the Argument Minimum and Argument Maximum Operators.”

LaTeX-Tutorial.Com, 13 Oct. 2021, https://latex-tutorial.com/argmin-argmax/. Accessed 7 Mar. 2023.Alejandro. “Command for Argmin or Argmax?”

TeX – LaTeX Stack Exchange, https://tex.stackexchange.com/questions/5223/command-for-argmin-or-argmax. Accessed 7 Mar. 2023.## Share this: