Skip to content

Instantly share code, notes, and snippets.

@jannismain
Last active May 22, 2023 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jannismain/4a17d195b7b8eb027b658dac71971167 to your computer and use it in GitHub Desktop.
Save jannismain/4a17d195b7b8eb027b658dac71971167 to your computer and use it in GitHub Desktop.
configure markdownlint-cli2 to lint math in CLI and pre-commit hook properly
{
"markdownItPlugins": [
["markdown-it-texmath"]
],
"config": {
"MD013": false
}
}
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/DavidAnson/markdownlint-cli2
rev: v0.5.1
hooks:
- id: markdownlint-cli2
additional_dependencies: ["markdown-it-texmath", "katex"]

Proper linting of math documents using markdownlint-cli2

The problem is that when linting example.md, a false positive MD049 warning is generated.

$ markdownlint-cli2 example.md
markdownlint-cli2 v0.5.1 (markdownlint v0.26.2)
Finding: example.md
Linting: 1 file(s)
Summary: 1 error(s)
example.md:6:6 MD049/emphasis-style Emphasis style should be consistent [Expected: asterisk; Actual: underscore]

Solution

Use markdown-it-texmath plugin so that math syntax is parsed correctly.

  1. Install plugin and dependencies

    npm install markdown-it-texmath katex

    For usage with a pre-commit hook, these need to be added as additional_dependencies:

    - repos:
      - repo: https://github.com/DavidAnson/markdownlint-cli2
        hooks:
          - id: markdownlint-cli2
            additional_dependencies: ["markdown-it-texmath", "katex"]
  2. Reference plugin in markdownlint-cli2 configuration file (e.g. .markdownlint-cli2.jsonc):

    {
      "markdownItPlugins": [
        ["markdown-it-texmath"]
      ]
    }

Heading

Text with some emphasis

$$ q^{'}{i} = q^{'}{i+1} $$

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