# Should &nbsp; in LaTeX produce a space? #377

Closed
opened this issue Jan 15, 2013 · 15 comments

Projects
None yet
6 participants
Contributor

### christianp commented Jan 15, 2013

 Is it desired behaviour that an HTML   entity in mathmode LaTeX should produce a space? I don't mind if it does, and you could make a rational argument that when you put   you really mean it, but when writing LaTeX in a WYSIWYG editor like TinyMCE, it replaces repeated spaces with   entitites. It looks to the author like they've just got a couple of spaces in a row, which in normal LaTeX are ignored.
Contributor

### fred-wang commented Jan 15, 2013

 Mmm, maybe we should just add an option to ignore  ... I guess you can do that by modifying the "special" list from jax/input/TeX/jax.js to add the entry NBSP: 'Space'.

### leathrum commented Jan 15, 2013

 My mail reader has been turning your literal "nbsp" entities into spaces, so it took me a while to figure out what you were saying.... Point being, we aren't alone in needing to give this more thought.
Contributor

### fred-wang commented Jan 15, 2013

 Sorry, I think it's my fault I didn't enter the   correctly the first time. I didn't think too hard about that but I guess something like MathJax.InputJax.TeX.Definitions.special["\u00A0"] = 'Space'  after the TeX input Jax is loaded will work. Alternatively, perhaps one can attach a prefilter hook on the TeX input Jax to replace the  's by normal spaces.
Member

### dpvc commented Jan 27, 2013

 Note that the entity will have been converted to U+00A0 when the DOM is created, and MathJax will only see the non-breaking space as a regular character (not an entity), which it (correctly in my opinion) interprets as a space that you really want to be there. So it can't tell the entity from the actual Unicode character, for example. I think Fred's suggestions will work. I was going to recommend a prefilter as well as the most expedient solution.
Contributor

### fred-wang commented Jan 31, 2013

 See http://meta.math.stackexchange.com/questions/8355/invisible-latex-error-mathrmim-left-right-vs-mathrmim-left where the issue seems to happen for 0x200c and 0x200b too. Perhaps we should add a configurable list of characters to interpret as spaces.
Member

### dpvc commented Jan 31, 2013

 This is a different issue. The U+200C and U+200B are being added by the StackExchange comment editing code when a line exceeds 80 characters with no white space. That can occur anywhere in the original TeX code, and in the example given by the OP, it was between \r and ight of the original \right macro. I don't think that it is MathJax's job to try to work around that kind of error. SE could add a prefilter to the TeX input jax that would remove those.
Member

### dpvc commented Jan 31, 2013

 In particular, interpreting U+200C and U+200B as white space would not resolve the problem they are having. They would have to be ignored completely (i.e., removed), since \r ight would still be an error.

### bshska commented Feb 26, 2013

 I have the same problem, could some please explain the solution, where should I put this MathJax.InputJax.TeX.Definitions.special["\u00A0"] = 'Space' in. How can I create a prefilter? Thank you
Contributor

### fred-wang commented Feb 28, 2013

 Not tried, but perhaps after the TeX Jax is ready, by putting this in your x-mathjax-config: MathJax.Hub.Register.StartupHook("TeX Jax Ready ",function () { MathJax.InputJax.TeX.Definitions.special["\u00A0"] = 'Space' });  or MathJax.Hub.Register.StartupHook("TeX Jax Ready ",function () { MathJax.InputJax.TeX.prefilterHooks.Add(function (data) { ... } ); });  Here data contains property data.math, data.display, data.script. I think data.script contains the script tag with the TeX content and you should modify it to replace   by normal space. I'm not really sure, so please try it yourself and give feedback.

### dpvc pushed a commit to dpvc/MathJax that referenced this issue Mar 20, 2013

 Merge remote-tracking branch 'fred/sniffing' into develop 
Resolves issue mathjax#377.
 c2f64e3 
Member

### dpvc commented Mar 20, 2013

 (OOPS, used wrong issue number on that last commit. Argh! should have been 317.)

Closed

Member

### pkra commented Feb 10, 2014

 I'm not sure why this was closed but a related issue is open on MediaWiki's bug 49210. There, the problem is a special case of what @christianp pointed out in the OP: what about \ ? MathJax seems to interpret this as a TeX macro where the macro name is the non-breaking space and throws an error.

Member

### dpvc commented Feb 10, 2014

 MathJax seems to interpret this as a TeX macro where the macro name is the non-breaking space and throws an error. Yes, that is absolutely correct. The   is initially converted by the browser into U+00A0 (NON-BREAKING SPACE), and so MathJax sees \ followed by the non-breaking space, and that is an undefined control sequence name. We can define this sequence to work the same as \ followed by a regular space, and can make U+00A0 be treated as a space during math processing using Fred's suggestion above. We also need to change the definition of nextIsSpace() to skip it as well (this is used to skip spaces after control sequence names, and when looking for arguments for a macro, and so on). I think that will take care of the issues here and at MediaWiki.

### dpvc pushed a commit to dpvc/MathJax that referenced this issue Feb 10, 2014

 Make U+00A0 act as space in math mode. Resolves issue mathjax#377. 
 8fb4157 

Member

### pkra commented Feb 10, 2014

 Sounds good. I've sent an update to the MediaWiki's bug.

### dpvc pushed a commit to dpvc/MathJax that referenced this issue Feb 12, 2014

 Merge branch 'issue377' into develop. Issue mathjax#377. 
 6e597f8 

Member

### dpvc commented Feb 12, 2014

 => Merged.

### dpvc pushed a commit to mathjax/MathJax-test that referenced this issue Apr 21, 2014

 Add test for issue mathjax/MathJax#377. 
 6f9d272 
Member

### dpvc commented Apr 21, 2014

 => In Test Suite. LaTeXToMathML/issue377.html