12

Is there a way to get the superscript math mode behavior without using ^?

By way of background: I work at a large school that has a large web site that occasionally has math content on pages. I recently convinced the powers that be to start using MathJax to render all of the math content, but they have encountered a hitch. There is a collection of pages that is processed by complicated subsystems in an automated way, and I'm told that the ^ character is a control character at some stage(s).

So either they have to work around that, or I could start communicating the math without using ^ symbol. (I understand that I may still have a MathJax issue to move on to, but my issue starts with this LaTeX question.)

Mico
  • 506,678
alex.jordan
  • 2,179
  • 2
    Is this a LaTeX question? MathJax questions are off-topic –  May 21 '15 at 21:03
  • 3
    In (La)TeX it's possible to use \sp instead of ^ for exponents; it doesn't seem possible in MathJax. Nothing can be done other than making a feature request to the developers. However, I have tried $\def\sp{^}a\sp{b}$ on a page where MathJax is used and it appears to work, so it may be possible to add \def\sp{^} to some initialization file. – egreg May 21 '15 at 21:06
  • 1
    @ChristianHupfer But mathjax is a recognized tag at this site, as you can see. So is that really true? In any case, it is not necessarily a MathJax question. If there exists a LaTeX command like, say, \mathsuperscript{}, then that would answer my question here. I'd move on to see if MathJAx supports it. – alex.jordan May 21 '15 at 21:13
  • 2
    @alex.jordan: MathJax uses the same syntax (or supports at least some commands) as (La)TeX, but the engine behind it is different. –  May 21 '15 at 21:16
  • 1
    you could do \newcommand\sp[1]{^{#1}} to define \sp in mathjax (or use another name, as the behaviour is slightly different. – David Carlisle May 21 '15 at 23:18
  • ^ as a control character…I feel a little hypocritical for saying this, but that's abhorrent. – Sean Allred May 22 '15 at 00:55
  • 2
    If your page is pre-processed before being sent to the browser, you might be able to use ^ in place of the ^ (either in your math expressions, or in the definition of \sp) in order to get past the pre-processing of ^. This is will be converted to the circumflex by the browser, but is not a literal ^ in the source file. – Davide Cervone May 22 '15 at 10:25
  • I tried \sp and \sb in place of ^ and _ in a LaTex \documentclass{article} file and they worked. But in MathJax via StackExchange Physics, it won't typeset e.g. $a = x\sp2$ or $y = cx\sb6$. – Leon Chang Nov 25 '23 at 04:56

1 Answers1

19

in latex.ltx there is a line

\let\sp=^

so there is an alternate command, \sp, that will produce a superscript.

@egreg notes in a comment that this isn't available for mathjax, so it's apparently not "portable". however, david cervone (mathjax lead developer) says that

MathJax does handle \let\sp=^ [...]. MathJax's \let only works to set a control sequence name, not another character, so you can't do \let!=^, for example, but setting \sp would certainly work.

this command is inherited from plain.tex. in the texbook (p.135)

\danger If for some reason you cannot use ^ and _ for superscripts and subscripts, because you have an unusual keyboard or because you need ^ for French accents or something, plain TeX lets you type \sp and \sb instead. For example, $x\sp2$ is another way to get x2. On the other hand, some people are lucky enough to have keyboards that contain additional symbols besides those of standard ASCII.

  • 1
    Why is the macro named \sp? \stackpowers? –  May 21 '15 at 21:09
  • 3
    @ChristianHupfer \let\sb=_ is the analog: SuPerscript and SuBscript. – egreg May 21 '15 at 21:10
  • 2
    @ChristianHupfer -- shorthand defined by knuth. this line in plain.tex':\let\sp=^ \let\sb=_`. adding note to answer. – barbara beeton May 21 '15 at 21:12
  • 3
    Can you add the original |verb| to the quote? I was a bit confused reading $x\sp2$ is another way to get $x\sp2$. Or simply leaving out the code-markup for the second instance might do just as fine. – Johannes_B May 21 '15 at 21:40
  • Perhaps extend the answer to mention that any token could be \let to ^, or indeed the \catcode could be set to 7, to achieve the same effect. – Joseph Wright May 22 '15 at 06:55
  • 1
    @ChristianHupfer, MathJax does handle \let\sp=^, so I'm not sure where that claim is coming from. MathJax's \let only works to set a control sequence name, not another character, so you can't do \let!=^, for example, but setting \sp would certainly work. Perhaps that is the source of the claim. – Davide Cervone May 22 '15 at 10:31
  • @DavideCervone: I never denied that. I just stated that the background engine is different –  May 24 '15 at 18:37
  • @ChristianHupfer, sorry, I tagged the wrong user, and didn't notice until after I could no longer edit the comment. It was apparently egreg who made the comment (as noted in Barbara's answer above, though I don't see egreg's original note to that effect). My apologies. – Davide Cervone May 25 '15 at 13:12
  • @DavideCervone: No worries. Such 'errors' happen ;-) –  May 25 '15 at 14:13
  • @DavideCervone -- egreg's comment (that \sb doesn't natively work with mathjax) was the second one posted to the question, not to this answer. (i'm happy to crib useful information from anywhere, provided i have a reasonable feeling that it's accurate. so thanks to you for clarifying that a simple \let will provide the feature.) – barbara beeton May 25 '15 at 14:20
  • @barbarabeeton, thanks for pointing out where the comment came from. I misread the citation to mean that egreg said that your approach with \let wasn't portable. Clearly I wasn't paying enough attention that day! – Davide Cervone May 25 '15 at 21:06