I need to put stellar mass data in units of Solar Mass, and I tried the M_{\odot}, but the console shows:
! missing $ inserted error.
I don't know what is wrong. Please help me out
I need to put stellar mass data in units of Solar Mass, and I tried the M_{\odot}, but the console shows:
! missing $ inserted error.
I don't know what is wrong. Please help me out
TeX complains with missing $ inserted because of the underscore. _ is a special character dedicated for subscripts, which require math mode.
My first example is all math mode, the second one is typesetting the M in upright text mode, the third uses text mode for the subscript. Choose for yourself whether the solar mass should be typeset in math italic—as a variable—or upright—as having a defined meaning.
\documentclass{article}
\begin{document}
(M_\odot)
or
(\textup{M}_\odot)
or
M\textsubscript{(\odot)}
\end{document}
_ as active character is misleading. TeX reserves this name to chars with category code 13. The underscore is a subscript character (category code 8). In your answer I would rather use "special character" to avoid issues.
– campa
Dec 05 '20 at 09:23
In Unicode, the symbol you want is U+2609, and can be loaded from any font that contains it using fontspec. Here is an example using DejaVu Sans, and the output with LuaLaTeX.
\documentclass{article}
\tracinglostchars=2
\usepackage{fontspec}
\newfontfamily\symbolfont{DejaVu Sans}[Scale=MatchUppercase]
\newcommand\astrosun{{\symbolfont\symbol{"2609}}}
\newcommand\solarmass{\ensuremath{\mathrm{M}_{\textnormal{\astrosun}}}}
\pagestyle{empty} % Suppress page numbering.
\begin{document}
Solar mass is denoted {\solarmass}.
\end{document}
wasysympackage and\astrosun– samcarter_is_at_topanswers.xyz May 16 '17 at 13:05