Skip to content

Commit 236cb11

Browse files
committed
More aggressively detect end longtable
1 parent ab326e0 commit 236cb11

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/format/pdf/format-pdf.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,11 +659,23 @@ const processLongTableSidenotes = (latexLongTable: string) => {
659659
strOutput.push(remainingStr);
660660
}
661661
}
662-
strOutput.push(strProcessing);
663662

663+
// Ensure that we inject sidenotes after the longtable
664+
const endTable = "\\end{longtable}";
665+
const endPos = strProcessing.indexOf(endTable);
666+
const prefix = strProcessing.substring(0, endPos + endTable.length);
667+
const suffix = strProcessing.substring(
668+
endPos + endTable.length,
669+
strProcessing.length,
670+
);
671+
672+
strOutput.push(prefix);
664673
for (const note of sidenotes) {
665674
strOutput.push(`\\sidenotetext{${note}}\n`);
666675
}
676+
if (suffix) {
677+
strOutput.push(suffix);
678+
}
667679

668680
return strOutput.join("");
669681
};
@@ -683,7 +695,7 @@ const longTableSidenoteProcessor = () => {
683695
}
684696
case "capturing":
685697
capturedLines.push(line);
686-
if (line.match(/[^\\n]\\end{longtable}.*$/)) {
698+
if (line.match(/\\end{longtable}/)) {
687699
state = "scanning";
688700

689701
// read the whole figure and clear any capture state

0 commit comments

Comments
 (0)