-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Package: bump version * Feat: pass math to DOM in $$ tags * Fix: remove KaTeX from style * Feat: add setup.py for JupyterLab develop * Package: bump markup dependency version * Refactor: drop math rendering from docutils We need to unify this across all math plugins, so for now just require the amsmath impl * Feat: add `sphinx-display-math` plugin This reproduces the sphinx treatment of display math for convenient multi-line and multiple-equation environments * Chore: uncap markup dependency
- Loading branch information
Showing
8 changed files
with
86 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# setup.py shim for use with versions of JupyterLab that require | ||
# it for extensions. | ||
__import__("setuptools").setup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { simpleMarkdownItPlugin } from '@agoose77/jupyterlab-markup'; | ||
import { JupyterFrontEndPlugin } from '@jupyterlab/application'; | ||
import MarkdownIt from 'markdown-it'; | ||
|
||
import { PACKAGE_NS } from '../tokens'; | ||
|
||
function splitPart(text: string): string { | ||
if (text.includes('\\\\')) { | ||
return `\\begin{split}${text}\\end{split}`; | ||
} else { | ||
return text; | ||
} | ||
} | ||
|
||
export function wrapDisplayMath(text: string): string { | ||
const parts = text.split('\n\n'); | ||
const split_parts = parts.map(splitPart); | ||
|
||
// Allow multiline equations using split | ||
if (parts.length === 1) { | ||
return `\\begin{equation}\\begin{split}${parts[0]}\\end{split}\\end{equation}\n`; | ||
} | ||
// Allow aligned equations with aligned | ||
else if (parts.length > 1) { | ||
let result = ' \\begin{align}\\begin{aligned}'; | ||
result += split_parts.join('\\\\\n'); | ||
result += ' \\end{aligned}\\end{align}'; | ||
return result; | ||
} else { | ||
return split_parts.join('////'); | ||
} | ||
} | ||
|
||
/** | ||
* Provides Sphinx math-environment support | ||
*/ | ||
export const sphinxMath: JupyterFrontEndPlugin<void> = simpleMarkdownItPlugin( | ||
PACKAGE_NS, | ||
{ | ||
id: 'sphinx-display-math', | ||
title: 'Sphinx Display Math', | ||
description: | ||
'Plugin for transforming display math using the Sphinx displaymath rules', | ||
documentationUrls: {}, | ||
examples: { | ||
'Multi-line Equation ': '$$\nx = y \\\\ + mx + c\n$$\n', | ||
'Multiple Equations ': '$$x = y\n\ny + z = 2$$\n' | ||
}, | ||
plugin: async () => { | ||
return [ | ||
(md: MarkdownIt) => { | ||
md.core.ruler.push('sphinx-displaymath', state => { | ||
state.tokens.forEach(token => { | ||
if (token.type === 'math_block') { | ||
token.content = wrapDisplayMath(token.content); | ||
} else if (token.type === 'inline') { | ||
token.children.forEach(token => { | ||
if (token.type === 'math_inline_double') { | ||
token.content = wrapDisplayMath(token.content); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
]; | ||
} | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
@import 'markdown-it-docutils'; | ||
@import 'katex/dist/katex.css'; | ||
|
||
/* Use theme colours */ | ||
:root { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters