Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should   in LaTeX produce a space? #377

Closed
christianp opened this issue Jan 15, 2013 · 15 comments

Comments

Projects
None yet
6 participants
@christianp
Copy link
Contributor

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.

@fred-wang

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link

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.

@fred-wang

This comment has been minimized.

Copy link
Contributor

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.

@dpvc

This comment has been minimized.

Copy link
Member

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.

@fred-wang

This comment has been minimized.

Copy link
Contributor

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.

@dpvc

This comment has been minimized.

Copy link
Member

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.

@dpvc

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link

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

@fred-wang

This comment has been minimized.

Copy link
Contributor

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

@dpvc

This comment has been minimized.

Copy link
Member

commented Mar 20, 2013

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

@pkra

This comment has been minimized.

Copy link
Member

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.

@dpvc dpvc added Accepted labels Feb 10, 2014

@dpvc

This comment has been minimized.

Copy link
Member

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 dpvc added this to the Bugfix Version milestone Feb 10, 2014

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

@pkra

This comment has been minimized.

Copy link
Member

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

@dpvc dpvc added Merged and removed Ready for Review labels Feb 12, 2014

@dpvc

This comment has been minimized.

Copy link
Member

commented Feb 12, 2014

=> Merged.

@dpvc dpvc closed this Feb 12, 2014

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

@dpvc

This comment has been minimized.

Copy link
Member

commented Apr 21, 2014

=> In Test Suite.

LaTeXToMathML/issue377.html

@dpvc dpvc added v2.4 and removed Merged labels Jun 30, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.