Is it considered bad style to write:

x^2, 2^\frac{1}{2} and 2^\sqrt{2} (without curly brackets around the superscript)

instead of:

x^{2}, 2^{\frac{1}{2}} and 2^{\sqrt{2}}?

The same for subscripts.

  • 7
    Welcome! It is not supported syntax, so it may happen to work but it may not continue to work or work reliably.
    – cfr
    Commented May 29 at 18:34

2 Answers 2

  1. x^2 is mildly bad style: the LaTeX manual always braces superscripts and subscripts also in cases like this.

  2. 2^\frac{1}{2} is bad style and works by chance. See later.

  3. 2^\sqrt{2} is an outright error and, indeed, you get

    ! Missing { inserted.
    <to be read again>
    l.10 $2^\sqrt
    ! Missing } inserted.
    <inserted text>
    l.10 $2^\sqrt{2}$

The output for all three examples is correct, but errors should never be ignored as error recovery attempted by TeX is never guaranteed to produce the expected result.

Why does 2^\frac{1}{2} seem to work? Because \frac{1}{2} ultimately produces {1\over 2}, so the output is correct without errors just because of how \frac is implemented. Luck.

Much similar is the bad habit of typing x_\mathrm{loc}. For instance, if you use unicode-math with the option mathrm=sym, the input $x_\mathrm{loc}$ will raise an error. Conversely, x_\notin will be accepted when unicode-math is used, but explode with pdflatex.

General rule Always brace superscripts and subscripts unless they're simple characters, when braces are optional. So, for instance,

\lim_{x\to 0^+}f(x)

is acceptable. When the superscript or subscript is a single command, it may or may not work without braces (see \notin above). Learn to use braces. And remember that seeing the expected result does not guarantee that the wrong input will work in every circumstance.

  • 3
    I mentioned 2^\sqrt{2} because it works in MathJax, but apparently not in real TeX - exactly what you said in your last sentence. Commented May 29 at 21:07
  • 1
    @DavidScherfgen remember that MathJax has nothing to do with TeX, it is just a JS libary tht can parse some subset of the LaTeX math syntax.
    – daleif
    Commented May 30 at 12:32
  • I wouldn't call it "bad style", but a documented syntax error. Commented May 30 at 22:54

In general it is an error, with numbers even with only numbers of more than two digits it does not work correctly, even with some packages like xfrac (different presentation of fractions) when compiling it generates an error due to the lack of curly braces.


$2^3$ ok

$2^36$ incorrect

$2^{36}$ ok

$2^\frac{1}{2}$ ok

$x^{\sfrac{2}{4}}$ ok 

$x^\sfrac{2}{4}$ fatal error

  • 2
    Could you change parentheses to braces or curly brackets? Parentheses are not the same.
    – cfr
    Commented May 29 at 20:55
  • Just works with {} Commented May 29 at 20:57
  • 6
    Did you mean to edit? Your answer still says it generates an error due to the lack of parentheses but that's not correct. Parentheses are ( and ). {} would be fine as a substitute and probably clearer to non-English speakers anyway, but parentheses is wrong and so confusing.
    – cfr
    Commented May 29 at 23:46
  • Please use the correct term braces. “Curly brackets” is for schoolchildren, and “curly braces” is a pleonasm. Commented May 31 at 6:01
  • 3
    @JohnBentin perhaps you don't know this, but for a decent fraction of the English speaking world, "curly brackets" is the correct term. In British English, {} are called "curly brackets", [] are called "square brackets", and () are called "brackets". The words "braces" and "parentheses" are primarily American English terms, as far as I know.
    – N. Virgo
    Commented May 31 at 7:45

You must log in to answer this question.

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