Set multline rows flush to the margins
This commit is contained in:
1 parent
4edc951958
commit
29d363d47a
6 files changed
+209
-10
No files matched your search
+85
-4
@@ -2146,6 +2146,8 @@ struct SourceParagraph {
|
||||
right_skip: i64,
|
||||
/// Overrides the paragraph measure inside a `minipage` environment.
|
||||
width: Option<i64>,
|
||||
/// A `multline` display: rows share one equation number.
|
||||
multline: bool,
|
||||
}
|
||||
|
||||
/// The kind of a LaTeX float environment.
|
||||
@@ -2414,6 +2416,7 @@ fn paragraphs_with_spacing(
|
||||
if let Some(index) = table_reference(chunk) {
|
||||
result.push(SourceParagraph {
|
||||
width: None,
|
||||
multline: false,
|
||||
list_depth: None,
|
||||
list_label: 0,
|
||||
right_skip: 0,
|
||||
@@ -2600,6 +2603,7 @@ fn float_block(raw: &str) -> Option<SourceParagraph> {
|
||||
let table = embedded_table(inner);
|
||||
Some(SourceParagraph {
|
||||
width: None,
|
||||
multline: false,
|
||||
list_depth: None,
|
||||
list_label: 0,
|
||||
right_skip: 0,
|
||||
@@ -2923,6 +2927,7 @@ fn theorem_block(raw: &str, definitions: &[TheoremDefinition]) -> Option<Vec<Sou
|
||||
let theorem_title = if name == "proof" { None } else { title.clone() };
|
||||
let heading = SourceParagraph {
|
||||
width: None,
|
||||
multline: false,
|
||||
list_depth: None,
|
||||
list_label: 0,
|
||||
right_skip: 0,
|
||||
@@ -2963,6 +2968,7 @@ fn theorem_block(raw: &str, definitions: &[TheoremDefinition]) -> Option<Vec<Sou
|
||||
);
|
||||
let statement = SourceParagraph {
|
||||
width: None,
|
||||
multline: false,
|
||||
list_depth: None,
|
||||
list_label: 0,
|
||||
right_skip: 0,
|
||||
@@ -3264,6 +3270,7 @@ fn list_paragraph(
|
||||
let (before, stretch, shrink) = space.unwrap_or((0, 0, 0));
|
||||
SourceParagraph {
|
||||
width: None,
|
||||
multline: false,
|
||||
text,
|
||||
font: ParagraphFont::Roman,
|
||||
line_height: 12,
|
||||
@@ -3305,6 +3312,7 @@ fn verbatim_blocks(raw: &str) -> Option<Vec<SourceParagraph>> {
|
||||
let text = line.trim_end();
|
||||
blocks.push(SourceParagraph {
|
||||
width: None,
|
||||
multline: false,
|
||||
list_depth: None,
|
||||
list_label: 0,
|
||||
right_skip: 0,
|
||||
@@ -3456,6 +3464,7 @@ fn standalone_graphic(raw: &str) -> Option<SourceParagraph> {
|
||||
let (width, height, image, scale, keep_aspectratio) = figure_graphic(trimmed)?;
|
||||
Some(SourceParagraph {
|
||||
width: None,
|
||||
multline: false,
|
||||
list_depth: None,
|
||||
list_label: 0,
|
||||
right_skip: 0,
|
||||
@@ -3620,6 +3629,7 @@ fn parse_blocks_raw(
|
||||
{
|
||||
let heading = SourceParagraph {
|
||||
width: None,
|
||||
multline: false,
|
||||
list_depth: None,
|
||||
list_label: 0,
|
||||
right_skip: 0,
|
||||
@@ -3649,6 +3659,7 @@ fn parse_blocks_raw(
|
||||
};
|
||||
let body = SourceParagraph {
|
||||
width: None,
|
||||
multline: false,
|
||||
list_depth: None,
|
||||
list_label: 0,
|
||||
right_skip: 0,
|
||||
@@ -3746,6 +3757,7 @@ fn parse_blocks_raw(
|
||||
if !text.is_empty() {
|
||||
return vec![SourceParagraph {
|
||||
width: None,
|
||||
multline: false,
|
||||
list_depth: None,
|
||||
list_label: 0,
|
||||
text: text.to_string(),
|
||||
@@ -4755,6 +4767,40 @@ fn parse_paragraph(raw: &str) -> SourceParagraph {
|
||||
{
|
||||
return parse_paragraph(&format!("$$\n{}\n$$", inner));
|
||||
}
|
||||
for (environment, starred) in [("multline", false), ("multline*", true)] {
|
||||
let begin = format!("\\begin{{{environment}}}");
|
||||
let finish = format!("\\end{{{environment}}}");
|
||||
let Some(inner) = raw
|
||||
.strip_prefix(&begin)
|
||||
.and_then(|text| text.strip_suffix(&finish))
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
let lines: Vec<&str> = inner
|
||||
.split("\\\\")
|
||||
.map(str::trim)
|
||||
.filter(|row| !row.is_empty())
|
||||
.collect();
|
||||
let rows: Vec<EquationRow> = lines
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, row)| EquationRow {
|
||||
text: row.to_string(),
|
||||
number: if !starred && index + 1 == lines.len() {
|
||||
Some(0)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
tag: None,
|
||||
})
|
||||
.collect();
|
||||
let mut block = parse_paragraph(inner.trim());
|
||||
block.equation_rows = rows;
|
||||
block.multline = true;
|
||||
block.align_centered = false;
|
||||
block.math = true;
|
||||
return block;
|
||||
}
|
||||
for (environment, starred) in [("alignat", false), ("alignat*", true)] {
|
||||
let begin = format!("\\begin{{{environment}}}");
|
||||
let finish = format!("\\end{{{environment}}}");
|
||||
@@ -4813,6 +4859,7 @@ fn parse_paragraph(raw: &str) -> SourceParagraph {
|
||||
.collect();
|
||||
return SourceParagraph {
|
||||
width: None,
|
||||
multline: false,
|
||||
list_depth: None,
|
||||
list_label: 0,
|
||||
right_skip: 0,
|
||||
@@ -4845,6 +4892,7 @@ fn parse_paragraph(raw: &str) -> SourceParagraph {
|
||||
if let Some((font, font_size, body)) = nfss_font_with_size(raw, ParagraphFont::Roman) {
|
||||
return SourceParagraph {
|
||||
width: None,
|
||||
multline: false,
|
||||
list_depth: None,
|
||||
list_label: 0,
|
||||
right_skip: 0,
|
||||
@@ -4879,6 +4927,7 @@ fn parse_paragraph(raw: &str) -> SourceParagraph {
|
||||
{
|
||||
return SourceParagraph {
|
||||
width: None,
|
||||
multline: false,
|
||||
list_depth: None,
|
||||
list_label: 0,
|
||||
right_skip: 0,
|
||||
@@ -4913,6 +4962,7 @@ fn parse_paragraph(raw: &str) -> SourceParagraph {
|
||||
{
|
||||
return SourceParagraph {
|
||||
width: None,
|
||||
multline: false,
|
||||
list_depth: None,
|
||||
list_label: 0,
|
||||
right_skip: 0,
|
||||
@@ -4951,6 +5001,7 @@ fn parse_paragraph(raw: &str) -> SourceParagraph {
|
||||
{
|
||||
return SourceParagraph {
|
||||
width: None,
|
||||
multline: false,
|
||||
list_depth: None,
|
||||
list_label: 0,
|
||||
right_skip: 0,
|
||||
@@ -4982,6 +5033,7 @@ fn parse_paragraph(raw: &str) -> SourceParagraph {
|
||||
if let Some((level, starred, title, short)) = heading_command(raw) {
|
||||
return SourceParagraph {
|
||||
width: None,
|
||||
multline: false,
|
||||
list_depth: None,
|
||||
list_label: 0,
|
||||
right_skip: 0,
|
||||
@@ -5033,6 +5085,7 @@ fn parse_paragraph(raw: &str) -> SourceParagraph {
|
||||
if let Some(text) = command_body(raw, command) {
|
||||
return SourceParagraph {
|
||||
width: None,
|
||||
multline: false,
|
||||
list_depth: None,
|
||||
list_label: 0,
|
||||
right_skip: 0,
|
||||
@@ -5064,6 +5117,7 @@ fn parse_paragraph(raw: &str) -> SourceParagraph {
|
||||
}
|
||||
SourceParagraph {
|
||||
width: None,
|
||||
multline: false,
|
||||
list_depth: None,
|
||||
list_label: 0,
|
||||
right_skip: 0,
|
||||
@@ -5247,6 +5301,7 @@ fn clean_title_value(text: &str) -> String {
|
||||
fn title_block(text: String, size: f64, space_before: i64) -> SourceParagraph {
|
||||
SourceParagraph {
|
||||
width: None,
|
||||
multline: false,
|
||||
list_depth: None,
|
||||
list_label: 0,
|
||||
right_skip: 0,
|
||||
@@ -5620,6 +5675,7 @@ fn number_floats(
|
||||
fn bibliography_heading(text: &str) -> SourceParagraph {
|
||||
SourceParagraph {
|
||||
width: None,
|
||||
multline: false,
|
||||
list_depth: None,
|
||||
list_label: 0,
|
||||
right_skip: 0,
|
||||
@@ -5661,6 +5717,7 @@ fn append_bibliography(
|
||||
for (index, (_, entry)) in bibliography.iter().enumerate() {
|
||||
paragraphs.push(SourceParagraph {
|
||||
width: None,
|
||||
multline: false,
|
||||
list_depth: None,
|
||||
list_label: 0,
|
||||
right_skip: 0,
|
||||
@@ -5728,6 +5785,7 @@ fn expand_toc(paragraphs: &mut Vec<SourceParagraph>, tocdepth: u32, contents_nam
|
||||
for (level, number, text) in entries.iter() {
|
||||
toc.push(SourceParagraph {
|
||||
width: None,
|
||||
multline: false,
|
||||
list_depth: None,
|
||||
list_label: 0,
|
||||
right_skip: 0,
|
||||
@@ -5812,6 +5870,7 @@ fn expand_float_lists(
|
||||
for (prefix, text) in entries.iter() {
|
||||
list.push(SourceParagraph {
|
||||
width: None,
|
||||
multline: false,
|
||||
list_depth: None,
|
||||
list_label: 0,
|
||||
right_skip: 0,
|
||||
@@ -6021,7 +6080,19 @@ fn build_document(paragraphs: &[SourceParagraph], geometry: &PageGeometry) -> Do
|
||||
}
|
||||
if paragraph.math {
|
||||
let font = Cmr10Metrics::Math;
|
||||
let atom = if let Some(split_rows) = split_body_rows(¶graph.text) {
|
||||
let atom = if paragraph.multline {
|
||||
let rows: Vec<MathAtom> = paragraph
|
||||
.equation_rows
|
||||
.iter()
|
||||
.map(|row| parse_math(&row.text))
|
||||
.collect();
|
||||
let tag = paragraph.equation_rows.last().and_then(|row| {
|
||||
row.tag
|
||||
.clone()
|
||||
.or_else(|| row.number.map(|number| format!("({number})")))
|
||||
});
|
||||
MathAtom::Multline { rows, tag }
|
||||
} else if let Some(split_rows) = split_body_rows(¶graph.text) {
|
||||
let rows: Vec<AlignedRow> = split_rows
|
||||
.iter()
|
||||
.map(|row| {
|
||||
@@ -6488,6 +6559,7 @@ const SUPPORTED_ENVIRONMENTS: &[&str] = &[
|
||||
"cases",
|
||||
"split",
|
||||
"alignat",
|
||||
"multline",
|
||||
"matrix",
|
||||
"pmatrix",
|
||||
"bmatrix",
|
||||
@@ -7262,6 +7334,15 @@ mod source_tests {
|
||||
assert_eq!(geometry_counter(&geometry, "steps"), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multline_rows_share_one_number() {
|
||||
let json = preview_json("\\begin{multline}a + b \\\\ c + d \\\\ e\\end{multline}")
|
||||
.expect("multline preview");
|
||||
assert!(json.contains(">1</text>"), "{json}");
|
||||
assert!(json.contains(">e</text>"), "{json}");
|
||||
assert!(!json.contains("multline"), "{json}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn split_inside_equation_numbers_once() {
|
||||
let json = preview_json(
|
||||
@@ -7311,10 +7392,10 @@ mod source_tests {
|
||||
a &= b
|
||||
\end{align}
|
||||
|
||||
\[\begin{multline}
|
||||
\[\begin{eqnarray}
|
||||
x = 1 \\
|
||||
y = 2
|
||||
\end{multline}\]
|
||||
\end{eqnarray}\]
|
||||
|
||||
\begin{tabularx}{\textwidth}{lX}
|
||||
a & b
|
||||
@@ -7322,7 +7403,7 @@ a & b
|
||||
\end{document}";
|
||||
let json = preview_json(source).expect("preview");
|
||||
assert!(
|
||||
json.contains("unsupported environment `multline`"),
|
||||
json.contains("unsupported environment `eqnarray`"),
|
||||
"{json}"
|
||||
);
|
||||
assert!(
|
||||
|
||||
Reference in new issue
Block a user