Why the following code gives me the following error?


\begingroup \catcode`\"=12
    \ifnum\mathcode`\-=45 \else




tex error       > error on line 13 in file /Users/maggyero/Desktop/test.tex: ! Extended mathchar used as mathchar (4203026)
<to be read again> 
\newmcodes ...thcode `\."613A\ifnum \mathcode `\-=
                                                  45 \else \mathchardef \std...
<argument> \newmcodes @
             \kern \zeropoint \mfunction {fancy-function-name'*.:}
\486>nolop #1->\mathop {#1
l.13 $\xyz

Thank you in advance.

  • 1
    In any case the @ is not a letter, so \newmcodes @ are two tokens, and the same for \std @minus. You should add \unprotect and \protect before that code using @ in control sequences. – Manuel May 5 '15 at 12:18
  • I have to wonder what you are up to here: based on egreg's comment on his answer, you seem to have copy-pasted some of the amsmath code for LaTeX into ConTeXt! – Joseph Wright May 5 '15 at 14:30
  • @JosephWright I think I saw a previows question, he's trying to replicate the behaviour of \DeclareMathOperator if I'm not mistaken. – Manuel May 5 '15 at 16:47
  • @Manuel: Exactly, it's copied from amsopn.sty to replicate the behaviour of \DeclareMathOperator. – Maggyero May 7 '15 at 22:05

You shouldn't use @ in command names, when using ConTeXt; but you should be aware of the fact that ConTeXt uses Unicode math, so the standard math code of the hyphen cannot be accessed to with \mathcode.

  \catcode`\"=12 \catcode`\`=12 % added a safe setting for the backquote
  \ifnum\Umathcodenum`\-=4203026 \else

\definemathcommand[xyz][nolop]{\begingroup % added a grouping


I also added a safe setting for the backquote and grouping around the call of \newmcodes.

enter image description here

  • Code for the error is part of luatex.org/svn/tags/beta-0.76.0/source/texk/web2c/luatexdir/tex/…. Perhaps worth noting in the question that with LuaTeX/XeTeX the relationship \mathcode/\mathchardef/\Umathcode/... is complex (and could I guess still be revised somewhat). – Joseph Wright May 5 '15 at 12:27
  • The code is written in uselessly compressed way which complicates reading for humans. It is much more better to write \mathcode`\'=39 \mathcode`\*=42 than \mathcode`\'39\mathcode`\*42. Or instead \Umathcharnumdef\stdminus\Umathcodenum`\-\relax would be better to write \Umathcharnumdef\stdminus=\Umathcodenum`\-. And the percent at the end of line two causes that the expanding of \ifnum is done before previous \mathcode is assigned. – wipet May 5 '15 at 13:37
  • @wipet You're right about the %, which I didn't notice in the original code`; I kept the OP's style with regard to assignments. – egreg May 5 '15 at 13:38
  • Yes, this is OP's style. But we can notice that this is not a good style. – wipet May 5 '15 at 13:39
  • 1
    @JosephWright It's copied from amsopn.sty; the code even has the improper % (which does no real harm in this case). – egreg May 5 '15 at 14:11

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.