I know this is kind of blasphemic thing to ask, but is there a way to make mathmode obey spaces? Preferably in Plain with XeTeX.

  • Changing the catcode of the space to other or active seems to have no effect. The ignoring of spaces in mathmode might be hardcoded.
    – Martin Scharrer
    Feb 25 '11 at 20:10
  • @Martin: The active space is by default defined to be a space character with catcode 10. Change the definition, and all will be well. See my answer. Feb 25 '11 at 20:22
  • @lockstep: As I don't think the question or any likely answer is likely to be XeTeX related, I don't think the XeTeX tag is appropriate here – even though the OP specified XeTeX. Feb 25 '11 at 20:25
  • Thanks @Harald, I knew about the active space being defined as normal space, but after the other catcode didn't worked as well I just gave up on it.
    – Martin Scharrer
    Feb 25 '11 at 20:25
  • @Harald: This is a close call. On the one hand, I agree that the {xetex} tag should be removed if it turns out that XeTeX has nothing to do with the problem at hand. On the other hand, someone versed in XeTeX (i.e., not me) should decide this -- and the {xetex} tag may call this person's attention to the question at hand.
    – lockstep
    Feb 25 '11 at 20:33


{\catcode`\ =\active\global\let =\ }
\everymath{\catcode`\ =\active}

(The space has mathcode "8000, which is supposed to make it active in math mode. But this is not enough for some reason. You do need the \everymath.)

  • 1
    I should add that all the catcode changing caveats apply here. But you could use this to your advantage: With \def\ism$#1${$#1$} you can do \ism $x = y$ and get your math with spaces ignored as usual. Feb 25 '11 at 20:34

One can use the fact that the space has mathcode "8000, but TeX checks the mathcode only for category 11 or 12 characters:

\def\spacemath{\catcode`\ =12
  \begingroup\lccode`~=` \lowercase{\endgroup\def~}{\ }}

$\spacemath{}a b$

If one wants this in all math, then

  • Any idea why this doesn't work in macros? For example \newcommand{\ff}[2]{\forall {\spacemath{} #1}, #2}
    – Clément
    Jan 16 '16 at 17:05
  • \spacemath does nothing if the argument has already been tokenized.
    – egreg
    Jan 16 '16 at 17:24

I actually managed to somehow accidentally make it work by:

\catcode`\ =13 \def {\space}

after which

$$\def\space{ } meow woof$$ % the thing between the braces is U+A0

much to my surprise, worked.

  • (dodging a bump here) Ofcourse, you'd need a font which has that U+A0 "glyph" to be present.
    – morbusg
    Feb 26 '11 at 21:54

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.