How would you implement the "catcode" solution here for superscripts? Thanks


The code below reproduces the error (complied using XeLaTeX). Works if the following two lines are commented out:

\newcommand^[1]{\ensuremath{\sp{\scriptscriptstyle #1}}}

Full code:


\newcommand_[1]{\ensuremath{\sb{\scriptscriptstyle #1}}}

\newcommand^[1]{\ensuremath{\sp{\scriptscriptstyle #1}}}




\section{Set up}

\int_{n-1}^{n}c_{n}dt & =x\left(i,n\right)\\
\implies c_{n} & =x\left(i,n\right)

  • 1
    just copy the code replacing _ by ^ and \sb by \sp – David Carlisle Jan 30 '18 at 1:49
  • Thanks, David. I did that, but it didn't work for some reason. \catcode`^=\active \newcommand^[1]{\ensuremath{\sp{\scriptscriptstyle #1}}} – gsab Jan 30 '18 at 1:53
  • 2
    if you want help with an error message the question is always clearer if it includes a complete test document that produces the error and the exact error message you got. "did not work" is hard to debug. – David Carlisle Jan 30 '18 at 1:57
  • 1
    What's the error message? – cfr Jan 30 '18 at 2:19
  • ! Missing number, treated as zero. <to be read again> \protect l.1455 \XC@catcodes – gsab Jan 30 '18 at 2:24

The error comes because you're changing category codes before TeX processes certain files that don't expect those category codes:

\newcommand^[1]{\ensuremath{\sp{\scriptscriptstyle #1}}}


This means that xcolor.sty is processed with the new catcode for ^ (not something it is prepared for), which can lead to undesirable results. Similar problems with having this redefinition before \usepackage{xunicode}.

Move these \catcode-changing lines to after all external files have been loaded. Say, just before or after \begin{document}. Then the error goes away.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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