2

I'm trying to find the right definition for the norm of a vector. I used this macro before :

\newcommand{\norme}[2][]{\ensuremath{\left\lVert #2 \right\rVert_{#1}}}

(optionnal argument is to specify some special norms).

But it sometimes give bad result. Just look at this :

\documentclass{article}
\usepackage{amsmath}
\usepackage{esvect}

\newcommand{\norme}[2][]{\ensuremath{\left\lVert #2 \right\rVert_{#1}}}

\begin{document}
\begin{equation*}
    \norme[p]{u}^2, \norme[p]{\vv{u}}^2, \norme[p]{AB}^2, \norme[p]{\vv{AB}}^2.
\end{equation*}
\end{document}

Problem is, when there is an arrow above the vector (i.e. when there is a asymmetry between the height and the depth of the argument of norme), the result looks a bit ugly.

norm, versio 1

I found this new definition on a french forum :

\newcommand\norme[2][]{%
  \begingroup\setbox0 \hbox{\ensuremath{#2}}%
  \edef\drule{\vrule height\the\dimexpr\ht0+.25ex\relax
    depth\the\dimexpr\dp0+.25ex\relax width.6pt }% 
  \quitvmode
  \hbox{\drule\kern.16667em\drule\kern.16667em \box0
    \kern.16667em\drule\kern.16667em\drule}\endgroup_{#1} 
}

Problem now is that the vertical bars do not seem to behave like delimiters, so the square and the p on the right of the norm looks a bit too close :

\documentclass{article}
\usepackage{amsmath}
\usepackage{esvect}

\newcommand\norme[2][]{%
  \begingroup\setbox0 \hbox{\ensuremath{#2}}%
  \edef\drule{\vrule height\the\dimexpr\ht0+.25ex\relax
    depth\the\dimexpr\dp0+.25ex\relax width.6pt }% 
  \quitvmode
  \hbox{\drule\kern.16667em\drule\kern.16667em \box0
    \kern.16667em\drule\kern.16667em\drule}\endgroup_{#1} 
}

\begin{document}

\begin{equation*}
  \norme[p]{u}^2, \norme[p]{\vv{u}}^2, \norme[p]{AB}^2, \norme[p]{\vv{AB}}^2.
\end{equation*}

\end{document}

norm, version 2

What could I add to recover the proper behavior of my delimiters ?

Thanks for any help.

[Edit] I think what I need is put a "\mathopen" and a "\mathclose" somewhere in my macro definition, but I don't know where...

2
  • BTW: you should never use automatic \left...\right for this very reason. IMO there is no need to scale the norm on \vv{u}, as you have already seen they often get too big.
    – daleif
    May 25, 2021 at 15:30
  • For the \newcommand{\norme}[2][]{\ensuremath{\left\lVert #2 \right\rVert_{#1}}} I suggest to see dynbrackets package.
    – Sebastiano
    May 25, 2021 at 15:51

3 Answers 3

4

Maybe you can use \adjustbox to manually set the height and vertical offset.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\usepackage{esvect}
\usepackage{adjustbox}

\newcommand{\norme}[2][]{\ensuremath{\left\lVert #2 \right\rVert_{#1}}}

\begin{document}
\begin{equation*}
    \norme[p]{u}^2, 
    \norme[p]{\vv{u}}^2, 
    \norme[p]{AB}^2, 
    \norme[p]{\adjustbox{raise=-0.5ex, set height=2.0ex}{$\vv{AB}$}}^2.
\end{equation*}
\end{document}
2
  • Thanks for the tip. Could be useful for one or two vectors, but I type documents with lots of those norms, so it's not very practical... But I'll remember the trick ;-) May 25, 2021 at 15:30
  • You can define a macro to automate this.
    – Alan Xiang
    May 25, 2021 at 15:55
4

Using commath package:

\documentclass[12pt]{article}

\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{esvect}

\usepackage{commath}

\begin{document}
\[\enVert[0]{u}^{2}_{p}, \enVert[0]{\vv{u}}^{2}_{p}, \enVert[0]{AB}^{2}_{p}, \enVert[0]{\vv{AB}}^{2}_{p}  \]
\[\enVert[1]{u}^{2}_{p}, \enVert[1]{\vv{u}}^{2}_{p}, \enVert[1]{AB}^{2}_{p}, \enVert[1]{\vv{AB}}^{2}_{p}  \] 
\end{document}

enter image description here

7
  • 2
    Well, now the norm symbol on the last example is clearly too short :-) Too bad, the other three are quite alright ! May 25, 2021 at 15:38
  • @NicolasFRANCOIS It is true. In fact I have edited my answer using the factor scale 1. :-)
    – Sebastiano
    May 25, 2021 at 15:39
  • 1
    +1, but I wonder where and how you find this (to me exotic) packages like commath :-)
    – Zarko
    May 25, 2021 at 15:39
  • @Zarko LOL :-) ahahahh. And yet I not remember of a new recent package for the brackets that I have not download :-)))))))))))))))))))).
    – Sebastiano
    May 25, 2021 at 15:41
  • 1
    The package indeed seems very interesting ;-) I found at least one or two constructions that I had hard time setting correctly ! May 25, 2021 at 15:46
1

You can use the \DeclarePairedDelimiterXPP from math tools to define norme. It defines a star version, which is equivalent to a pair of implicit \left … \right in front of the delimiters, or use an optional argument among \big, \Big, \bigg, \Bigg, which is equivalent to a pair of \bigl … \bigr, &c.

\documentclass{article}
\usepackage{mathtools}
\usepackage{esvect}

\DeclarePairedDelimiterXPP\norme[1]{}\lVert\rVert{_p}{#1}

\begin{document}


\begin{equation*}
  \norme*{u}^2, \norme*{\vv{u}}^2, \norme*{AB}^2, \norme*{\vv{AB}}^2.
\end{equation*}

\begin{equation*}
  \norme*{u}^2, \norme*{\vv{u}}^2, \norme*{AB}^2, \norme[\big]{\vv{AB}}^2.
\end{equation*}

\end{document} 

enter image description here

3
  • This isn't really as flexible as the one the OP is using, in the version generated by DeclareP... the p is fixed. One cannot easily switch to q. That said, I'd used this one as well.
    – daleif
    May 25, 2021 at 18:14
  • @daleif: Maybe it might be done using xparse, but I didn't have time to test. Anyway, I think most of the time, only a small set of indices it used, so it is as simple to define a \pnorm, a\qnorm, and so on.
    – Bernard
    May 25, 2021 at 18:21
  • I agree, it isn't really worth using an extra optional argument for
    – daleif
    May 25, 2021 at 18:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .