+
Skip to content

_ in math expressions doesn't get parsed correctly when surrounded by curly braces #38

Open
@Bisaloo

Description

@Bisaloo

When surrounded by curly braces, _ is parsed as an emph marker instead of being preserved as math syntax:

Reprex:

# Works
commonmark::markdown_xml(
  "This $\\mathcal{R}_0$ and that $\\mathcal{R}_0$"
)
#> [1] "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n<document xmlns=\"http://commonmark.org/xml/1.0\">\n  <paragraph>\n    <text xml:space=\"preserve\">This $\\mathcal{R}_0$ and that $\\mathcal{R}_0$</text>\n  </paragraph>\n</document>\n"

# Doesn't work
commonmark::markdown_xml(
  "This $\\mathcal{R}_{eff}$ and that $\\mathcal{R}_{eff}$"
)
#> [1] "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n<document xmlns=\"http://commonmark.org/xml/1.0\">\n  <paragraph>\n    <text xml:space=\"preserve\">This $\\mathcal{R}</text>\n    <emph>\n      <text xml:space=\"preserve\">{eff}$ and that $\\mathcal{R}</text>\n    </emph>\n    <text xml:space=\"preserve\">{eff}$</text>\n  </paragraph>\n</document>\n"

Created on 2025-04-09 with reprex v2.1.1

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R Under development (unstable) (2025-03-18 r87998)
#>  os       Ubuntu 24.04.2 LTS
#>  system   x86_64, linux-gnu
#>  ui       X11
#>  language en_US
#>  collate  en_GB.UTF-8
#>  ctype    en_GB.UTF-8
#>  tz       Europe/Paris
#>  date     2025-04-09
#>  pandoc   3.1.3 @ /bin/ (via rmarkdown)
#>  quarto   1.6.39 @ /opt/quarto/bin/quarto
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  cli           3.6.4   2025-02-13 [1] RSPM (R 4.6.0)
#>  commonmark    1.9.5   2025-04-09 [1] Github (r-lib/commonmark@e033b75)
#>  digest        0.6.37  2024-08-19 [1] RSPM (R 4.6.0)
#>  evaluate      1.0.3   2025-01-10 [1] RSPM (R 4.6.0)
#>  fastmap       1.2.0   2024-05-15 [1] RSPM (R 4.6.0)
#>  fs            1.6.5   2024-10-30 [1] RSPM (R 4.6.0)
#>  glue          1.8.0   2024-09-30 [1] RSPM (R 4.6.0)
#>  htmltools     0.5.8.1 2024-04-04 [1] RSPM (R 4.6.0)
#>  knitr         1.50    2025-03-16 [1] RSPM (R 4.6.0)
#>  lifecycle     1.0.4   2023-11-07 [1] RSPM (R 4.6.0)
#>  reprex        2.1.1   2024-07-06 [1] RSPM
#>  rlang         1.1.5   2025-01-17 [1] RSPM (R 4.6.0)
#>  rmarkdown     2.29    2024-11-04 [1] RSPM
#>  sessioninfo   1.2.3   2025-02-05 [1] RSPM (R 4.6.0)
#>  withr         3.0.2   2024-10-28 [1] RSPM (R 4.6.0)
#>  xfun          0.51    2025-02-19 [1] RSPM (R 4.6.0)
#>  yaml          2.3.10  2024-07-26 [1] RSPM (R 4.6.0)
#> 
#>  [1] /home/hugo/.local/share/R/x86_64-pc-linux-gnu-library/4.6
#>  [2] /opt/R/devel/lib/R/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载