TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Welcome to TeX.SX. tex.stackexchange.com/questions/1223/… is probably of interest. – Torbjørn T. Dec 13 '13 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 Dec 13 '13 at 17:39
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 Dec 13 '13 at 20:44
Thanks for providing this additional information. I'd say @egreg's solution should be more or less what you need. – Mico Dec 13 '13 at 20:47

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

share|improve this answer

Your Answer


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.