13

I want to use \lVert and \rVert to denote the vector norm. "Testing ||x||." in CM

With Computer Modern this works quite fine. But when trying to use Iwona as a math font, I run into trouble:

\documentclass{standalone}
\usepackage[math]{iwona}
\usepackage{mathtools}
\DeclarePairedDelimiter\norm{\lVert}{\rVert}
\begin{document}
Testing $\norm{x}$.
\end{document}

"Testing x." in Iwona

I never had any problems using Iwona as a math font, even with much more exotic symbols. I'm a bit surprised this occurs at this point and of course I'd like to know how to fix it.

Christian
  • 19,238

2 Answers2

16

For very strange reasons, the slot "6B in the font sy-iwona is empty. The \lVert and \rVert commands point to that slot, so you can't see any symbol because it's not there to begin with. The definition of \lVert and \rVert given by amsmath are

\DeclareMathDelimiter{\lVert}
  {\mathopen}{symbols}{"6B}{largesymbols}{"0D}
\DeclareMathDelimiter{\rVert}
  {\mathclose}{symbols}{"6B}{largesymbols}{"0D}

which mean: in normal size take the character living in the symbol font in slot "6B while for bigger sizes take the character living in the largesymbols font in slot "0D. The difference between the two is that the former is given \mathopen type, the latter is \mathclose.

Indeed

$\norm[\big]{x}$

works, because the bigger delimiter is found.

enter image description here

There's not so much to do except taking the symbol from another font, for instance

\documentclass[border=4]{standalone}
\usepackage[math]{iwona}
\usepackage{mathtools}

\DeclareSymbolFont{extrasymbols}{OMS}{cmsy}{m}{n}
\DeclareMathDelimiter{\lVert}
  {\mathopen}{extrasymbols}{"6B}{largesymbols}{"0D}
\DeclareMathDelimiter{\rVert}
  {\mathclose}{extrasymbols}{"6B}{largesymbols}{"0D}

\DeclarePairedDelimiter\norm{\lVert}{\rVert}
\begin{document}
Testing $\norm{x}$.

Testing $\norm[\big]{x}$.
\end{document}

enter image description here

Unfortunately, a compatible candidate would be Kurier, which also lacks the symbol.

A different solution, that doesn't require a substitute font, is to emulate the symbol at the size it's missing.

\documentclass[border=4]{standalone}
\usepackage[math]{iwona}
\usepackage{mathtools}
\usepackage{xparse}

\DeclarePairedDelimiter\xnorm{\lVert}{\rVert}
\NewDocumentCommand{\norm}{som}
 {\IfBooleanTF{#1}
   {\xnorm*{#3}}
   {\IfNoValueTF{#2}
     {\mathopen{|\mkern-.8mu|}#3\mathclose{|\mkern-.8mu|}}
     {\xnorm[#2]{#3}}%
   }
 }


\begin{document}
Testing $\norm{x}$.

Testing $\norm[\big]{x}$.
\end{document}

The \norm symbol does like xnorm unless it has no optional argument, in which case the two bars are produced from the single bar.

enter image description here

If you want a definition that works without doing the hack when the bug is fixed, you can do like this:

\documentclass[border=4]{standalone}
\usepackage[math]{iwona}
\usepackage{mathtools}
\usepackage{xparse}

\makeatletter
\AtBeginDocument{%
  \check@mathfonts
  \iffontchar\textfont2 "6B
    \DeclarePairedDelimiter\norm{\lVert}{\rVert}
  \else
    \DeclarePairedDelimiter\xnorm{\lVert}{\rVert}
    \NewDocumentCommand{\norm}{som}
     {\IfBooleanTF{#1}
       {\xnorm*{#3}}
         {\IfNoValueTF{#2}
           {\mathopen{|\mkern-1mu|}#3\mathclose{|\mkern-1mu|}}
           {\xnorm[#2]{#3}}%
       }%
    }
  \fi
}
\makeatother

\begin{document}
Testing $\norm{x}$.

Testing $\norm[\big]{x}$.

\end{document}

It works with all fonts so long as they don't use bizarre slots for the double vertical bar. It will define \norm in the easier way if the character exists, otherwise it will do the hack.

egreg
  • 1,121,712
  • I think .8mu is a tiny bit too wide, 1mu works better for me but other than that, this is an ingenious hack :) – Christian May 17 '13 at 20:16
  • 1
    @Christian Maybe you're right. I added a better hack that will use the correct glyph once the bug is fixed. – egreg May 17 '13 at 20:34
4

EDIT for left/right. While David Carlisle points out that my solution does not work for vertically scaled \left \right syntax, the \stretchleftright{}{}{} syntax of the scalerel package takes care of it.

\documentclass{standalone}
\usepackage[math]{iwona}
\usepackage{mathtools}
\usepackage{scalerel}
\DeclarePairedDelimiter\norm{\lVert}{\rVert}
\def\lVert{\mid\!\mid}
\def\rVert{\mid\!\mid}
\begin{document}
Testing $\norm{x}$.
Testing $\norm{\frac{x}{y}}$.
Testing $\stretchleftright{\lVert}{\frac{x}{y}}{\rVert}$.
\end{document}

enter image description here