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

Arithmatex: Small improvements #44

Closed
facelessuser opened this issue Jan 20, 2017 · 3 comments
Closed

Arithmatex: Small improvements #44

facelessuser opened this issue Jan 20, 2017 · 3 comments
Labels
T: feature Feature.
Milestone

Comments

@facelessuser
Copy link
Owner

  • Allow Arithmatex to handle \begin{env} as people like this.
  • Allow math content to be wrapped in math/tex script tags.
@facelessuser
Copy link
Owner Author

Maybe add \[\] and \(\). Just give the people what they want :).

@facelessuser facelessuser added this to the 1.7.0 milestone Jan 20, 2017
@facelessuser facelessuser added the T: feature Feature. label Jan 20, 2017
@RoyiAvital
Copy link

Could you please also add option to support $ ... $ and $$ ... $$ for advanced users.
It means those advanced users (You may call it LaTeX mode) are aware that for the $ sign he need to use escape \$.

I really like that currently Markdown Preview is compatible with LaTeX and StackExchane as I copy & paste a lot of data around from and to.

Yet as I found out in facelessuser/MarkdownPreview#12 (comment) something breaks when using \{ or \} in Math Mode.

@facelessuser
Copy link
Owner Author

Please create a new issue. But I will go ahead and comment here.

$$ ... $$ is already possible. There is no restriction on spaces between $$.

I can consider the advanced mode for inline, but it will need ArithMatex's non-generic mode. Discussed later in this comment.

No Issue with \}

There is no issue with }. Let me explain why.

The examples posted here worked with one understandable issue. The 1st and 3rd were not parsed as expected. This is because \ is treated as a Markdown escape, but then placed back in the HTML as a single \. Then MathJax parses it because it is looking for \(...\).

\\( \forall i, \, {\mathcal{F} \left( g \right)}_{i} \in \left\{ -1, 1 \right\} \\)

\( \forall i, \, {\mathcal{F} \left( g \right)}_{i} \in \left\{ -1, 1 \right\} \)

\\(\forall i, \, {\mathcal{F} \left( g \right)}_{i} \in \left\{ -1, 1 \right\}\\)

\(\forall i, \, {\mathcal{F} \left( g \right)}_{i} \in \left\{ -1, 1 \right\}\)

What you actually need to do is double escape because Markdown will take \\\\( and turn it into HTML like this \\( and then MathJax will ignore it. Makes sense? Even curly brackets that are escaped are expected to translate from \{ to { if not handled specially. So this does not surprise me. Take a look at how other Markdown parsers handle this: https://johnmacfarlane.net/babelmark2/?text=%5C%7Btest%5C%7D+%5C%5C.

So when escaping by properly with \\\\(...\\\\). Let's look at the results:

screenshot 2018-05-26 12 55 47

Now Markdown Preview has another extension enabled called pymdownx.escapeall which will allow any character to be escaped. So you'll probably see additional things get coverted like \f --> f. But you can disable that if you find it surprising:

screenshot 2018-05-26 13 00 39

Non Generic Mode

But here's a trick. You can use Arithmatex's non generic mode (when the generic option is set to False which is the default) to actually wrap stuff in special MathJax scripts, which MathJax looks for by default. Then you don't even need to setup your JavaScript config to look for silly things like \(...\) in your HTML. Then escaping like \\(...\\) will work fine. As mentioned earlier, this would be required when using \$. Arithmatex does not process \$ even in generic mode. It treats it special, so \$ becomes $ in HTML MathJax will process it anyways unless you let it look for the scripts instead.

You can actually configure your own config in Markdown Preview and point to it instead. This one doesn't look for plain text to convert, but looks for the special non-generic MathJax scripts.

MathJax.Hub.Config({
  config: ["MMLorHTML.js"],
  jax: ["input/TeX", "output/HTML-CSS", "output/NativeMML"],
  extensions: ["MathMenu.js", "MathZoom.js"],
  TeX: {
    extensions: ["AMSmath.js", "AMSsymbols.js"],
    TagSide: "right",
    TagIndent: ".8em",
    MultLineWidth: "85%",
    equationNumbers: {
      autoNumber: "AMS",
    },
    unicode: {
      fonts: "STIXGeneral,'Arial Unicode MS'"
    }
  },
  displayAlign: "left",
  showProcessingMessages: false,
  messageStyle: 'none'
});

I actually tried to drop generic mode originally, but users requested it back again to work with non-MathJax libs. It probably makes sense for Markdown Preview to not use generic mode by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: feature Feature.
Projects
None yet
Development

No branches or pull requests

2 participants