Split wide display formulas into lines
This commit is contained in:
1 parent
95e677b5c7
commit
c9ad1e209a
6 files changed
+103
-10
No files matched your search
+25
-6
@@ -10,7 +10,7 @@ use std::fmt::Write as _;
|
||||
use std::sync::{Mutex, OnceLock};
|
||||
|
||||
use texrra_tex_core::cmr10::Cmr10Metrics;
|
||||
use texrra_tex_core::math::parse_math;
|
||||
use texrra_tex_core::math::{parse_math, split_math_lines};
|
||||
use texrra_tex_core::pdf::{PageOrigin, display_lists_to_pdf_with_paper};
|
||||
use texrra_tex_core::{Document, Engine, ParagraphFont, ParagraphStyle, Unit};
|
||||
|
||||
@@ -925,11 +925,10 @@ fn build_document(paragraphs: &[SourceParagraph], geometry: &PageGeometry) -> Do
|
||||
}
|
||||
}
|
||||
if paragraph.math {
|
||||
let mut unit = Unit::math(
|
||||
index as u64,
|
||||
parse_math(¶graph.text),
|
||||
&Cmr10Metrics::default(),
|
||||
);
|
||||
let font = Cmr10Metrics::default();
|
||||
let atom = parse_math(¶graph.text);
|
||||
let lines = split_math_lines(&atom, &font, 480 * SCALE);
|
||||
let mut unit = Unit::math_lines(index as u64, &lines, &font);
|
||||
unit.space_before = paragraph.space_before;
|
||||
unit.space_stretch = paragraph.space_stretch;
|
||||
unit.space_shrink = paragraph.space_shrink;
|
||||
@@ -1066,6 +1065,26 @@ fn escape_json(value: &str) -> String {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn display_math_is_split_to_the_measure() {
|
||||
let mut formula = String::from("$$");
|
||||
for index in 0..80 {
|
||||
if index > 0 {
|
||||
formula.push_str(" + ");
|
||||
}
|
||||
formula.push('x');
|
||||
}
|
||||
formula.push_str(" = z$$");
|
||||
let (body, geometry) = geometry_and_body(&formula);
|
||||
let paragraphs = paragraphs(&body).unwrap();
|
||||
let document = build_document(¶graphs, &geometry);
|
||||
assert!(
|
||||
document.units[0].items.len() > 1,
|
||||
"items={}",
|
||||
document.units[0].items.len()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn engine_template_keeps_paragraph_columns() {
|
||||
assert_eq!(engine_template("{|l|c|p{3cm}|}"), "lcp{3cm}");
|
||||
|
||||
Reference in new issue
Block a user