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

Support math latex. #1275

Closed
wants to merge 11 commits into from
Closed

Support math latex. #1275

wants to merge 11 commits into from

Conversation

ahuigo
Copy link

@ahuigo ahuigo commented May 24, 2018

Marked version:
Release 0.4.0

Contributor

I don't know how to test this project exactly. Any advice?

  • Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR); or,
  • no tests required for this PR.
  • If submitting new feature, it has been documented in the appropriate places.

The demo for this feature:

https://github.com/ahuigo/marked/blob/master/docs/demo/latex.html

Committer

In most cases, this should be a different person than the contributor.

  • Draft GitHub release notes have been updated.
  • CI is green (no forced merge required).
  • Merge PR

@UziTech
Copy link
Member

UziTech commented May 25, 2018

This seems like it would be better as a wrapper around marked.

You could create a separate npm package that extends the lexer

@ahuigo
Copy link
Author

ahuigo commented May 25, 2018

@UziTech
It's hard to add a wrapper for marked. I have to add a math lexer to marked.( If user want to parse math, he should pass option latexParser).

  1. I wish marked itself would support math lexer, because many people need math latex.
  2. If I create a separate npm, it was hard to pull code back to upstream , as I have changed marked's lexer directly.

@UziTech
Copy link
Member

UziTech commented May 25, 2018

We are trying to slim marked down. By the 1.0 release we would like to deprecate most of the options.

We are trying to focus on making marked spec compliant with CommonMark and GFM. For everything else we would like to create separate modules that extend marked.

I can leave this PR open so we can revisit it in the future and possibly create a module ourselves but it will be a while before that happens.

@BenjaminHoegh
Copy link

Is there a API for marked or is it code it from the ground if you wanna make extensions to it?

@UziTech
Copy link
Member

UziTech commented May 29, 2018

You can check out the documentation here for extending marked.

@BenjaminHoegh
Copy link

@UziTech Posible without node.js? Some web hotels don't support nodejs and would like to keep it working on so many server types as possible

@UziTech
Copy link
Member

UziTech commented May 29, 2018

@BenjaminHoegh Is what possible without node? marked is written in js so it needs a js engine in order to run at all.

If you use marked on the client side it will create a global variable marked so you just replace var myMarked = require('marked'); with var myMarked = marked;

@BenjaminHoegh
Copy link

@UziTech Is there documentation about how to add new rules to inline and block

@UziTech
Copy link
Member

UziTech commented May 29, 2018

I don't believe there is a way to add new rules easily yet. All of our documentation is at marked.js.org

@yhcharles
Copy link

yhcharles commented Oct 17, 2018

@ahuigo
It seems the blocklatex is not rendering in display mode, which gives this:
qq20181017-115715 2x
but it's better to be this:
qq20181017-115730 2x

yhcharles added a commit to yhcharles/yhcharles.github.io that referenced this pull request Oct 17, 2018
@UziTech UziTech closed this Dec 5, 2018
@ahuigo
Copy link
Author

ahuigo commented Dec 31, 2018

@yhcharles What you need is \displaystyle , for example$\displaystyle \sum_i^j$. You can try it here: https://ahuigo.github.io/a/md.html

@BrianHung
Copy link

BrianHung commented Jul 19, 2019

@yhcharles

This is a bit late, but another solution would be to change the source code beginning at line 935 from

      var html = marked.defaults.latexRender(text);
      if (block) {
        out = '<div style="text-align:center">' + html + '</div>';
      }else{
        out = html;
      }

to

      if (block) {
        out = marked.defaults.latexRender(text, {displayMode: true});
      }else{
        out = marked.defaults.latexRender(text);
      }

This assumes you're using KaTeX to render LaTeX; documentation here. I'm sure that MathJax has the same setting.

Note I haven't tested this implementation yet.

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

Successfully merging this pull request may close these issues.

5 participants