5

New bye here, I have a situation to solve, with two different behaviors of the tilde. The first looks normal, within a regular text, something like:

... some text $\sim$A then some text ...

but in equation mode (or even inside the equation dollar signs within the text), there is a space between the tilde and the letter (see the screenshot below):

... some text $\sim{A}$ then some text ...

enter image description here

Is there a way to eliminate that space, in equation mode?

I need it for equations mode:

\[ \sim{A} = ... \]

If relevant, in the preamble I use the package lmodern to use the CM10 font., plus some others dealing with equations: mathptmx, amssymb, amsmath, mathspec and parse the text with xelatex.

10

The default "math type" of \sim is mathrel, i.e., that of a relational operator. (Another example of an operator of type mathrel is =.) The default math type of the letter A is mathord ("math ordinary"). As you've "discovered", TeX automatically inserts some whitespace -- in the amount of \thickmuskip -- between elements of types mathrel and mathord, respectively.

If you do not wish to get whitespace between \sim and A, simply write

{\sim}A

This setup changes the math type of \sim to mathord, and TeX does not insert extra whitespace between elements of type mathord.

6

Usually \sim is a relation like =. So the space is wanted:

\documentclass{article}

\usepackage{lmodern}
\usepackage{amsmath}

\begin{document}
\[ A = B \]
\[ A \sim B \]
\end{document}

\sim relation

But you could also define it as an ordinary symbol:

\documentclass{article}

\usepackage{lmodern}
\usepackage{amsmath}
\mathchardef\simsym"0218
\begin{document}
\[ A \sim B \]
\[ A \simsym B \]
\end{document}

sim ordinary

For more information about math classes see, e.g., TeX by Topic section 38.3 and 23.3.

Instead of using \mathchardef you could also use

\newcommand*{\simsym}{\mathord\sim}

to define \simsym as the ordinary symbol variant of \sim:

\documentclass{article}

\usepackage{lmodern}
\usepackage{amsmath}
\newcommand*{\simsym}{\mathord\sim}
\begin{document}
\[ A \sim B \]
\[ A \simsym B \]
\end{document}

The result is exactly the same as above and would be the same like with

\documentclass{article}

\usepackage{lmodern}
\usepackage{amsmath}
\newcommand*{\simsym}{{\sim}}% note the extra {…}
\begin{document}
\[ A \sim B \]
\[ A \simsym B \]
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.