Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added LaTeX to PreTeXt Plugin to the CLI package #113

Merged
merged 74 commits into from
Aug 20, 2024
Merged
Changes from 1 commit
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
3a85c98
added math mode macro report function and test file
renee-k May 25, 2024
0c1971a
updated report unsupported katex and expand command files
renee-k May 26, 2024
a140ea3
added more tests to be implemented
renee-k May 26, 2024
575141d
implemented expand macros tests and function
renee-k May 28, 2024
2711765
formatted code
renee-k May 29, 2024
a450ac1
addressed some katex related comments
renee-k May 30, 2024
bd2f4d5
added more tests
renee-k May 31, 2024
76352c5
removed uneeded variable
renee-k Jun 4, 2024
6f6221a
revised tests
renee-k Jun 5, 2024
b55e08c
revised some test descriptions
renee-k Jun 5, 2024
49e25bc
fixed expand userdefined macros
renee-k Jun 5, 2024
577d1be
addressed more PR comments
renee-k Jun 8, 2024
7648bc7
moved files to pre-conversion-subs
renee-k Jun 9, 2024
80fce28
edited docstrings
renee-k Jun 12, 2024
8383767
Merge branch 'main' into pretext
renee-k Jun 12, 2024
c5cea44
Merge branch 'siefkenj:pretext' into pretext
renee-k Jun 26, 2024
a0439b6
modified some test cases
renee-k Jul 3, 2024
537c71b
Merge branch 'pretext' of https://github.com/renee-k/unified-latex in…
renee-k Jul 3, 2024
97f3b2b
fixed a failed test case
renee-k Jul 4, 2024
9d0c2da
added boolean to the plugins
renee-k Jul 6, 2024
24008c6
updated a few more test cases
renee-k Jul 6, 2024
78a9463
modified plugins to include new boolean
renee-k Jul 9, 2024
0809260
added another tabular test
renee-k Jul 9, 2024
7c9e262
looked into all skipped test cases
renee-k Jul 10, 2024
02b525a
added comments for cases to fix later
renee-k Jul 11, 2024
03966d2
unskipped some test cases
renee-k Jul 12, 2024
a522c4f
changed tags for displaymath and tabular
renee-k Jul 16, 2024
fd21bae
fixed a couple more test cases
renee-k Jul 22, 2024
09c711e
fixed xml like test cases
renee-k Jul 24, 2024
dae8baf
began fixing enumerate
renee-k Jul 24, 2024
b6cce1e
Merge branch 'siefkenj:pretext' into pretext
renee-k Jul 24, 2024
37c55b6
fixed all list related test cases
renee-k Jul 26, 2024
46a4001
implemented support for tabular borders
renee-k Jul 27, 2024
7803f0f
corrected most subs
renee-k Jul 28, 2024
034d58d
added new functions into the xml plugin
renee-k Jul 28, 2024
8a8fbd5
fixed a list related test case
renee-k Jul 28, 2024
bd41f2e
Merge branch 'pretext' into pretext-xml-plugin
renee-k Jul 28, 2024
1a39d75
started adding in mandatory pretext tags
renee-k Jul 30, 2024
adef778
removed unneeded imports
renee-k Jul 30, 2024
7565f7b
Merge branch 'pretext' into pretext-xml-plugin
renee-k Jul 30, 2024
414dcda
added new plugin option to every test file
renee-k Jul 30, 2024
f1ca69c
Merge branch 'pretext' into pretext-xml-plugin
renee-k Jul 30, 2024
e5229d0
added option to one more test file
renee-k Jul 30, 2024
d3b0b6b
Merge branch 'pretext' into pretext-xml-plugin
renee-k Jul 30, 2024
31726e5
fixed unskipped test case to be proper pretext output
renee-k Jul 30, 2024
3759e35
Merge branch 'pretext' into pretext-xml-plugin
renee-k Jul 30, 2024
4d1594f
changed order of function calls in xml plugin
renee-k Jul 31, 2024
18821c3
fixed tabular code
renee-k Jul 31, 2024
eae1fc8
added vfile to xmllike plugin
renee-k Jul 31, 2024
155b07f
added vfile import
renee-k Jul 31, 2024
62b4511
made functions to create a valid document
renee-k Aug 2, 2024
2be12ad
changed return of report unsupported macros by katex to VMessages
renee-k Aug 3, 2024
d2da32f
Merge branch 'pretext' into pretext-xml-plugin
renee-k Aug 3, 2024
491f409
added function that creates an empty string node
renee-k Aug 4, 2024
295a6db
added function warnings to VFile
renee-k Aug 4, 2024
d7f9277
added warnings to VFile for no equivalent pretext tags
renee-k Aug 4, 2024
83fd352
fixed warning message positions being null
renee-k Aug 5, 2024
c64b1f8
added title tag to valid pretext doc
renee-k Aug 5, 2024
603539e
cleaned up code
renee-k Aug 7, 2024
6ec2e43
fixed one test case
renee-k Aug 7, 2024
9ae7ee3
addressed some PR comments
renee-k Aug 9, 2024
14a005c
moved some functions into utils file
renee-k Aug 10, 2024
b5cfa21
added new file for creating tabular
renee-k Aug 11, 2024
11a5182
fixed bug in to pretext file
renee-k Aug 11, 2024
5c59985
changed structure of to pretext plugin
renee-k Aug 12, 2024
1fe0c37
fixed comments using html to using pretext
renee-k Aug 12, 2024
3ae132c
cleaned up code
renee-k Aug 13, 2024
6737ed3
fixed last test case and removed only center env
renee-k Aug 14, 2024
a09daa9
changed div and span fallbacks
renee-k Aug 14, 2024
d5b50f9
cleaned up code again
renee-k Aug 15, 2024
c359495
fixed all new PR comments
renee-k Aug 15, 2024
e09f4cc
Merge branch 'siefkenj:pretext' into pretext
renee-k Aug 16, 2024
7d3445a
started adding pretext package to cli
renee-k Aug 16, 2024
f92419e
fixed import
renee-k Aug 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed all new PR comments
renee-k committed Aug 15, 2024
commit c359495e02f6a0468533dca045901aa7a40ad3dc
Original file line number Diff line number Diff line change
@@ -92,7 +92,6 @@ function enumerateFactory(parentTag = "ol") {
}

/**
*
* Remove the env environment by returning the content in env only.
*/
function removeEnv(env: Ast.Environment, info: VisitInfo, file?: VFile) {
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import { getArgsContent } from "@unified-latex/unified-latex-util-arguments";
import { printRaw } from "@unified-latex/unified-latex-util-print-raw";
import { VisitInfo } from "@unified-latex/unified-latex-util-visit";
import { VFile } from "unified-lint-rule/lib";
import { makeWarningMessage, emptyStringWithWarning } from "./utils";
import { makeWarningMessage, emptyStringWithWarningFactory } from "./utils";

/**
* Factory function that generates html-like macros that wrap their contents.
@@ -88,13 +88,11 @@ export const macroReplacements: Record<
"em",
`Warning: There is no equivalent tag for \"underline\", \"em\" was used as a replacement.`
),
mbox: emptyStringWithWarning(
`Warning: There is no equivalent tag for \"mbox\", an empty Ast.String was used as a replacement.`,
"macro-subs"
mbox: emptyStringWithWarningFactory(
`Warning: There is no equivalent tag for \"mbox\", an empty Ast.String was used as a replacement.`
),
phantom: emptyStringWithWarning(
`Warning: There is no equivalent tag for \"phantom\", an empty Ast.String was used as a replacement.`,
"macro-subs"
phantom: emptyStringWithWarningFactory(
`Warning: There is no equivalent tag for \"phantom\", an empty Ast.String was used as a replacement.`
),
appendix: createHeading("appendix"),
url: (node) => {
@@ -130,33 +128,27 @@ export const macroReplacements: Record<
content: args[1] || [],
});
},
"\\": emptyStringWithWarning(
`Warning: There is no equivalent tag for \"\\\", an empty Ast.String was used as a replacement.`,
"macro-subs"
"\\": emptyStringWithWarningFactory(
`Warning: There is no equivalent tag for \"\\\", an empty Ast.String was used as a replacement.`
),
vspace: emptyStringWithWarning(
`Warning: There is no equivalent tag for \"vspace\", an empty Ast.String was used as a replacement.`,
"macro-subs"
vspace: emptyStringWithWarningFactory(
`Warning: There is no equivalent tag for \"vspace\", an empty Ast.String was used as a replacement.`
),
hspace: emptyStringWithWarning(
`Warning: There is no equivalent tag for \"hspace\", an empty Ast.String was used as a replacement.`,
"macro-subs"
hspace: emptyStringWithWarningFactory(
`Warning: There is no equivalent tag for \"hspace\", an empty Ast.String was used as a replacement.`
),
textcolor: factory(
"em",
`Warning: There is no equivalent tag for \"textcolor\", \"em\" was used as a replacement.`
),
textsize: emptyStringWithWarning(
`Warning: There is no equivalent tag for \"textsize\", an empty Ast.String was used as a replacement.`,
"macro-subs"
textsize: emptyStringWithWarningFactory(
`Warning: There is no equivalent tag for \"textsize\", an empty Ast.String was used as a replacement.`
),
makebox: emptyStringWithWarning(
`Warning: There is no equivalent tag for \"makebox\", an empty Ast.String was used as a replacement.`,
"macro-subs"
), // remove for now
noindent: emptyStringWithWarning(
`Warning: There is no equivalent tag for \"noindent\", an empty Ast.String was used as a replacement.`,
"macro-subs"
makebox: emptyStringWithWarningFactory(
`Warning: There is no equivalent tag for \"makebox\", an empty Ast.String was used as a replacement.`
),
noindent: emptyStringWithWarningFactory(
`Warning: There is no equivalent tag for \"noindent\", an empty Ast.String was used as a replacement.`
),
includegraphics: (node) => {
const args = getArgsContent(node);
Original file line number Diff line number Diff line change
@@ -10,11 +10,11 @@ import { VFileMessage } from "vfile-message";
export function makeWarningMessage(
node: Ast.Node,
message: string,
sourceFile: string
warningType: string
): VFileMessage {
const newMessage = new VFileMessage(message, node);

newMessage.source = `unified-latex-to-pretext:${sourceFile}`;
newMessage.source = `unified-latex-to-pretext:${warningType}`;

return newMessage;
}
@@ -23,22 +23,21 @@ export function makeWarningMessage(
* Create an empty Ast.String node, adding a warning message from
* the source file into the VFile.
*/
export function emptyStringWithWarning(
warningMessage: string,
sourceFile: string
export function emptyStringWithWarningFactory(
warningMessage: string
): (node: Ast.Node, info: VisitInfo, file?: VFile) => Ast.String {
return (node, info, file) => {
// add a warning message
if (file) {
const message = makeWarningMessage(
node,
warningMessage,
sourceFile
"macro-subs"
);
file.message(
message,
message.position,
`unified-latex-to-pretext:${sourceFile}`
`unified-latex-to-pretext:macro-subs`
);
}

Original file line number Diff line number Diff line change
@@ -113,9 +113,16 @@ export function toPretextWithLoggerFactory(
// create a title tag containing the division macro's title arg
const title = getArgsContent(node)[0];

if (!title) {
logger(
`Warning: No title was given, so an empty title tag was used.`,
node
);
}

const titleTag = x("title", title?.flatMap(toPretext));

if (divisionName && title) {
if (divisionName) {
return x(divisionName, [
titleTag,
...node.content.flatMap(toPretext),
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ export type PluginOptions = {
*
* Note: this plugin only wraps paragraphs in `p` tags if there are multiple paragraphs. Otherwise it omits the <p> tags.
*/
export const unifiedLatexToXmlLike: Plugin<
export const unifiedLatexToPretextLike: Plugin<
PluginOptions[],
Ast.Root,
Hast.Root
Original file line number Diff line number Diff line change
@@ -8,9 +8,9 @@ import { match } from "@unified-latex/unified-latex-util-match";
import { EXIT, visit } from "@unified-latex/unified-latex-util-visit";
import { toPretextWithLoggerFactory } from "./pretext-subs/to-pretext";
import {
unifiedLatexToXmlLike,
unifiedLatexToPretextLike,
PluginOptions as HtmlLikePluginOptions,
} from "./unified-latex-plugin-to-xml-like";
} from "./unified-latex-plugin-to-pretext-like";
import { expandUserDefinedMacros } from "./pre-conversion-subs/expand-user-defined-macros";

export type PluginOptions = HtmlLikePluginOptions & {
@@ -58,7 +58,7 @@ export const unifiedLatexToPretext: Plugin<
// since we don't want to wrap content outside of \begin{document}...\end{document} with <pretext>...</pretext>
tree.content = content;

unified().use(unifiedLatexToXmlLike, options).run(tree, file);
unified().use(unifiedLatexToPretextLike, options).run(tree, file);

// This should happen right before converting to PreTeXt because macros like `\&` should
// be expanded via html rules first (and not turned into their corresponding ligature directly)
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { describe, it, expect } from "vitest";
import { processLatexViaUnified } from "@unified-latex/unified-latex";
import { VFile } from "vfile";
import util from "util";
import { unifiedLatexToXmlLike } from "../libs/unified-latex-plugin-to-xml-like";
import { unifiedLatexToPretextLike } from "../libs/unified-latex-plugin-to-pretext-like";
import { htmlLike } from "@unified-latex/unified-latex-util-html-like";
import { printRaw } from "@unified-latex/unified-latex-util-print-raw";

@@ -18,7 +18,7 @@ describe("unified-latex-to-pretext:unified-latex-to-xml-like", () => {
let file: VFile;
const process = (value: string) =>
processLatexViaUnified()
.use(unifiedLatexToXmlLike, { producePretextFragment: true })
.use(unifiedLatexToPretextLike, { producePretextFragment: true })
.processSync({ value });

it("wrap pars and streaming commands", () => {
@@ -46,7 +46,7 @@ describe("unified-latex-to-pretext:unified-latex-to-xml-like", () => {
it("can accept custom replacers", () => {
const process = (value: string) =>
processLatexViaUnified({ macros: { xxx: { signature: "m m" } } })
.use(unifiedLatexToXmlLike, {
.use(unifiedLatexToPretextLike, {
macroReplacements: {
xxx: (node) =>
htmlLike({