Start equation numbering from setcounter values
This commit is contained in:
1 parent
2640884721
commit
d379d941bb
4 files changed
+49
-11
No files matched your search
+45
-7
@@ -59,7 +59,11 @@ pub fn project_preview_json_with_images(
|
||||
) -> Result<String, String> {
|
||||
let (body, mut geometry) = geometry_and_body(source);
|
||||
geometry.images = images.clone();
|
||||
let paragraphs = paragraphs_with_definitions(&body, &geometry.theorem_definitions)?;
|
||||
let paragraphs = paragraphs_with_counters(
|
||||
&body,
|
||||
&geometry.theorem_definitions,
|
||||
geometry_counter(&geometry, "equation"),
|
||||
)?;
|
||||
let mut document = build_document(¶graphs, &geometry);
|
||||
apply_geometry(&mut document, &geometry);
|
||||
let mut sessions = project_sessions()
|
||||
@@ -1702,7 +1706,11 @@ fn layout_document(document: &Document) -> Engine {
|
||||
/// Build a JSON preview from blank-line-separated plain-text paragraphs.
|
||||
pub fn preview_json(source: &str) -> Result<String, String> {
|
||||
let (body, geometry) = geometry_and_body(source);
|
||||
let paragraphs = paragraphs_with_definitions(&body, &geometry.theorem_definitions)?;
|
||||
let paragraphs = paragraphs_with_counters(
|
||||
&body,
|
||||
&geometry.theorem_definitions,
|
||||
geometry_counter(&geometry, "equation"),
|
||||
)?;
|
||||
let mut document = build_document(¶graphs, &geometry);
|
||||
apply_geometry(&mut document, &geometry);
|
||||
let engine = layout_document(&document);
|
||||
@@ -1727,7 +1735,11 @@ pub fn pdf_bytes_with_images(
|
||||
) -> Result<Vec<u8>, String> {
|
||||
let (body, mut geometry) = geometry_and_body(source);
|
||||
geometry.images = images.clone();
|
||||
let paragraphs = paragraphs_with_definitions(&body, &geometry.theorem_definitions)?;
|
||||
let paragraphs = paragraphs_with_counters(
|
||||
&body,
|
||||
&geometry.theorem_definitions,
|
||||
geometry_counter(&geometry, "equation"),
|
||||
)?;
|
||||
let mut document = build_document(¶graphs, &geometry);
|
||||
apply_geometry(&mut document, &geometry);
|
||||
let engine = layout_document(&document);
|
||||
@@ -1754,7 +1766,11 @@ pub fn pdf_bytes_with_images(
|
||||
/// checkpoints that were reused versus rebuilt.
|
||||
pub fn edit_json(source: &str, unit: usize) -> Result<String, String> {
|
||||
let (body, geometry) = geometry_and_body(source);
|
||||
let paragraphs = paragraphs_with_definitions(&body, &geometry.theorem_definitions)?;
|
||||
let paragraphs = paragraphs_with_counters(
|
||||
&body,
|
||||
&geometry.theorem_definitions,
|
||||
geometry_counter(&geometry, "equation"),
|
||||
)?;
|
||||
if unit >= paragraphs.len() {
|
||||
return Err(format!(
|
||||
"unit {unit} is out of range for {} paragraphs",
|
||||
@@ -1993,6 +2009,14 @@ fn paragraphs(source: &str) -> Result<Vec<SourceParagraph>, String> {
|
||||
fn paragraphs_with_definitions(
|
||||
source: &str,
|
||||
definitions: &[TheoremDefinition],
|
||||
) -> Result<Vec<SourceParagraph>, String> {
|
||||
paragraphs_with_counters(source, definitions, 0)
|
||||
}
|
||||
|
||||
fn paragraphs_with_counters(
|
||||
source: &str,
|
||||
definitions: &[TheoremDefinition],
|
||||
equation_start: u32,
|
||||
) -> Result<Vec<SourceParagraph>, String> {
|
||||
let paragraphs: Vec<&str> = source
|
||||
.split("\n\n")
|
||||
@@ -2057,7 +2081,7 @@ fn paragraphs_with_definitions(
|
||||
}
|
||||
result.extend(blocks);
|
||||
}
|
||||
resolve_equation_numbers(&mut result);
|
||||
resolve_equation_numbers(&mut result, equation_start);
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
@@ -2068,8 +2092,8 @@ fn command_body<'a>(text: &'a str, command: &str) -> Option<&'a str> {
|
||||
}
|
||||
|
||||
/// Assign equation numbers in source order and substitute label references.
|
||||
fn resolve_equation_numbers(blocks: &mut [SourceParagraph]) {
|
||||
let mut number = 0;
|
||||
fn resolve_equation_numbers(blocks: &mut [SourceParagraph], equation_start: u32) {
|
||||
let mut number = equation_start;
|
||||
let mut labels: Vec<(String, String)> = Vec::new();
|
||||
for block in blocks.iter_mut() {
|
||||
if !block.math {
|
||||
@@ -6575,6 +6599,20 @@ A definition.
|
||||
assert_eq!(document.units[0].source, "5 Intro");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn setcounter_offsets_equation_numbers() {
|
||||
let source = "\\setcounter{equation}{2}\n\n\\begin{equation}\nx = 1\n\\end{equation}";
|
||||
let (body, geometry) = geometry_and_body(source);
|
||||
assert_eq!(geometry_counter(&geometry, "equation"), 2);
|
||||
let paragraphs = paragraphs_with_counters(
|
||||
&body,
|
||||
&geometry.theorem_definitions,
|
||||
geometry_counter(&geometry, "equation"),
|
||||
)
|
||||
.expect("blocks");
|
||||
assert_eq!(paragraphs[0].equation_number, Some(3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn float_list_names_follow_renewcommand() {
|
||||
let source = "\\renewcommand{\\listfigurename}{Abbildungen}\n\n\\renewcommand{\\listtablename}{Tabellen}\n\n\\listoffigures\n\n\\begin{figure}\n\\caption{Plot}\n\\end{figure}\n\n\\listoftables\n\n\\begin{table}\n\\begin{tabular}{l}\nA\n\\end{tabular}\n\\caption{Numbers}\n\\end{table}";
|
||||
|
||||
Reference in new issue
Block a user