Skip to content

Commit

Permalink
updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
renee-k committed Jun 28, 2024
1 parent 7fba2d7 commit 9f407ca
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { visit } from "@unified-latex/unified-latex-util-visit";

/**
* All the divisions, where each item is [division macro, environment]
* All the divisions, where each item is {division macro, mapped environment}
* Note that this is ordered from the "largest" division to the "smallest" division.
*/
const divisions: { division: string; mappedEnviron: string }[] = [
Expand All @@ -41,6 +41,26 @@ export function breakOnBoundaries(ast: Ast.Ast): { messages: string[] } {
divisions.map((x) => x.division)
);

// check if a node is a mapped environment
const isMappedEnviron = match.createMacroMatcher(
// *** not working
divisions.map((x) => x.mappedEnviron)
);

// first remove groups that contain a division as an immediate child
replaceNode(ast, (node) => {
if (match.group(node) && isDivision(node.content[0])) {
// push a warning message
messagesLst.messages.push(
`Warning: hoisted out of a group, which might break the LaTeX code. { group: ${printRaw(
node
)} }`
);

return node.content;
}
});

visit(ast, (node, info) => {
// needs to be an environment, root, or group node
if (
Expand All @@ -59,35 +79,21 @@ export function breakOnBoundaries(ast: Ast.Ast): { messages: string[] } {
anyEnvironment(node) &&
divisions.map((x) => x.mappedEnviron).includes(node.env)
) {
console.log("repeat");
return;
}

// if it's a group, push a warning message
if (match.group(node)) {
messagesLst.messages.push(
`Warning: hoisted out of a group, which might break the LaTeX code. { group: ${printRaw(
node
)} }`
);
}

// now break up the divisions, starting at part
node.content = breakUp(node.content, 0);
});

// remove all old division nodes
replaceNode(ast, (node) => {
// remove all old division nodes
if (anyMacro(node) && isDivision(node)) {
return null;
}
// remove groups
else if (match.group(node)) {
return node.content;
}
});

console.log(messagesLst);

return messagesLst;
}

Expand All @@ -109,7 +115,7 @@ function breakUp(content: Ast.Node[], depth: number): Ast.Node[] {

createEnvironments(splits, divisions[depth].mappedEnviron);

// rebuild this part of the ast
// rebuild this part of the AST
return unsplitOnMacro(splits);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe("unified-latex-to-pretext:break-on-boundaries", () => {
String.raw`Warning: hoisted out of a group, which might break the LaTeX code. ` +
String.raw`{ group: {\subsection{Intro}description.\subsubsection{body}more text.{\subparagraph{Conclusion}Conclusion.}} }`,
String.raw`Warning: hoisted out of a group, which might break the LaTeX code. ` +
String.raw`{ group: {\subparagraph{Conclusion}Conclusion.} }`,
String.raw`{ group: {\subparagraph{Conclusion}Conclusion.} }`, // ** Doesn't keep nested group
],
});

Expand Down Expand Up @@ -146,7 +146,7 @@ describe("unified-latex-to-pretext:break-on-boundaries", () => {
expect(breakOnBoundaries(ast)).toEqual({ messages: [] });

expect(printRaw(ast)).toEqual(
String.raw`\begin{_subsubsection}[first]subsection 1` +
String.raw`\begin{_subsubsection}[first]subsection 1 ` +
String.raw`\begin{_paragraph}[body]This is paragraph` +
String.raw`\end{_paragraph}\end{_subsubsection}`
);
Expand Down

0 comments on commit 9f407ca

Please sign in to comment.