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

Math block convert subscript to <em> #739

Closed ProFatXuanAll closed 3 years ago

ProFatXuanAll commented 3 years ago

I'm aware of issue #47 and #323 . But seems like this happens again. And I think this is an issue related to kramdown which treat subscript _ as markdown emphasis syntax.

Software versions:

Input:

$$
\begin{align}
\text{net}_i(t + 1) & = \sum_{j = 1}^{d_{\text{in}}} w_{ij} x_j(t) + \sum_{j = 1}^{d_{\text{out}}} w_{ij} y_j(t) \\
& = \sum_{j = 1}^{d_{\text{in}} + d_{\text{out}}} w_{ij} [x ; y]_j(t)
\end{align}
$$

Actual Output:

<p>$$
\begin{align}
\text{net}<em>i(t + 1) &amp; = \sum</em>{j = 1}^{d_{\text{in}}} w_{ij} x_j(t) + \sum_{j = 1}^{d_{\text{out}}} w_{ij} y_j(t) <br>
&amp; = \sum_{j = 1}^{d_{\text{in}} + d_{\text{out}}} w_{ij} [x ; y]_j(t)
\end{align}
$$</p>

Expected Output:

<p>$$
\begin{align}
\text{net}_i(t + 1) &amp; = \sum_{j = 1}^{d_{\text{in}}} w_{ij} x_j(t) + \sum_{j = 1}^{d_{\text{out}}} w_{ij} y_j(t) <br>
&amp; = \sum_{j = 1}^{d_{\text{in}} + d_{\text{out}}} w_{ij} [x ; y]_j(t)
\end{align}
$$</p>

Not sure related, here is my Gemfile:

source "https://rubygems.org"

gem "jekyll", "~> 4.2.1"

gem "jekyll-theme-yat", "~> 1.8.0"

# Mathjax support.
gem "kramdown-math-katex"

group :jekyll_plugins do
  gem "jekyll-feed", "~> 0.12"
end

platforms :mingw, :x64_mingw, :mswin, :jruby do
  gem "tzinfo", "~> 1.2"
  gem "tzinfo-data"
end

gem "wdm", "~> 0.1.1", :platforms => [:mingw, :x64_mingw, :mswin]

here is my _config.yml

author: ProFatXuanAll
baseurl: ""
copyright: "Copyright (c) 2021-{currentYear} <a href='https://github.com/ProFatXuanAll'>{author}</a>"

description: >- # this means to ignore newlines until "email:"
  ML notes all written by {{site.author}}.

encoding:         "utf-8"
email:            ProFatXuanAll@gmail.com
github_username:  ProFatXuanAll

title: >- # this means to ignore newlines.
  ML Notes

twitter_username: ProFatXuanAll

url: ""

yat:
  date_format: "%b %d, %Y"

timezone: Asia/Taipei

debug: true

sitemap: true

lang: "zh-TW"  # default lang is en

night_mode: "off"

paginate: 10

theme: jekyll-theme-yat
markdown: CommonMarkGhPages
markdown: kramdown
kramdown:
  input:            kramdown
  math_engine:      katex
  math_engine_opts: {}

plugins:
  - jekyll-feed
  - jekyll-seo-tag
  - jekyll-sitemap
  - jekyll-paginate
  - jekyll-spaceship
  - jekyll-paginate

I also found that star * in math block get converted to <em>, but I'm not sure if this is related to CJK.

Input:

現在讓我們固定 $k_0^{*} \in \{1, \dots, d_{\text{out}}\}$,我們可以計算 $\vartheta_{k_0^{*}}^{t}[t]$ 對於 $\vartheta_{k_n^{*}}^{t}[t - n]$ 的微分

Actual Output:

<p>現在讓我們固定 $k_0^{<em>} \in {1, \dots, d_{\text{out}}}$,我們可以計算 $\vartheta_{k_0^{</em>}}^{t}[t]$ 對於 $\vartheta_{k_n^{*}}^{t}[t - n]$ 的微分</p>

Expected Output:

<p>現在讓我們固定 $k_0^{*} \in {1, \dots, d_{\text{out}}}$,我們可以計算 $\vartheta_{k_0^{*}}^{t}[t]$ 對於 $\vartheta_{k_n^{*}}^{t}[t - n]$ 的微分</p>
gettalong commented 3 years ago
ProFatXuanAll commented 3 years ago

This sounds like Jekyll's configuration problem. (the math_engine option in _config.yaml only add a KaTeX script tag to html output.)

At the end I downgrade to 3.9.0 (which is the github supported version) and add MathJax v3 script by myself it suddenly work.

Also the two dollar signs for inline tex make my example run in display mode, so I assume this is also problems related to Jekyll.

gettalong commented 3 years ago

Thanks for the feedback! I will close the issue since there is nothing for kramdown to do.

For what kramdown supports in terms of math syntax see https://kramdown.gettalong.org/syntax.html#math-blocks.