gettalong / kramdown

kramdown is a fast, pure Ruby Markdown superset converter, using a strict syntax definition and supporting several common extensions.
http://kramdown.gettalong.org
Other
1.72k stars 274 forks source link

mathjax 3.0 issues #712

Closed OrenBochman closed 3 years ago

OrenBochman commented 3 years ago

I've had a too many issues to list trying to cram mathjax v.3 down kramdown's throat without it choking latex code on a new jekyll blog hosted by githubpages.

Here are a few that if fixed should make it much simpler to use mathjax.

  1. | used for absolute values and norm trigger a markdown table.
    • desired behaviour o not replace | in non markdown blocks i.e. within the mathjax delimiters
    • my workaround is replace | with \vert instead of '|' in equations.
  2. \\ as line breaks are replaced with hard line breaks and then ignored within the mathjax delimiters
    • desired behaviour o not replace \\ in non markdown blocks i.e. within the mathjax delimiters
    • workaround use \newline instead of '\` in equations.
  3. mathjax now looks for its delimiters rather then the tags being used.
    • add a math_engine_opts entry: say dollars_untaxed to suppress replacement of the mathjax $ delimiters
    • workaround replace $ and $$ to say @ and @@ respectively.

here is my current integration:

    <script>
      window.MathJax = {
        loader: {load: ['[tex]/ams']},
        tex: {
          inlineMath: [['@', '@']],
          displayMath: [['@@', '@@'],],
          tags: 'ams',
          multlineWidth: '85%',      // width of multline environment
          packages: {'[+]': ['ams']}},
          formatError:               // function called when TeX syntax errors occur
            (jax, err) => jax.formatError(err),
      };
    </script>
    <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
    <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
gettalong commented 3 years ago

ad 1) Your work-around is the way to go. This is historic behaviour due to how parsing works and how tables are defined.

ad 2) This is how hard line breaks are defined by kramdown. Note that this is only done when using inline math but not within block math.

ad 3) The output of the HTML converter with respect to math elements has been changed to use \(...\) for inline math and \[...\] for block math because of MathJax 3. This was done in kramdown 2.2.0, also see https://github.com/gettalong/kramdown/issues/626

itcarroll commented 3 years ago

Display equations still aren't working for me, despite the kramdown update.

Here's my markdown:

An inline $$x = \pi$$ equation.

$$
x = \tau
$$

Here's the (relevant) rendered html

<p>An inline \(x = \pi\) equation.</p>

<p>[x = \tau]</p>

Here's my Gemfile.lock

GEM
  remote: https://rubygems.org/
  specs:
    activesupport (6.0.3.4)
      concurrent-ruby (~> 1.0, >= 1.0.2)
      i18n (>= 0.7, < 2)
      minitest (~> 5.1)
      tzinfo (~> 1.1)
      zeitwerk (~> 2.2, >= 2.2.2)
    addressable (2.7.0)
      public_suffix (>= 2.0.2, < 5.0)
    coffee-script (2.4.1)
      coffee-script-source
      execjs
    coffee-script-source (1.11.1)
    colorator (1.1.0)
    commonmarker (0.17.13)
      ruby-enum (~> 0.5)
    concurrent-ruby (1.1.7)
    dnsruby (1.61.5)
      simpleidn (~> 0.1)
    em-websocket (0.5.2)
      eventmachine (>= 0.12.9)
      http_parser.rb (~> 0.6.0)
    ethon (0.12.0)
      ffi (>= 1.3.0)
    eventmachine (1.2.7)
    execjs (2.7.0)
    faraday (1.1.0)
      multipart-post (>= 1.2, < 3)
      ruby2_keywords
    ffi (1.14.2)
    forwardable-extended (2.6.0)
    gemoji (3.0.1)
    github-pages (209)
      github-pages-health-check (= 1.16.1)
      jekyll (= 3.9.0)
      jekyll-avatar (= 0.7.0)
      jekyll-coffeescript (= 1.1.1)
      jekyll-commonmark-ghpages (= 0.1.6)
      jekyll-default-layout (= 0.1.4)
      jekyll-feed (= 0.15.1)
      jekyll-gist (= 1.5.0)
      jekyll-github-metadata (= 2.13.0)
      jekyll-mentions (= 1.6.0)
      jekyll-optional-front-matter (= 0.3.2)
      jekyll-paginate (= 1.1.0)
      jekyll-readme-index (= 0.3.0)
      jekyll-redirect-from (= 0.16.0)
      jekyll-relative-links (= 0.6.1)
      jekyll-remote-theme (= 0.4.2)
      jekyll-sass-converter (= 1.5.2)
      jekyll-seo-tag (= 2.6.1)
      jekyll-sitemap (= 1.4.0)
      jekyll-swiss (= 1.0.0)
      jekyll-theme-architect (= 0.1.1)
      jekyll-theme-cayman (= 0.1.1)
      jekyll-theme-dinky (= 0.1.1)
      jekyll-theme-hacker (= 0.1.2)
      jekyll-theme-leap-day (= 0.1.1)
      jekyll-theme-merlot (= 0.1.1)
      jekyll-theme-midnight (= 0.1.1)
      jekyll-theme-minimal (= 0.1.1)
      jekyll-theme-modernist (= 0.1.1)
      jekyll-theme-primer (= 0.5.4)
      jekyll-theme-slate (= 0.1.1)
      jekyll-theme-tactile (= 0.1.1)
      jekyll-theme-time-machine (= 0.1.1)
      jekyll-titles-from-headings (= 0.5.3)
      jemoji (= 0.12.0)
      kramdown (= 2.3.0)
      kramdown-parser-gfm (= 1.1.0)
      liquid (= 4.0.3)
      mercenary (~> 0.3)
      minima (= 2.5.1)
      nokogiri (>= 1.10.4, < 2.0)
      rouge (= 3.23.0)
      terminal-table (~> 1.4)
    github-pages-health-check (1.16.1)
      addressable (~> 2.3)
      dnsruby (~> 1.60)
      octokit (~> 4.0)
      public_suffix (~> 3.0)
      typhoeus (~> 1.3)
    html-pipeline (2.14.0)
      activesupport (>= 2)
      nokogiri (>= 1.4)
    http_parser.rb (0.6.0)
    i18n (0.9.5)
      concurrent-ruby (~> 1.0)
    jekyll (3.9.0)
      addressable (~> 2.4)
      colorator (~> 1.0)
      em-websocket (~> 0.5)
      i18n (~> 0.7)
      jekyll-sass-converter (~> 1.0)
      jekyll-watch (~> 2.0)
      kramdown (>= 1.17, < 3)
      liquid (~> 4.0)
      mercenary (~> 0.3.3)
      pathutil (~> 0.9)
      rouge (>= 1.7, < 4)
      safe_yaml (~> 1.0)
    jekyll-avatar (0.7.0)
      jekyll (>= 3.0, < 5.0)
    jekyll-coffeescript (1.1.1)
      coffee-script (~> 2.2)
      coffee-script-source (~> 1.11.1)
    jekyll-commonmark (1.3.1)
      commonmarker (~> 0.14)
      jekyll (>= 3.7, < 5.0)
    jekyll-commonmark-ghpages (0.1.6)
      commonmarker (~> 0.17.6)
      jekyll-commonmark (~> 1.2)
      rouge (>= 2.0, < 4.0)
    jekyll-default-layout (0.1.4)
      jekyll (~> 3.0)
    jekyll-feed (0.15.1)
      jekyll (>= 3.7, < 5.0)
    jekyll-gist (1.5.0)
      octokit (~> 4.2)
    jekyll-github-metadata (2.13.0)
      jekyll (>= 3.4, < 5.0)
      octokit (~> 4.0, != 4.4.0)
    jekyll-mentions (1.6.0)
      html-pipeline (~> 2.3)
      jekyll (>= 3.7, < 5.0)
    jekyll-optional-front-matter (0.3.2)
      jekyll (>= 3.0, < 5.0)
    jekyll-paginate (1.1.0)
    jekyll-readme-index (0.3.0)
      jekyll (>= 3.0, < 5.0)
    jekyll-redirect-from (0.16.0)
      jekyll (>= 3.3, < 5.0)
    jekyll-relative-links (0.6.1)
      jekyll (>= 3.3, < 5.0)
    jekyll-remote-theme (0.4.2)
      addressable (~> 2.0)
      jekyll (>= 3.5, < 5.0)
      jekyll-sass-converter (>= 1.0, <= 3.0.0, != 2.0.0)
      rubyzip (>= 1.3.0, < 3.0)
    jekyll-sass-converter (1.5.2)
      sass (~> 3.4)
    jekyll-seo-tag (2.6.1)
      jekyll (>= 3.3, < 5.0)
    jekyll-sitemap (1.4.0)
      jekyll (>= 3.7, < 5.0)
    jekyll-swiss (1.0.0)
    jekyll-theme-architect (0.1.1)
      jekyll (~> 3.5)
      jekyll-seo-tag (~> 2.0)
    jekyll-theme-cayman (0.1.1)
      jekyll (~> 3.5)
      jekyll-seo-tag (~> 2.0)
    jekyll-theme-dinky (0.1.1)
      jekyll (~> 3.5)
      jekyll-seo-tag (~> 2.0)
    jekyll-theme-hacker (0.1.2)
      jekyll (> 3.5, < 5.0)
      jekyll-seo-tag (~> 2.0)
    jekyll-theme-leap-day (0.1.1)
      jekyll (~> 3.5)
      jekyll-seo-tag (~> 2.0)
    jekyll-theme-merlot (0.1.1)
      jekyll (~> 3.5)
      jekyll-seo-tag (~> 2.0)
    jekyll-theme-midnight (0.1.1)
      jekyll (~> 3.5)
      jekyll-seo-tag (~> 2.0)
    jekyll-theme-minimal (0.1.1)
      jekyll (~> 3.5)
      jekyll-seo-tag (~> 2.0)
    jekyll-theme-modernist (0.1.1)
      jekyll (~> 3.5)
      jekyll-seo-tag (~> 2.0)
    jekyll-theme-primer (0.5.4)
      jekyll (> 3.5, < 5.0)
      jekyll-github-metadata (~> 2.9)
      jekyll-seo-tag (~> 2.0)
    jekyll-theme-slate (0.1.1)
      jekyll (~> 3.5)
      jekyll-seo-tag (~> 2.0)
    jekyll-theme-tactile (0.1.1)
      jekyll (~> 3.5)
      jekyll-seo-tag (~> 2.0)
    jekyll-theme-time-machine (0.1.1)
      jekyll (~> 3.5)
      jekyll-seo-tag (~> 2.0)
    jekyll-titles-from-headings (0.5.3)
      jekyll (>= 3.3, < 5.0)
    jekyll-watch (2.2.1)
      listen (~> 3.0)
    jemoji (0.12.0)
      gemoji (~> 3.0)
      html-pipeline (~> 2.2)
      jekyll (>= 3.0, < 5.0)
    kramdown (2.3.0)
      rexml
    kramdown-parser-gfm (1.1.0)
      kramdown (~> 2.0)
    liquid (4.0.3)
    listen (3.3.3)
      rb-fsevent (~> 0.10, >= 0.10.3)
      rb-inotify (~> 0.9, >= 0.9.10)
    mercenary (0.3.6)
    mini_portile2 (2.4.0)
    minima (2.5.1)
      jekyll (>= 3.5, < 5.0)
      jekyll-feed (~> 0.9)
      jekyll-seo-tag (~> 2.1)
    minitest (5.13.0)
    multipart-post (2.1.1)
    nokogiri (1.10.10)
      mini_portile2 (~> 2.4.0)
    octokit (4.19.0)
      faraday (>= 0.9)
      sawyer (~> 0.8.0, >= 0.5.3)
    pathutil (0.16.2)
      forwardable-extended (~> 2.6)
    public_suffix (3.1.1)
    rb-fsevent (0.10.4)
    rb-inotify (0.10.1)
      ffi (~> 1.0)
    rexml (3.2.3)
    rouge (3.23.0)
    ruby-enum (0.8.0)
      i18n
    ruby2_keywords (0.0.2)
    rubyzip (2.3.0)
    safe_yaml (1.0.5)
    sass (3.7.4)
      sass-listen (~> 4.0.0)
    sass-listen (4.0.0)
      rb-fsevent (~> 0.9, >= 0.9.4)
      rb-inotify (~> 0.9, >= 0.9.7)
    sawyer (0.8.2)
      addressable (>= 2.3.5)
      faraday (> 0.8, < 2.0)
    simpleidn (0.1.1)
      unf (~> 0.1.4)
    terminal-table (1.8.0)
      unicode-display_width (~> 1.1, >= 1.1.1)
    thread_safe (0.3.6)
    typhoeus (1.4.0)
      ethon (>= 0.9.0)
    tzinfo (1.2.9)
      thread_safe (~> 0.1)
    unf (0.1.4)
      unf_ext
    unf_ext (0.0.7.7)
    unicode-display_width (1.7.0)
    zeitwerk (2.4.2)

PLATFORMS
  x86_64-linux-musl

DEPENDENCIES
  github-pages

BUNDLED WITH
   2.2.2
gettalong commented 3 years ago

If I run you sample document through the kramdown binary I get the following result:

<p>An inline \(x = \pi\) equation.</p>

\[x = \tau\]

Which looks fine and like it should be. If you get a different result, please ask someone from Jekyll.

itcarroll commented 3 years ago

Ah. Okay I see/agree it's not a kramdown issue.

Thanks!