0

For example, I do not know the definition of the LaTeX command \ensuremath. Where can I get its accurate meaning? Is there one professional website to offer some information about this?

Werner
  • 603,163
  • 1
    Welcome to TeX.SX! What about https://en.wikibooks.org/wiki/LaTeX? There might be a huge amount of sites, of course. –  Jul 23 '15 at 16:30
  • I frequently just search for the command - e.g. Google latex ensuremath - and pick a link that I think will give me an explanation at the level I want. – Ethan Bolker Jul 23 '15 at 16:50

1 Answers1

1

The best source for definitions and meanings of LaTeX sources is source2e. Specifically for \ensuremath, it states

In math mode, \ensuremath{text} is equivalent to text; in LR or paragraph mode, it is equivalent to $text$. \relax is not needed in front of the \ifmmode as \protect will be \let to \relax. This version (due to Donald Arseneau) avoids duplicating its argument in the ‘then’ and ‘else’ part of the \ifmath which is necessary in nested ‘tabular’ like environments. See amslatex/2104.

305 \DeclareRobustCommand{\ensuremath}{%
306   \ifmmode
307     \expandafter\@firstofone
308   \else
309     \expandafter\@ensuredmath
310   \fi}

Then there are also numerous LaTeX Help pages compiled in HTML format. Here's the specific one related to \ensuremath:

\ensuremath (LaTeX2e)

\ensuremath{Text set in math mode}

The argument of the \ensuremath command is always set in math mode, regardless of the current mode. Note that math mode is not specifically invoked in the argument of the \ensuremath command.

Thus \ensuremath{$\alpha^2+\beta^2$} is not correct. The correct form is \ensuremath{\alpha^2+\beta^2}.

Werner
  • 603,163