TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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. – Harald Hanche-Olsen 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. – Harald Hanche-Olsen 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
up vote 5 down vote accepted


{\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.)

share|improve this answer
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. – Harald Hanche-Olsen 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

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

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.

share|improve this answer
(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 posting your answer, you agree to the privacy policy and terms of service.

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