# Declare a math operator with only lower limit

I'd like to declare a math operator which only expects a lower limit but not an upper one. What I mean is that in case of a display, only the lower limit would go under the operator while I can write a superscript to it and it would behave like a superscript not like a limit and would go above it. This is a behavior between what \DeclareMathOperator and \DeclareMathOperator* do.

\documentclass{article}
\usepackage{amsmath,amssymb}

\DeclareMathOperator{\Norm}{\mathbf{N}}
\DeclareMathOperator*{\Norma}{\mathbf{N}}

\begin{document}
\begin{align*}
\Norm_{x\in X}^pf(x)&=\left(\int_{x\in X}|f(x)|^p\right)^{1/p}\\
\Norma_{j\in \mathbb Z}^pf_j&=\left(\sum_{j\in\mathbb Z}|f_j|^p\right)^{1/p}
\end{align*}
\end{document}


So the placement of p is good and x\in X is bad in the first formula while the placement of j\in \mathbb Z is good but p is bad in the second.

I add that \lim is an operator where we don't use upper limit but we certainly could use an upper index so that we could indicate what kind of limit we have. In this example, the w should be placed in the superscript, not as an upper limit.

\documentclass{article}
\usepackage{amsmath}

\begin{document}
Definition of weak limit
\begin{equation*}
\lim_{n\to \infty}^{w}f_n =\lim_{n\to \infty}(f_n,g)\text{ for every }g
\end{equation*}
\end{document}


• For weak limit, you can use something like w-lim. Commented May 26 at 18:45
• Off-topic: The line \left(\sum_{j\in\mathbb Z}|f_j|^p\right)^{1/p} is a perfect illustration of how things can go terribly wrong when \left and \right are used indiscriminately. You really should be replacing both instances of \left with \biggl and both instances of \right with \biggr.
– Mico
Commented May 26 at 21:50

Some measurements are necessary when the limits are given: there are three cases:

1. the limits exceed the width of the exponent
2. the exponent exceeds the width of the limit, but this exceeds the width of N
3. otherwise
\documentclass{article}
\usepackage{amsmath}

\NewDocumentCommand{\Norm}{e{^_}}{%
\IfNoValueTF{#2}{% no limit
\operatorname{N}\IfValueT{#1}{^{#1}}%
}{% with limit
\mathop{%
\mathchoice{\NORM{\IfValueT{#1}{#1}}{#2}}% <-- Fixed 2024-06-06
{\operatorname{N}\IfValueT{#1}{^{#1}}_{#2}}%
{\operatorname{N}\IfValueT{#1}{^{#1}}_{#2}}%
{\operatorname{N}\IfValueT{#1}{^{#1}}_{#2}}%
}\nolimits
}%
}

\makeatletter
\newcommand{\NORM}[2]{%
\sbox\z@{$\m@th{}^{#1}$}% the superscript
\sbox\tw@{$\m@th\scriptstyle#2\kern-\scriptspace$}% the subscript
\sbox4{$\m@th\operatorname{N}$}% the base
\operatorname*{N\rlap{\copy\z@}}_{#2}%
\dimen@=\dimeval{0.5\wd\tw@ - 0.5\wd4 - \wd\z@}
\ifdim\dimen@>0pt
% the limit protrudes beyond the base with the superscript
\else
\ifdim\wd\tw@<\wd4
% short limit
\kern\wd\z@
\else
\kern-\dimen@
\fi
\fi
}
\makeatother

\begin{document}

$\Norm^{p}_{j}(v)$ $\Norm^{p}_{j\in X}(v)$ $A_{\Norm^{p}_{j\in X}(v)}$
$\Norm^{p}_{j}(v)\quad \Norm^{p}_{j\in X}(v) \quad \Norm^p_{a+b\in A}(v)$

\end{document}


With \mathchoice we can know whether the construction is in one of the four math styles and make TeX choose the appropriate one.

In comments you mention making the N bigger with \scalerel.

\documentclass{article}
\usepackage{amsmath}
\usepackage{scalerel}

\newcommand{\Normop}{\mathop{\scalerel*{\mathbf{N}}{\sum}}}

\NewDocumentCommand{\Norm}{e{^_}}{%
\IfNoValueTF{#2}{% no limit
\Normop\IfValueT{#1}{^{#1}}%
}{% with limit
\mathop{%
\mathchoice{\NORM{\IfValueT{#1}{#1}}{#2}}% <-- Fix 2024-06-06
{\Normop\IfValueT{#1}{^{#1}}_{#2}}%
{\Normop\IfValueT{#1}{^{#1}}_{#2}}%
{\Normop\IfValueT{#1}{^{#1}}_{#2}}%
}\nolimits
}%
}

\makeatletter
\newcommand{\NORM}[2]{%
\sbox\z@{$\m@th\scriptstyle#1$}% the superscript
\sbox\tw@{$\m@th\scriptstyle#2\kern-\scriptspace$}% the subscript
\sbox4{$\m@th\displaystyle\Normop$}% the base
\operatorname*{\Normop\nolimits^{\rlap{\copy\z@}}}_{#2}%
\dimen@=\dimeval{0.5\wd\tw@ - 0.5\wd4 - \wd\z@}
\ifdim\dimen@>0pt
% the limit protrudes beyond the base with the superscript
\else
\ifdim\wd\tw@<\wd4
% short limit
\kern\wd\z@
\else
\kern-\dimen@
\fi
\fi
}
\makeatother

\begin{document}

$\Norm^{p}_{j}(v)$ $\Norm^{p}_{j\in X}(v)$ $A_{\Norm^{p}_{j\in X}(v)}$
$\Norm^{p}_{j}(v)\quad \Norm^{p}_{j\in X}(v) \quad \Norm^p_{a+b\in A}(v)$
$\Norm^p_{aaaaaaaaaa}(v)$

\end{document}


### Update for a generic version

The \genericnorm command takes as first argument the letter to use; two optional arguments follow, both contain a factor for moving horizontally the superscript; the first one for nondisplay styles, the second one for display style. They are necessary for A and possibly for other letters.

The other two arguments are the same as before: optional superscript and optional subscript introduced as usual by ^ and _ (in either order).

Once the generic command is available, you can define abbreviations for frequently used ones, as shown below. The names witness my lack of fantasy. 😊

\documentclass{article}
\usepackage{amsmath}
\usepackage{scalerel}

\newcommand{\genericnormop}[1]{\mathop{\scalerel*{\mathbf{#1}}{\sum}}}

\NewDocumentCommand{\genericnorm}{mO{0}O{#2}e{^_}}{%
\IfNoValueTF{#4}{\mathchoice % no limit
{\genericnormop{#1}\IfValueT{#4}{^{\mspace{#3mu}#4}}}%
{\genericnormop{#1}\IfValueT{#4}{^{\mspace{#2mu}#4}}}%
{\genericnormop{#1}\IfValueT{#4}{^{\mspace{#2mu}#4}}}%
{\genericnormop{#1}\IfValueT{#4}{^{\mspace{#2mu}#4}}}%
}{% with limit
\mathop{%
\mathchoice{\GENERICNORM{#1}{\IfValueT{#4}{\mspace{#3mu}#4}}{#5}}%
{\genericnormop{#1}\IfValueT{#4}{^{\mspace{#2mu}#4}}_{#5}}%
{\genericnormop{#1}\IfValueT{#4}{^{\mspace{#2mu}#4}}_{#5}}%
{\genericnormop{#1}\IfValueT{#4}{^{\mspace{#2mu}#4}}_{#5}}%
}\nolimits
}%
}

\makeatletter
\newcommand{\GENERICNORM}[3]{%
\sbox\z@{$\m@th\scriptstyle#2$}% the superscript
\sbox\tw@{$\m@th\scriptstyle#3\kern-\scriptspace$}% the subscript
\sbox4{$\m@th\displaystyle\genericnormop{#1}$}% the base
\operatorname*{\genericnormop{#1}\nolimits^{\rlap{\copy\z@}}}_{#3}%
\dimen@=\dimeval{0.5\wd\tw@ - 0.5\wd4 - \wd\z@}
\ifdim\dimen@>0pt
% the limit protrudes beyond the base with the superscript
\else
\ifdim\wd\tw@<\wd4
% short limit
\kern\wd\z@
\else
\kern-\dimen@
\fi
\fi
}
\makeatother

\NewDocumentCommand{\Norm}{}{\genericnorm{N}}
\NewDocumentCommand{\Aorm}{}{\genericnorm{A}[-4][-10]}
\NewDocumentCommand{\Eorm}{}{\genericnorm{E}}

\begin{document}

$\Norm^{p}_{j}(v)$ $\Norm^{p}_{j\in X}(v)$ $A_{\Norm^{p}_{j\in X}(v)}$

$\Aorm^{p}_{j}(v)$ $\Aorm^{p}_{j\in X}(v)$ $A_{\Aorm^{p}_{j\in X}(v)}$

$\Eorm^{p}_{j}(v)$ $\Eorm^{p}_{j\in X}(v)$ $A_{\Eorm^{p}_{j\in X}(v)}$
$\Norm^{p}_{j}(v)\quad \Norm^{p}_{j\in X}(v) \quad \Norm^p_{a+b\in A}(v)$
$\Aorm^p_{aaaaaaaaaa}(v)$

$\Eorm^q_x \quad \Eorm_x$

\end{document}


• I actually was trying to make this thing work with using scalerel so I had \DeclareMathOperator*{\opnorm}{\scalerel*{\mathbf{N}}{\sum}} . I tried to replace the N by \scalerel*{\mathbf{N}}{\sum} in your code but the superscript gets messed up in the display part. Commented May 27 at 0:22
• @MátéWierdl You should have mentioned that in the question. Anyway, I added the code for that case. Commented May 27 at 8:11
• I thought that was just a particularity in my setup and I thought I could do the modification myself. This is perfect, thx! Commented Jun 3 at 16:37
• @MátéWierdl Fixed! Sorry, I overlooked a condition. Just one line of code has changed. For the other problem I'll try and come up with a generic solution. Commented Jun 6 at 21:07
• @MátéWierdl The “generic” version is online. You may need to tailor the optional arguments for \Aorm to the specific font you use. Commented Jun 6 at 21:37
\documentclass{article}
\usepackage{amsmath,amssymb}

\NewDocumentCommand{\Norm}{E{_^}{{}{}}}{\mathop{\underset{#1}{\mathbf{N}}^{#2}}}

\begin{document}

$\Norm_{x\in X}^p f(x) = \left(\int_{x\in X}|f(x)|^p\right)^{1/p}$

\end{document}


Or maybe:

\documentclass{article}
\usepackage{amsmath,amssymb,mathtools}

\NewDocumentCommand{\Norm}{E{_^}{{}{}}}{\mathop{\underset{#1}{\mathbf{N}^{\mathrlap{#2}}}}}

\begin{document}

$\Norm_{x\in X}^p f(x) = \left(\int_{x\in X}|f(x)|^p\right)^{1/p}$

\end{document}


A version with the subscript in position \nolimits in text style and \limits in display style.

\documentclass{article}
\usepackage{amsmath,amssymb,mathtools}

\NewDocumentCommand{\Norm}{E{_^}{{}{}}}{\mathop{\mathbf{N}^{\mathrlap{#2}}}_{#1}^{}}

\begin{document}

In the text : $\Norm_{x\in X}^p f(x) = \left(\int_{x\in X}|f(x)|^p\right)^{1/p}$
$\Norm_{x\in X}^p f(x) = \left(\int_{x\in X}|f(x)|^p\right)^{1/p}$

\end{document}


• The second one is already great, thx, but is it possible to make sure that in non-display math mode it doesn't print the subscript under the operator's name but just as a subscript (exactly as it's done by default with limits of operators)? Commented May 26 at 17:28
• I actually was trying to make this thing work with using scalerel so I had \DeclareMathOperator*{\opnorm}{\scalerel*{\mathbf{N}}{\sum}} I tried to replace the N by \scalerel*{\mathbf{N}}{\sum} but the superscript gets messed up. Commented May 27 at 0:20