# Different symbols in $…$ and align environments

Is there a way to force LaTeX to produce different symbols either in $...$ or \begin{align}...\end{align} environments? For example

$\mymacro$


A

while

\begin{align} \mymacro \end{align}


should produce

B ............................................................ (1)

(without the dots).

-
Could you explain the wider context here? This seems like a very strange request at first sight. –  Joseph Wright Dec 1 '11 at 10:08
For example: decide when to use \nicefrac () or \frac (align), or when to use subscripts and superscripts like \limits does it or when to use less space () or more space (align) in general. –  John Dec 1 '11 at 11:04
Manuals of style usually don't recommend \nicefrac in mathematical papers. You don't have to think to align, in general, but to "display" and "text" math styles, as Joseph suggested. Why don't you give some examples? Edit your question to include them. –  egreg Dec 1 '11 at 11:40

\documentclass{article}
\usepackage{amsmath}
\makeatletter
\def\mymacro{\ifinalign@ B\else A\fi}
\makeatother
\begin{document}

$\mymacro$
\begin{align} \mymacro \end{align}

\end{document}

-
Works, thanks ! –  John Dec 1 '11 at 11:05

It sounds as if you want to detect not a particular environment but the current math style. The \mathchoice primitive is appropriate here:

\documentclass{article}
\usepackage{amsmath}
\newcommand*{\mymacro}{\mathchoice{A}{B}{C}{D}}

\begin{document}

$\mymacro_{\mymacro}$
\begin{align} \mymacro \end{align}

$\mymacro$

\end{document}


The four cases are display style, text style, subscript style and subsubscript style. For the demo, they are all entirely different but in a real case would be in some way related!

-