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

Latex support #334

Closed
v-goncharenko opened this issue Jul 5, 2022 · 3 comments
Closed

Latex support #334

v-goncharenko opened this issue Jul 5, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@v-goncharenko
Copy link

v-goncharenko commented Jul 5, 2022

Context

I use Latex in my Markdown, then it is rendered with MathJax (in Jupyter Notebook).

But now mdformat reformats my Latex code as follows:

$$
-    "\\begin{equation}\n",
+    "\\\\begin{equation}\n",

-    "d(x, y) = \\sqrt{\\sum_{i = 1}^n (x_i - y_i)^2}\n",
+    "d(x, y) = \\\\sqrt{\\\\sum\\_{i = 1}^n (x_i - y_i)^2}\n",

-    "\\end{equation}\n",
+    "\\\\end{equation}\n",
$$

So after formatting it stops to be valid Latex and renders as string.

Proposal

Escape Latex notation in mdformat.

  1. Easy way - just escape (left as is) everything inside $$ ... $$ block (and maybe in $ ... $ block). But this is error prone =(
  2. Harder way - borrow parser ideas from Jupyter, MathJax, etc. This requires some research.

Tasks and updates

No response

@v-goncharenko v-goncharenko added the enhancement New feature or request label Jul 5, 2022
@welcome
Copy link

welcome bot commented Jul 5, 2022

Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.

If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).

Welcome to the EBP community! 🎉

@hukkin
Copy link
Member

hukkin commented Jul 5, 2022

mdformat-myst plugin supports the dollar math syntax that you use. Please try installing it. It is possible that the support discontinuous though in which case you may need to create a separate plugin, see #330 (comment)

Nonetheless, the syntax is not included in CommonMark spec so mdformat "core" will not support it.

@v-goncharenko
Copy link
Author

Yes, this seem to solve the problem, thanks!

I use it with nbQA and my final config for mdformat looks like this:

  - repo: https://github.com/nbQA-dev/nbQA
    rev: 1.3.1
    hooks:
      - id: nbqa-black
        additional_dependencies: [black==22.6.0]
      - id: nbqa-isort
        additional_dependencies: [isort==5.10.1]
      - id: nbqa-flake8
        additional_dependencies: [flake8==3.9.2]
      - id: nbqa-mdformat
        name: nbqa-mdformat
        entry: nbqa mdformat
        alias: nbqa-mdformat
        additional_dependencies:
          - mdformat==0.7.14
          - mdformat-myst

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants