12

Problem

For some reason, \nsim looks like a negated bold version of \sim, while I would expect it to look exactly like \sim with a slash on top of it.


Examples

This seems to happen with mathdesign:

\documentclass{article}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage[charter]{mathdesign}
\begin{document}
\begin{center}
\scalebox{10}{%
$\sim$
$\nsim$
\makebox[0pt][l]{$\nsim$}%
\color{red}$\sim$%
}
\end{center}
\end{document}

It looks like this (note that \nsim is thicker than \sim; it is easiest to see when we overlay a red \sim on top of a black \nsim):

mathdesign

And it also seems to happen with amssymb:

\documentclass{article}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{amssymb}
\begin{document}
\begin{center}
\scalebox{10}{%
$\sim$
$\nsim$
\makebox[0pt][l]{$\nsim$}%
\color{red}$\sim$%
}
\end{center}
\end{document}

It looks like this (again black \nsim is visible under red \sim):

amssymb


Questions

  1. Why does this happen? Isn't \nsim supposed to be a negated \sim?

  2. How can I construct with \usepackage[charter]{mathdesign} a symbol that looks like a negated version of \sim? (Something like \not\sim is ugly.)

Jukka Suomela
  • 20,795
  • 13
  • 74
  • 91

3 Answers3

9

It seems that it depends on the font — the \nsim glyph is a different glyph and not made by composition (which, with the default fonts for article class, comes out quite ugly):

\documentclass{article}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{amssymb}
\begin{document}
\begin{center}
\scalebox{10}{%
$\sim$
$\nsim$
\makebox[0pt][l]{$\nsim$}%
\color{red}$\sim$%
}

\scalebox{10}{% $\sim$ $\not\sim$ \makebox[0pt][l]{$\not\sim$}% \color{red}$\sim$% } \end{center} \end{document}

enter image description here

With stix2 fonts things are (in my opinion) much better:

\documentclass{article}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{stix2}
\begin{document}
\begin{center}
\scalebox{10}{%
$\sim$
$\nsim$
\makebox[0pt][l]{$\nsim$}%
\color{red}$\sim$%
}

\scalebox{10}{% $\sim$ $\not\sim$ \makebox[0pt][l]{$\not\sim$}% \color{red}$\sim$% } \end{center} \end{document}

enter image description here

...and looking at the example, I think that amssymb is using the stix glyph under the hood...

Rmano
  • 40,848
  • 3
  • 64
  • 125
  • Sorry, \documentclass wasn't visible as I had a mistake with Markdown, now fixed, yes, it was article. – Jukka Suomela Nov 21 '20 at 19:33
  • 3
    Since amssymb predates stix by decades, it's highly unlikely that the stix glyph is used under the hood in the former. (You're certainly correct that more care should have been taken in making sure the negated symbol was different in only the negation.) – barbara beeton Nov 22 '20 at 02:04
  • @barbarabeeton so probably it was the other way around... ;-) – Rmano Nov 22 '20 at 09:55
4

With amssymb, the \thicksim and \nsim are a pair, but \sim and \nsim are not. To get more consistent output, you can redefine \sim to \thicksim by \let\sim\thicksim.

\documentclass{article}
\usepackage{amssymb}
\usepackage{tikz}

\begin{document} \begin{tikzpicture}[blend group=screen, scale=10, every node/.style={scale=10}] \node[red] {$\sim$}; \node[blue] {$\nsim$};

\begin{scope}[xshift=10pt] \node[red] {$\thicksim$}; \node[blue] {$\nsim$}; \end{scope} \end{tikzpicture} \end{document}

enter image description here

Related implementations:

% latex2e kernel
\DeclareSymbolFont{symbols} {OMS}{cmsy}{m}{n}
\DeclareMathSymbol{\sim}      {\mathrel}{symbols}{"18}

% amsfonts.sty \DeclareSymbolFont{AMSb} {U}{msb}{m}{n} % amssymb.sty \DeclareMathSymbol{\thicksim} {\mathrel}{AMSb}{"73} \DeclareMathSymbol{\nsim} {\mathrel}{AMSb}{"1C}

muzimuzhi Z
  • 26,474
2

Since the issue seems to be with the definition of \nsim, I suggest you redefine it:

\makeatletter
\renewcommand{\nsim}{\mathrel{\mathpalette\n@sim\relax}}
\newcommand{\n@sim}[2]{%
  \ooalign{%
    $\m@th#1\sim$\cr
    \hidewidth$\m@th#1\rotatebox[origin=c]{50}{$#1-$}$\hidewidth\cr
  }%
}
\makeatother

For users unfamiliar with \mathpalette: The mysteries of \mathpalette

For general advice on designing your own symbols: How do you make your own symbol when Detexify fails?

For additional details regarding \ooalign: https://tex.stackexchange.com/a/22375/125871

To use the above code, the call $a\nsim b_{a\nsim b_{a\nsim b}}$ produces the output enter image description here

Since the original \sim command is used to redefine \nsim, the thickness is equal:

enter image description here

Using mathdesign: enter image description here

enter image description here

Sandy G
  • 42,558
  • Thanks, this is great! With mathdesign I decided to use 60 instead of 50 in \rotatebox, but other than that, this worked flawlessly and looks very good to me! – Jukka Suomela Dec 05 '20 at 12:45