GeneralDifferent command definition in math mode and display mode

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
szymtor
Posts: 2
Joined: Sat Feb 26, 2011 11:02 pm

Different command definition in math mode and display mode

Post by szymtor »

I would like to define a command which displays some formula in a different way,
depending on whether it is used in math mode or in display mode. How do I do that?
Thanks for any suggestions.
Last edited by szymtor on Sun Feb 27, 2011 2:06 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

Different command definition in math mode and display mode

Post by josephwright »

The TeX \mathchoice primitive is the best way to do this:

Code: Select all

\mathchoice{<display mode>}{<text mode>}{<superscript mode>}{<supersuperscript mode>}
Joseph Wright
szymtor
Posts: 2
Joined: Sat Feb 26, 2011 11:02 pm

Re: Different command definition in math mode and display mo

Post by szymtor »

Very cool. Thanks!
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Different command definition in math mode and display mode

Post by localghost »

szymtor wrote:Very cool. […]
Then please mark the topic (not the last post) accordingly as written in Section 3 of the Board Rules (to be read before posting).


Best regards and welcome to the board
Thorsten
Post Reply