3

I'm having the following code:

\documentclass[11pt]{article}
\usepackage{amssymb,amsthm,amsmath}
\newcommand{\norm}[1]{\lVert #1 \rVert_2}

\begin{document}
\begin{displaymath}
\norm{\cdot}=...
\end{displaymath}
\end{document}

I'd like to add a little space before and after the dot in the norm, because it's a bit crushed between the vertical lines now. Is there a command with the same output as \cdot that does this automatically or should I insert the spacing manually (with ~ for example) each time?

Jeroen
  • 4,491

2 Answers2

7

I would go even further than Mico, why not embed the empty arg marker into the macro it self.

\documentclass[a4paper]{memoir}
\usepackage{mathtools,etoolbox,amssymb}
\newcommand\emptyarg{{}\cdot{}}
\DeclarePairedDelimiterX\norm[1]\lVert\rVert{
  \ifblank{#1}{\emptyarg}{#1}
}
\begin{document}
\[
\norm{}: A \to B \qquad \norm{X}
\]
\end{document}

BTW: on CTAN the latest mathtools version now contain a tool to build the L^2 norm, such that one does not have to add the _2 manually all the time.

daleif
  • 54,450
6

You could define a new macro named, say, "\widecdot", that surrounds \cdot with thinspace (\,) on either side. Note: I wouldn't redefine \cdot directly, as this macro tends to be used internally by other macros as well.

Incidentally, your definition of \norm is a bit suboptimal since subscripts -- such as the 2 in your example -- aren't set quite low enough. It may be preferable to use the macro \DeclarePairedDelimiter of the mathtools package; compare the output of the \norm and \Norm macros in the second equation below.

enter image description here

\documentclass[11pt]{article}
\usepackage{amssymb,mathtools}
\newcommand{\norm}[1]{\lVert #1 \rVert_2}
\DeclarePairedDelimiter{\Norm}{\lVert}{\rVert}
\newcommand\widecdot{\,\cdot\,}
\begin{document}
\[ \norm{\cdot} \text{ vs.\ } \norm{\widecdot}\]

\[ \norm{\widecdot}\text{ vs.\ } \Norm{\widecdot}_2 \]
\end{document}
Mico
  • 506,678
  • That's odd I event even thought there was a placement different between the two. Seems I got lucky ;-) – daleif May 25 '14 at 21:08
  • @daleif - I think the OP's definition of \norm generates the insufficiently-low subscript issue because it doesn't use \left and \right (or equivalent). Hence TeX doesn't "know" that the 2 subscript should be typeset a bit lower than usual as it follows a glyph (\Vert) that has a descender component. – Mico May 25 '14 at 21:34
  • But should it know from the fact what we are using \rVert that ought to to mark it as a closing fence. The only thing extra that mathtools do is to wrap it explicitly in a \mathclose. – daleif May 25 '14 at 22:15
  • @daleif - I think the use of the explicit \mathclose directive is the key. Compare the looks of \lVert a\rVert_2 and \mathopen{\lVert} a\mathclose{\rVert}_2, in either inline or display-style math mode: Without the explicit \mathclose directive, the subscript is positioned without regard to the size of the preceding symbol. This holds for other fence symbols too, such as ), ], and \}... – Mico May 25 '14 at 23:01
  • @daleif it is not the \mathclose as you can test with \mathopen\lVert a\mathclose\rVert_2 but the braces (which create a sub-formula) as you can test with {\lVert} a{\rVert}_2. Try also {\lVert a\rVert}_2. –  May 26 '14 at 06:58
  • So basically for an unscaled fence a subscript is generally placed a bit too cramped. – daleif May 26 '14 at 08:29
  • @daleif - I've discovered yet another wrinkle to this story: the "cramped" look of the subscript next to a math fence which hasn't been given an explicit \mathclose wrapper turns out to be specific to pdfLaTeX. In contrast, in LuaLaTeX (with the unicode-math package loaded), in such a situation the lower edge of the subscript ends up being typeset flush with the lower edge of the fence; this actually looks quite good to me. One could even argue that the subscript ends up being placed too low in LuaLaTeX if the closing fence has been wrapped in \mathclose. – Mico May 26 '14 at 09:54
  • Thanks a lot for your remark about the norms. It looks a lot better now. Big vote up! – Jeroen Jun 07 '14 at 18:35