# Change \newcommand behaviour based on the environment

I'd like to define a command \Lm, such that if used in a maths environment it is replaced with \mathcal{L}, but when used outside of the maths environment it would be replaced with $\mathcal{L}$. This would allow me to write both a sentence like this:

$\langle \Lm, \R \rangle$ is a \emph{deductive system}
consisting of a language \Lm and a set of inference rules \R;



• I'd recommend writing consisting of a language $\Lm$ and .... The symbol is math, after all; you gain little in not properly segregating math as math. – egreg May 23 '13 at 14:38

\newcommand{\Lm}{\ensuremath{\mathcal{L}}}