Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

$ \mymacro $

should lead to

A

while

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

should produce

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

(without the dots).

share|improve this question
    
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
1  
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

2 Answers 2

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

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

\end{document}
share|improve this answer
    
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!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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