{"id":15044286,"url":"https://github.com/vberlier/extract-math","last_synced_at":"2025-10-08T03:38:56.976Z","repository":{"id":34307998,"uuid":"177159663","full_name":"vberlier/extract-math","owner":"vberlier","description":"Extract TeX math environments.","archived":false,"fork":false,"pushed_at":"2023-03-04T03:26:48.000Z","size":2605,"stargazers_count":9,"open_issues_count":8,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-30T01:30:15.403Z","etag":null,"topics":["katex","latex","math","tex"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vberlier.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":["vberlier"]}},"created_at":"2019-03-22T14:56:07.000Z","updated_at":"2023-10-03T03:49:19.000Z","dependencies_parsed_at":"2023-01-15T06:13:41.874Z","dependency_job_id":"2985d80b-46ab-491b-a8c6-25e35dc02aed","html_url":"https://github.com/vberlier/extract-math","commit_stats":{"total_commits":233,"total_committers":5,"mean_commits":46.6,"dds":0.3004291845493562,"last_synced_commit":"148f9a93aca58719e9244da744a5ec650fd82e34"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/vberlier/extract-math","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vberlier%2Fextract-math","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vberlier%2Fextract-math/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vberlier%2Fextract-math/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vberlier%2Fextract-math/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vberlier","download_url":"https://codeload.github.com/vberlier/extract-math/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vberlier%2Fextract-math/sbom","scorecard":{"id":917155,"data":{"date":"2025-08-18","repo":{"name":"github.com/vberlier/extract-math","commit":"148f9a93aca58719e9244da744a5ec650fd82e34"},"scorecard":{"version":"v5.2.1-41-g40576783","commit":"40576783fda6698350fcbbeaea760ff827433034"},"score":1.7,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 0/15 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#signed-releases"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#license"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 30 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"24 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7","Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-24T21:27:29.027Z","repository_id":34307998,"created_at":"2025-08-24T21:27:29.027Z","updated_at":"2025-08-24T21:27:29.027Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278886369,"owners_count":26062972,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["katex","latex","math","tex"],"created_at":"2024-09-24T20:50:23.383Z","updated_at":"2025-10-08T03:38:56.943Z","avatar_url":"https://github.com/vberlier.png","language":"TypeScript","funding_links":["https://github.com/sponsors/vberlier"],"categories":[],"sub_categories":[],"readme":"# extract-math\n\n[![Build Status](https://travis-ci.com/vberlier/extract-math.svg?branch=master)](https://travis-ci.com/vberlier/extract-math)\n[![npm](https://img.shields.io/npm/v/extract-math.svg)](https://www.npmjs.com/package/extract-math)\n[![npm bundle size](https://img.shields.io/bundlephobia/minzip/extract-math.svg)](https://bundlephobia.com/result?p=extract-math)\n\n\u003e Extract TeX math environments.\n\nThis package parses [TeX shorthands](https://en.wikibooks.org/wiki/LaTeX/Mathematics#Mathematics_environments) for mathematics environments and extracts inline formulas (e.g.: `$x + 1$`) and displayed equations (e.g.: `$$\\sum_{i=1}^n 2^i$$`).\n\n```js\nimport { extractMath } from 'extract-math'\n\nconst segments = extractMath('hello $e^{i\\\\pi}$')\n\nconsole.log(segments)\n// Output: [\n//   { type: 'text', math: false, value: 'hello ', raw: 'hello ' },\n//   { type: 'inline', math: true, value: 'e^{i\\\\pi}', raw: 'e^{i\\\\pi}' }\n// ]\n```\n\nThe primary use-case is to process the math segments with a math typesetting library like [KaTeX](https://katex.org/).\n\n## Installation\n\nYou can install `extract-math` with your `npm` client of choice.\n\n```bash\n$ npm install extract-math\n```\n\n## Usage\n\n### extractMath(input, options?)\n\nParse the input string and return an array of `Segment` objects. `Segment` objects are defined by the following typescript interface:\n\n```ts\ninterface Segment {\n  type: 'text' | 'display' | 'inline'\n  math: boolean\n  value: string\n  raw: string\n}\n```\n\n\u003e The `Segment` interface can be imported with `import { Segment } from 'extract-math'`\n\nThe function splits the input string into 3 different types of segments:\n\n- Plain text segments have a `text` type and the `math` property set to `false`\n- Displayed equations have a `display` type and the `math` property set to `true`\n- Inline formulas have an `inline` type and the `math` property set to `true`\n\nThe function will check that the closing delimiter isn't immediately followed by a digit before extracting a math segment. This prevents input like `$20,000 and $30,000` from being interpreted as inline math.\n\nThe second parameter is optional and lets you specify custom options:\n\n```ts\ninterface ExtractMathOptions {\n  escape?: string\n  delimiters?: {\n    inline?: [string, string]\n    display?: [string, string]\n  }\n  allowSurroundingSpace?: Array\u003c'display' | 'inline'\u003e\n}\n```\n\n\u003e The `ExtractMathOptions` interface can be imported with `import { ExtractMathOptions } from 'extract-math'`\n\nHere are the default values:\n\n```js\n{\n  escape: '\\\\',\n  delimiters: {\n    inline: ['$', '$'],\n    display: ['$$', '$$']\n  },\n  allowSurroundingSpace: ['display']\n}\n```\n\nYou can extract formulas that use LaTeX math delimiters with the following options:\n\n```js\nconst segments = extractMath('hello \\\\(e^{i\\\\pi}\\\\)', {\n  delimiters: {\n    inline: ['\\\\(', '\\\\)'],\n    display: ['\\\\[', '\\\\]']\n  }\n})\n\nconsole.log(segments)\n// Output: [\n//   { type: 'text', math: false, value: 'hello ', raw: 'hello ' },\n//   { type: 'inline', math: true, value: 'e^{i\\\\pi}', raw: 'e^{i\\\\pi}' }\n// ]\n```\n\nBy default, only the `display` mode allows the formula to be surrounded by space. You can change this with the `allowSurroundingSpace` option:\n\n```js\nsegments = extractMath('$ 42 $$$ 42 $$', {\n  allowSurroundingSpace: ['inline', 'display']\n})\n\nconsole.log(segments)\n// Output: [\n//   { type: 'inline', math: true, value: ' 42 ', raw: ' 42 ' },\n//   { type: 'display', math: true, value: ' 42 ', raw: ' 42 ' }\n// ]\n```\n\n### Escaping\n\nAny delimiter immediately preceded by a backslash `\\` will be automatically escaped.\n\n```js\nconst segments = extractMath('in plain \\\\$ text $$in \\\\$ equation$$')\n\nconsole.log(segments)\n// Output: [\n//   { type: 'text', math: false, value: 'in plain $ text ', raw: 'in plain $ text ' },\n//   { type: 'display', math: true, value: 'in $ equation', raw: 'in \\\\$ equation' }\n// ]\n```\n\nThe `raw` property is set to the original string without interpreting the escape sequences. For plain text segments, the property is equal to the `value` property.\n\nThis comes in handy if you're feeding the math expressions to a math typesetting library like [KaTeX](https://katex.org/) that expects dollar signs to be escaped.\n\n```js\nkatex.render(segments[1].raw, ...)\n```\n\n## Contributing\n\nContributions are welcome. This project uses [jest](https://jestjs.io/) for testing.\n\n```bash\n$ npm test\n```\n\nThe code follows the [javascript standard](https://standardjs.com/) style guide [adapted for typescript](https://github.com/standard/eslint-config-standard-with-typescript).\n\n```bash\n$ npm run lint\n```\n\n---\n\nLicense - [MIT](https://github.com/vberlier/extract-math/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvberlier%2Fextract-math","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvberlier%2Fextract-math","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvberlier%2Fextract-math/lists"}