I have a series of norm macros that I want to expand to \left\| ...\right\|
in display math but remain as \| ... \|
in inline math. Each norm has a subscript unique to the macro:
\newcommand {\normbrak} [2] % display/inline -aware norm brackets
{\mathchoice{\left\|#1\right\|_{#2}}{\|#1\|_{#2}}{\|#1\|_{#2}}{\|#1\|_{#2}}}
\newcommand {\inorm} [1] {\normbrak{#1}{1}} % 1-norm (nuclear norm)
\newcommand {\iinorm} [1] {\normbrak{#1}{2}} % 2-norm (operator norm)
\newcommand {\fronorm} [1] {\normbrak{#1}{\text{F}}} % Frobenius norm
\newcommand {\infnorm} [1] {\normbrak{#1}{\infty}} % infinity norm
\newcommand {\Linorm} [1] {\normbrak{#1}{L^1}} % L1 norm
\newcommand {\Liinorm} [1] {\normbrak{#1}{L^2}} % L2 norm
\newcommand {\Linfnorm} [1] {\normbrak{#1}{L^\infty}} % L-infinity norm
In certain places, I wish to write, e.g., \fronorm{\hat H}^{-1}
to get a superscript on the norm as well. My problem is that \mathchoice
appears to reset the positioning of superscripts and subscripts, yielding
instead of the proper
One possible solution is to rewrite every macro as, e.g.
\newcommand {\normbrak} [3] {%
\mathchoice
{\left\|#1\right\|_{#2}\IfNoValueF {#3} {\sp{#3}}}
{\|#1\|_{#2}\IfNoValueF {#3} {\sp{#3}}}
{\|#1\|_{#2}\IfNoValueF {#3} {\sp{#3}}}
{\|#1\|_{#2}\IfNoValueF {#3} {\sp{#3}}}%
}
\NewDocumentCommand {\fronorm} {me{^}} {%
\normbrak{#1}{\text{F}}{#2}%
}
but this seems messy and redundant.
Is there a way to stop \mathchoice
from ratching the bounds of its contents, or a macro other than \mathchoice
that would work here?
Best Answer
You have to absorb the possible superscript before calling
\mathchoice
.Here's a way to do it, with some fixes:
\lVert
and\rVert
instead of\|
(try\|-x\|
to see why);\mathrm{F}
instead of\text{F}
(try in a theorem statement to see why).This image, however, clearly shows why using
\left
and\right
is very dangerous, because it leads to very oversized delimiters.