Adding an option to display the source of MathJax-rendered TeX inline
What I want to explain is described in this Stackoverflow question.
The problem is copying a piece of text with MathJax formula to Ipython Notebook is so frustrating. There are two issues that need to fixed:
- Ipython does not seem to recognize escaped parens, instead single or dollar signs are used.
- By going to context menu of the formula > Math Settings > Math Renderer > MathML, what is displayed does not have any formula enclosing characters. Adding them manually takes a lot of time.
The workarounds given in the answer are not simple. Does anyone know how to tweak the MathJax source to display those enclosing characters with dollar sign?
Sorry if my explanation is not so clear. I don't know much about these stuff.
It's probably better to use the PlainSource output instead of the MathML output for this kind of thing since it will behave identically across browsers.
Generally speaking, I don't see a good way of doing this as part of MathJax. MathJax can be configure to use pretty much anything as a delimiter (from the author's end) and what the reader is after will frequently be different (e.g., many stackexchange sites use custom delimiters).
Using the PlainSource output and some simple JavaScript (targeting the relevant class to wrap the plain source output in delimiters) seems the obvious choice to me.
When I try the plain source, I get a duplicate of the formula e.g. \sigma(\sum_iw_ix_i + b)σ(∑iwixi+b) in two different formats which makes the job even harder to get rid of one of them. Besides, I don't see any class associated with the Tex code in the source code (example here).
If the author can decide the delimiter, it should be possible to add a utility function for the user (in the context menu) to 1) make delimiters visible 2) choose the delimiter type of interest.
Or maybe overriding the authors configuration by running a script on the browser console. I tried to change
MathJax.Hub.Config({
tex2jax: {inlineMath: [["$","$"],["\\(","\\)"]]}
});
but it didn't work. It says undefined.
When I try the plain source, I get a duplicate of the formula e.g. \sigma(\sum_iw_ix_i + b)σ(∑iwixi+b) in two different formats which makes the job even harder to get rid of one of them.
I don't know what you're doing. Are you just copy&pasting? That's not what I described.
(example here).
That example is using MathJax 2.5 which does not have the PlainSource output option. That's new in v2.6,; cf. http://docs.mathjax.org/en/latest/options/PlainSource.html
Or maybe overriding the authors configuration by running a script on the browser console. I tried to change
That won't work and wouldn't do what you want.
Are you just copy&pasting?
Yes. I am just a plain user who wants to copy stuff from websites to Ipython notebook.
That example is using MathJax 2.5 which does not have the PlainSource output option. That's new in v2.6
My bad, I tried it here
Anyhow, you guys have made math beautiful on the web. It would be great to add some convenience as well. Thanks for the quick follow-up :)
Just switch to PlainSource output and run something like
(function(){ var inline = document.getElementsByClassName("MathJax_PlainSource"); var display = document.getElementsByClassName("MathJax_PlainSource_Display"); for (var i=0; i< inline.length; i++){ var math = inline[i]; math.innerHTML = '<span>$</span>' + math.innerHTML + '<span>$</span>'; } for (var i=0; i< display.length; i++){ var math = display[i]; math.innerHTML = '<span>$</span>' + math.innerHTML + '<span>$</span>'; }})()
e.g., by making it a bookmarklet -- prepend javascript: to this and make that the URL of a bookmark.
It would be great to add some convenience as well.
Again, the problem is rather complex. Dedicated HTML-to-LaTeX converters like pandoc are much better at this.
I created the bookmark. It works quite well. I will fix some minor issues and publish it on Chrome Web Store as an extension. Thank you so much!