diff --git a/packages/unified-latex-to-pretext/libs/pre-conversion-subs/environment-subs.ts b/packages/unified-latex-to-pretext/libs/pre-conversion-subs/environment-subs.ts index 0ff509ec..a4df3848 100644 --- a/packages/unified-latex-to-pretext/libs/pre-conversion-subs/environment-subs.ts +++ b/packages/unified-latex-to-pretext/libs/pre-conversion-subs/environment-subs.ts @@ -1,4 +1,4 @@ -import cssesc from "cssesc"; +// import cssesc from "cssesc"; import { parseTabularSpec, TabularColumn, @@ -14,6 +14,7 @@ import { match } from "@unified-latex/unified-latex-util-match"; import { printRaw } from "@unified-latex/unified-latex-util-print-raw"; import { wrapPars } from "../wrap-pars"; import { VisitInfo } from "@unified-latex/unified-latex-util-visit"; +import { trim } from "@unified-latex/unified-latex-util-trim"; const ITEM_ARG_NAMES_REG = ["label"] as const; const ITEM_ARG_NAMES_BEAMER = [null, "label", null] as const; @@ -48,7 +49,7 @@ function getItemArgs(node: Ast.Macro): ItemArgs { return ret as ItemArgs; } -function enumerateFactory(parentTag = "ol", className = "enumerate") { +function enumerateFactory(parentTag = "ol") { return function enumerateToHtml(env: Ast.Environment) { // The body of an enumerate has already been processed and all relevant parts have // been attached to \item macros as arguments. @@ -58,27 +59,45 @@ function enumerateFactory(parentTag = "ol", className = "enumerate") { return []; } - const attributes: Record> = - {}; + // const attributes: Record> = + // {}; + + const customMarker: Record = {}; + + // Figure out if there any manually-specified item labels. If there are, // we need to specify a custom list-style-type. // We test the open mark to see if an optional argument was actually supplied. const namedArgs = getItemArgs(node); + if (namedArgs.label != null) { - const formattedLabel = cssesc(printRaw(namedArgs.label || [])); - attributes.style = { - // Note the space after `formattedLabel`. That is on purpose! - "list-style-type": formattedLabel - ? `'${formattedLabel} '` - : "none", - }; + // parentTag = "dl" // can't do it here + const formattedLabel = printRaw(namedArgs.label || []) // cssesc(printRaw(namedArgs.label || [])); + // attributes.style = { + // // Note the space after `formattedLabel`. That is on purpose! + // "list-style-type": formattedLabel + // ? `'${formattedLabel} '` + // : "none", + // }; + console.log(formattedLabel) + // customMarker.marker = htmlLike({ + // tag: "title", + // content: namedArgs.label, + // // attributes, + // }) + // namedArgs.body = htmlLike({ + // tag: "title", + // content: namedArgs.label, + // // attributes, + // }) } const body = namedArgs.body; + console.log(namedArgs.body) return htmlLike({ tag: "li", content: wrapPars(body), - attributes, + // attributes, }); }); @@ -133,15 +152,18 @@ function createTableFromTabular(env: Ast.Environment) { styles["border-right"] = "1px solid"; } } + // trim whitespace off cell + trim(cell) + return htmlLike( Object.keys(styles).length > 0 ? { - tag: "cell", // cell -> td, + tag: "cell", content: cell, attributes: { style: styles }, } : { - tag: "cell", // cell -> td, + tag: "cell", content: cell, } ); @@ -177,7 +199,7 @@ export const environmentReplacements: Record< ) => Ast.Macro | Ast.String | Ast.Environment > = { enumerate: enumerateFactory("ol"), - itemize: enumerateFactory("ul", "itemize"), + itemize: enumerateFactory("ul"), center: createCenteredElement, tabular: createTableFromTabular, quote: (env) => { diff --git a/packages/unified-latex-to-pretext/libs/split-for-pars.ts b/packages/unified-latex-to-pretext/libs/split-for-pars.ts index 2d62ec5a..0f823810 100644 --- a/packages/unified-latex-to-pretext/libs/split-for-pars.ts +++ b/packages/unified-latex-to-pretext/libs/split-for-pars.ts @@ -50,11 +50,11 @@ export function splitForPars( continue; } // Display-math should always break pars - if (node.type === "displaymath") { - pushBody(); - ret.push({ content: [node], wrapInPar: false }); - continue; - } + // if (node.type === "displaymath") { + // pushBody(); + // ret.push({ content: [node], wrapInPar: true }); + // continue; + // } if (match.parbreak(node) || match.macro(node, "par")) { pushBody(); continue; 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 1faf3605..27487500 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 @@ -117,7 +117,7 @@ describe("unified-latex-to-pretext:unified-latex-to-pretext", () => { ); }); - it.skip("Converts enumerate environments", () => { + it("Converts enumerate environments", () => { html = process(`\\begin{enumerate}\\item a\\item b\\end{enumerate}`); expect(normalizeHtml(html)).toEqual( normalizeHtml(`
  1. a

  2. b

`) @@ -183,42 +183,21 @@ describe("unified-latex-to-pretext:unified-latex-to-pretext", () => { `
  • x)

    a

  • b

  • -
    ` + ` // list is centered though, @margins or @width in tabular could help tho + // width for how much space in marker so not helpful + // margins doesn't work for lists only tabulars ) ); }); - // \n in some tags for some reason, seems to come from normalizeHTML - it.skip("Converts tabular environment", () => { - // the spaces before or after each letter stay + it("Converts tabular environment", () => { html = process(`\\begin{tabular}{l l}a & b\\\\c & d\\end{tabular}`); + expect(normalizeHtml(html)).toEqual( - // normalizeHtml( - // ` - // - // - // - // - // - // - // - // - // - // - //
    ab
    cd
    ` - // ) + // centered tho + // can fix with margins="0%" normalizeHtml( - ` - - a - b - - - - c - d - - ` + `abcd` ) ); }); @@ -227,7 +206,7 @@ describe("unified-latex-to-pretext:unified-latex-to-pretext", () => { html = process(`\\begin{tabular}{r l}a & b\\\\c & d\\end{tabular}`); expect(normalizeHtml(html)).toEqual( // note: even though only one col is right aligned, need all cols - normalizeHtml( + // put all in single line once implemented ` @@ -240,7 +219,6 @@ describe("unified-latex-to-pretext:unified-latex-to-pretext", () => { d ` - ) ); }); @@ -295,14 +273,12 @@ describe("unified-latex-to-pretext:unified-latex-to-pretext", () => { ); }); - it.skip("Pars are broken at display math", () => { + it("Pars are broken at display math", () => { let ast; ast = process(`x\n\ny\\[a\\\\b\\]z`); expect(normalizeHtml(ast)).toEqual( - // block not wrapped by

    but should be - // likely needs to be added as an option in split-for-pars since type = displaymath isn't a macro or env - normalizeHtml(`

    x

    y

    a\\\\b

    z

    `) + normalizeHtml(`

    x

    ya\\\\bz

    `) ); }); it("replaces command inside argument", () => { @@ -330,6 +306,7 @@ describe("unified-latex-to-pretext:unified-latex-to-pretext", () => { ast = process(`\\paragraph{Important.} Paragraph`); expect(normalizeHtml(ast)).toEqual( + // should there be a or

    tag? normalizeHtml(` Important. Paragraph `)