I would like to write strings that contain asterisks, but LaTeX sees the asterisks as infix operators and surrounds them with spaces. How can I switch this off?
\[
aaa*aaa*aaa
\]
Should look like
\[
aaa\!*\!aaa\!*\!aaa
\]
If you never need *
as an infix binary operator, you can change its math code:
\documentclass{article}
\usepackage{amsmath}
\mathcode`*=\numexpr\mathcode`*-"2000\relax
\begin{document}
\[
aaa*aaa*aaa
\]
\end{document}
If it is for a one-off case,
\[
aaa{*}aaa{*}aaa
\]
would do.
$aaa{*}aaa{*}aaa$
if the objective is to print the string as is? By default, TeX places\medmuskip
between items of themathord
andmathbin
; using\!
removes only\thinmuskip
, not\medmuskip
.*
symbol the only one that's causing trouble, or are there other symbols of type mathbin or mathrel inside the strings that need to be printed "as is"?