Generate table of contents and figure/table lists

This commit is contained in:
gloamxun committed 2026-10-19 14:01:35 +08:00
1 parent 477e2124c8
commit 4aa1714923
11 files changed
+353 -29

No files matched your search

+63
View File
@@ -788,3 +788,66 @@ Body text.
);
}
}
#[test]
fn table_of_contents_lists_numbered_sections_and_pages() {
let source = r"\documentclass{article}
\begin{document}
\tableofcontents
\section{Alpha section}
Alpha paragraph.
\newpage
\section{Beta section}
Beta paragraph.
\end{document}";
let value = fresh_preview(source, "contents.tex");
assert_eq!(value["status"], "ok", "{value}");
assert_eq!(pages(&value).len(), 2, "{value}");
let svg = page_svg(&value, 0);
eprintln!("{svg}");
assert!(svg.contains(">Contents</text>"), "missing contents heading");
assert!(svg.contains(">Alpha</text>"), "missing first entry");
assert!(svg.contains(">Beta</text>"), "missing second entry");
assert!(svg.contains(">1</text>"), "missing first page number");
assert!(svg.contains(">2</text>"), "missing second page number");
}
#[test]
fn list_of_tables_lists_captions_and_pages() {
let source = r"\documentclass{article}
\begin{document}
\listoftables
\begin{table}[h]
\caption{First table}
\begin{tabular}{ll}
A & B \\
\end{tabular}
\end{table}
\end{document}";
let value = fresh_preview(source, "lot.tex");
assert_eq!(value["status"], "ok", "{value}");
let svg = page_svg(&value, 0);
assert!(svg.contains(">List</text>"), "missing list heading");
assert!(svg.contains(">of</text>"), "missing tables heading word");
assert!(svg.contains(">ables</text>"), "missing tables word");
assert!(svg.contains(">First</text>"), "missing caption entry");
assert!(svg.contains(">1</text>"), "missing page number");
}
#[test]
fn list_of_figures_lists_captions_and_pages() {
let source = r"\documentclass{article}
\begin{document}
\listoffigures
\begin{figure}[h]
\includegraphics[width=20mm]{examples/plot.png}
\caption{First figure}
\end{figure}
\end{document}";
let value = fresh_preview(source, "lof.tex");
assert_eq!(value["status"], "ok", "{value}");
let svg = page_svg(&value, 0);
assert!(svg.contains(">List</text>"), "missing list heading");
assert!(svg.contains(">of</text>"), "missing figures heading word");
assert!(svg.contains(">First</text>"), "missing caption entry");
}