benweet / stackedit

In-browser Markdown editor
https://stackedit.io/
Apache License 2.0
21.79k stars 2.73k forks source link

How to fix the `\\` problem? #19

Closed vanabel closed 11 years ago

vanabel commented 11 years ago

When I use mathjax to render math formula, in which \\ means new line, but when I export the markdown doc to html, the \\ has been transformed into \, I think this is done by markdown automatically?

How to fix it?

benweet commented 11 years ago

Hi @vanabel Yes, that's done by markdown, you can't avoid that. Are you still disabling MathJax extension before exporting to html? If so, that's not a good practice.

vanabel commented 11 years ago

I don't want to use your method as:

  1. the code rendered by mathjax is quite complicated, if I want to correct some typo in the formula, I almost don't know where to locate it in wp-editor, of course I can do this in stackedit, but I need to export them all to wp again.
  2. In wp, I have write a plugin to extend to ability of mathjax, which makes to publish my article from latex doc to wp almost without any modification. So, I prefer to raw latex code (rather than the code rendered by mathjax).

If in any case, I have some misunderstanding, then please tell me, I really fell inconvenient to disable and resume mathjax angain and agian.

benweet commented 11 years ago

Please have a look into this. If you export the HTML output, then you will have the MathJax_Display div block AND the MathJax-Element script block. So you have two options:

With the second option, you can modify from your editor the script block which contains the raw latex code. MathJax will recreate MathJax_Display according to it. You can also modify the latex code in StackEdit and click the "publish button" in the navigation bar to update your blog in one click.

vanabel commented 11 years ago

You mean you will work this(the second option is attractive!)? thks a lot!!

benweet commented 11 years ago

That's already implemented. The HTML output contains both MathJax_Display div block and MathJax-Element script block. Those are 2 options for your blog.

vanabel commented 11 years ago

I don't get it, did you mean that I can keep only the Mathjax-Element block in the final export? How to do this?

benweet commented 11 years ago

No, that's not what I meant. But you can do that as a 3rd option. To do that, you need to use the template output.

In Settings->Publish->Template, you can customize the template output. For instance you can modify the documentHTML variable to remove the MathJax, MathJax_Display, MathJax_Preview elements like that:

<%
var output = $("<div>").html(documentHTML);
output.find(".MathJax, .MathJax_Display, .MathJax_Preview").remove();
print(output.html());
%>

You can even revert the MathJax-Element script blocks into Tex with delimiters like that:

<%
var output = $("<div>").html(documentHTML);
output.find(".MathJax, .MathJax_Display, .MathJax_Preview").remove();
output.find('script[type="math/tex"]').each(function() { $(this).replaceWith('\\(' + this.innerHTML + '\\)'); });
output.find('script[type="math/tex; mode=display"]').each(function() { $(this).replaceWith('\\[' + this.innerHTML + '\\]'); });
print(output.html());
%>

Then you need to use Template as output when publishing.

vanabel commented 11 years ago

It's awesome, fantastic, that's so great!! I only need to add two more classes in your 2nd script, i.e., .MathJax_SVG and .MathJax_SVG_Display, then the export by template will be what I exact like. Thanks a lot!!!

vanabel commented 11 years ago

I recommend to make the preview HTML code only preserve the LaTeX code, just as I can configure in template, is there somewhere I can configure it for HTML code?

benweet commented 11 years ago

No, but I can add a configuration in the HTML code extension...

benweet commented 11 years ago

Added template configuration in the extension settings.

vanabel commented 11 years ago

@benweet May I point out that your default configuration of display math have some typo? The \[ and \]in display math should be \\[ and \\] respectively.

benweet commented 11 years ago

Yes, you're right! I just changed the default settings... Thank you for your point.

vanabel commented 11 years ago

I find that Html code view is not only preview the latex code, even when I setting it in template!

benweet commented 11 years ago

Can you give more detail?

vanabel commented 11 years ago

I want to set the template output as

<%
var output = $("<div>").html(documentHTML);
output.find(".MathJax, .MathJax_Display, .MathJax_Preview").remove();
output.find('script[type="math/tex"]').each(function() { $(this).replaceWith('\\(' + this.innerHTML + '\\)'); });
output.find('script[type="math/tex; mode=display"]').each(function() { $(this).replaceWith('\\[' + this.innerHTML + '\\]'); });
print(output.html());
%>

such that the exported html file is not include the rendered latex code, but the original input form of latex.