Hrishikesh Barman
2023-09-29 2f99339dcf93ef50b766263297785a32d9c35250
refs
author Hrishikesh Barman <geekodour@users.noreply.github.com>
Friday, September 29, 2023 18:35 +0000
committer GitHub <noreply@github.com>
Friday, September 29, 2023 18:35 +0000
commit2f99339dcf93ef50b766263297785a32d9c35250
tree e352a5239a9d967a8b1111b2cd47a8825962a0f6 tree | zip | gz
parent 5232d09af520e12bc421cf19ae5d231a7e36cd4d view | diff
feat: add transformations for latex in oxhugofm (#510)

ox-hugo currently supports the following syntax for latex equations:
- https://orgmode.org/manual/LaTeX-fragments.html
- https://ox-hugo.scripter.co/doc/equations

This syntax is supported by mathjax as is mentioned in the ox-hugo documentation.

But quartz uses remark-math which has some issues with the \( \) syntax.
See https://github.com/remarkjs/remark-math/issues/39

This change adds few more transformations to the OxHugoFlavouredMarkdown
plugin, which makes a best effort conversion of this syntax into what
the Quartz Latex transformer plugin supports.

With these changes, the generated files show latex formatting with
default quartz configuration.

Sidenote on `\_` escape by ox-hugo:

ox-hugo escapes, _ using \_, we match against it after we transform
equations into what quartz supports($$ and $).

This could be achieved using lookaround like regex as follows
```js
(?<=(\$|\$\$)[\s\S]*) -> Positive lookbehind for $ or $$
\\_ -> Matches \_
(?=[\s\S]*(?:\1)) Positive lookahead for $ or $$ if matched
const escapedUnderscoreRegex = new RegExp(/(?<=(\$|\$\$)[\s\S]*)\\_(?=[\s\S]*(?:\1))/, "g")
````

But since lookahead/behind can slow things down on large files, we just
look up all equations with $ and $$ delimiters and then try replacing \_
2 files modified
36 ■■■■■ changed files
docs/features/OxHugo compatibility.md 1 ●●●● diff | view | raw | blame | history
quartz/plugins/transformers/oxhugofm.ts 35 ●●●●● diff | view | raw | blame | history