I'm interested in writing a command which would result in output that varies when called within $...$ tags and when called within, say, displaymath environment.

For instance, assume that I want to define \xnorm command which works as


when called in the inline mode and which works as


when called in the "usual" math mode. How to achieve this?

I know that there exists a control sequence like ifmmode, but it tests whether I am in any type of math mode. Are there any more specific control sequences? Or, is there any other solution?

Question answered. The goal can be achieved with \mathchoice command. An example code snippet can be found below, in the answers to this post. Thanks all very much.

Nevertheless, it is worth a warning to others who have ideas similar to mine that math layout generated by \mathchoice can differ with the original one.

For example, try the following two functions:




(the first argument of \mathchoice provides a definition for "usual" math mode, other arguments do not play role in this example).

Now, simply try

\xnorma{x^2}^2 \xnormb{x^2}^2

A difference will be visible.

  • Welcome to TeX.SX. tex.stackexchange.com/questions/1223/… is probably of interest. Commented Dec 13, 2013 at 17:23
  • Do you want to create a set of norm "fences" that are always small when used in inline-math mode, but are allowed to grow in size as needed in display-math mode?
    – Mico
    Commented Dec 13, 2013 at 17:39
  • 1
    Not exactly. My editorial problem was the following. In inline mode, I usually use very short pieces of math (as everyone), e.g. a norm of vector v. In display mode, more complex expressions with norms appear, e.g. a product of norms of, say, five subexpressions with different size. If the size of each norm "fence" was adapted to height of the contained subexpression, then I would obtain a line of norm "fences" of significantly varying heights, what doesn't look good. Therefore, my idea was to fix the height of norm "fences" in display mode to some compromise height.
    – Gregory
    Commented Dec 13, 2013 at 20:44
  • Thanks for providing this additional information. I'd say @egreg's solution should be more or less what you need.
    – Mico
    Commented Dec 13, 2013 at 20:47

1 Answer 1


I don't think you really wants this. However, here it is:



A norm in text mode is $\xnorm{v}$, while in display math it is
\xnorm{v}=\sum_{i=1}^n\lvert v_i\rvert

The result is really ugly (and wrong):

enter image description here

If you change \Bigl and \Bigr with \bigl and \bigr you get a more acceptable result, but I can't see the point of increasing the fences' size.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .