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 know how to write either of those behaviours separately: \newcommand{\Lm}{$\mathcal{L}$}, \newcommand{\Lm}{\mathcal{L}}, but I'm not sure if there is a way to decide which one to use based on the environment I'm in.

  • 4
    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

For this specific problem, you can define your command as


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.