0

For example:

\documentclass{article}

\usepackage[svgnames]{xcolor}

\begin{document}

\colorbox{Gainsboro}{sdfASDF}

$\times$

\end{document}

Here, \colorbox{Gainsboro}{sdfASDF} doesn't need to be enclosed with $. But \times needs to be enclosed with $ like $\times$.

Why do some commands need to be in math mode while other commands do not?

  • 1
    The $ puts Latex in math mode. \times is a macro that only works in math mode. – Jesse op den Brouw Sep 1 '18 at 10:00
  • @JesseopdenBrouw So, is it true that all math commands need $ and all non math commands do not need any enclosing? – vasili111 Sep 1 '18 at 10:05
  • 3
    they do not need $ but they need to be in math mode, so for example \begin{equation} a \times b \end{equation} works without $ as equation is a math environment. – David Carlisle Sep 1 '18 at 10:12
  • 3
    sorry I can not guess what you mean by that last comment, but I suggest that you start by reading a basic latex tutorial, asking a question about each separate symbol in the language isn't a good way to get an over-view of how the language works. – David Carlisle Sep 1 '18 at 10:17
  • 1
    I think you would start to make rapid progress if you changed the title of your query from "Why some commands need to be enclosed with $ and why some commands don't need?" to "Why do some commands need to be in math mode while other commands do not?" This change would help you focus on the two fundamental modes TeX can be in: math mode and text mode. Some commands (not all that many, actually) can be run in both text and math mode. Most commands, in contrast, require TeX to be either in math mode (including \times, \sum, and \int) or in text mode (e.g., \section and \tiny). – Mico Sep 1 '18 at 11:26

Your Answer

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

Browse other questions tagged or ask your own question.