From 5c599855792ac2aeb375bb6ffb07021baaefcb7c Mon Sep 17 00:00:00 2001 From: Nahlee Naria Khan <95993773+renee-k@users.noreply.github.com> Date: Sun, 11 Aug 2024 20:22:42 -0400 Subject: [PATCH] changed structure of to pretext plugin --- .../libs/unified-latex-plugin-to-pretext.ts | 23 ++++++++++--------- .../tests/unified-latex-to-pretext.test.ts | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/unified-latex-to-pretext/libs/unified-latex-plugin-to-pretext.ts b/packages/unified-latex-to-pretext/libs/unified-latex-plugin-to-pretext.ts index fd6f0a3..8bfa323 100644 --- a/packages/unified-latex-to-pretext/libs/unified-latex-plugin-to-pretext.ts +++ b/packages/unified-latex-to-pretext/libs/unified-latex-plugin-to-pretext.ts @@ -11,7 +11,7 @@ import { unifiedLatexToXmlLike, PluginOptions as HtmlLikePluginOptions, } from "./unified-latex-plugin-to-xml-like"; -import { printRaw } from "@unified-latex/unified-latex-util-print-raw"; +import { expandUserDefinedMacros } from "./pre-conversion-subs/expand-user-defined-macros"; export type PluginOptions = HtmlLikePluginOptions & { /** @@ -34,19 +34,11 @@ export const unifiedLatexToPretext: Plugin< ? options?.producePretextFragment : false; - // bring expandmacros in here instead - // getting authorinfo would be in here too - - unified().use(unifiedLatexToXmlLike, options).run(tree, file); - - // This should happen right before converting to HTML because macros like `\&` should - // be expanded via html rules first (and not turned into their corresponding ligature directly) - expandUnicodeLigatures(tree); + // expand user defined macros + expandUserDefinedMacros(tree); // If there is a \begin{document}...\end{document}, that's the only // content we want to convert. - // *move this to before xmllike called - // after done do tree.content = content (content in document env) let content = tree.content; visit( tree, @@ -65,6 +57,15 @@ export const unifiedLatexToPretext: Plugin< tree.content = content; + unified().use(unifiedLatexToXmlLike, options).run(tree, file); + + // This should happen right before converting to HTML because macros like `\&` should + // be expanded via html rules first (and not turned into their corresponding ligature directly) + expandUnicodeLigatures(tree); + + // update content + content = tree.content; + const toHast = toPretextWithLoggerFactory(file.message.bind(file)); let converted = toHast({ type: "root", content }); if (!Array.isArray(converted)) { diff --git a/packages/unified-latex-to-pretext/tests/unified-latex-to-pretext.test.ts b/packages/unified-latex-to-pretext/tests/unified-latex-to-pretext.test.ts index 9835c82..43634bc 100644 --- a/packages/unified-latex-to-pretext/tests/unified-latex-to-pretext.test.ts +++ b/packages/unified-latex-to-pretext/tests/unified-latex-to-pretext.test.ts @@ -218,7 +218,7 @@ describe("unified-latex-to-pretext:unified-latex-to-pretext", () => { ); html = process(`a\n b\\begin{foo}x\\end{foo}c\n\nd`); expect(normalizeHtml(html)).toEqual( - normalizeHtml(`

a b

x

c

d

`) + normalizeHtml(`

a b

x

c

d

`) // Need to fix, since foo isn't an env in pretext and no div ); });