Accept table position options and row separator gaps
This commit is contained in:
1 parent
18c0288db0
commit
8bd725e9ff
5 files changed
+76
-5
No files matched your search
@@ -70,6 +70,38 @@ pub struct HalignRule {
|
||||
pub trim_right: i64,
|
||||
}
|
||||
|
||||
/// Scan a TeX dimension such as `6pt` or `1.5ex` at the start of `text`.
|
||||
fn scan_dimension(text: &str) -> Option<(i64, &str)> {
|
||||
let text = text.trim_start();
|
||||
let end = text
|
||||
.find(|character: char| !(character.is_ascii_digit() || character == '.'))
|
||||
.unwrap_or(text.len());
|
||||
if end == 0 {
|
||||
return None;
|
||||
}
|
||||
let value: f64 = text[..end].parse().ok()?;
|
||||
let rest = &text[end..];
|
||||
let units = [
|
||||
("pt", 65_536.0_f64),
|
||||
("bp", 7227.0 / 7200.0 * 65_536.0),
|
||||
("in", 4_736_286.0),
|
||||
("cm", 1_864_679.0),
|
||||
("mm", 186_468.0),
|
||||
("pc", 786_432.0),
|
||||
("dd", 70_124.0),
|
||||
("cc", 841_489.0),
|
||||
("em", 655_360.0),
|
||||
("ex", 327_680.0),
|
||||
("sp", 1.0),
|
||||
];
|
||||
for (unit, factor) in units {
|
||||
if let Some(after) = rest.strip_prefix(unit) {
|
||||
return Some(((value * factor).round() as i64, after));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn split_halign_cells(row: &str) -> Vec<&str> {
|
||||
let mut cells = Vec::new();
|
||||
let mut depth = 0usize;
|
||||
@@ -1109,6 +1141,13 @@ impl Unit {
|
||||
take_booktabs_rules(raw_row.trim(), rows.len(), column_count);
|
||||
rules.extend(collected);
|
||||
let mut raw_row = rule_text.trim();
|
||||
if let Some(after) = raw_row.strip_prefix('[')
|
||||
&& let Some((value, tail)) = after.split_once(']')
|
||||
&& let Some((gap, _)) = scan_dimension(value)
|
||||
{
|
||||
pending_gap += gap;
|
||||
raw_row = tail.trim();
|
||||
}
|
||||
if let Some(rest) = raw_row.strip_prefix(r"\noalign") {
|
||||
let rest = rest.trim_start();
|
||||
if let Some(body) = rest.strip_prefix('{') {
|
||||
@@ -7967,6 +8006,21 @@ b & 2 \\
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn row_separator_optional_gap_spaces_rows() {
|
||||
let source = "a & b \\\\[6pt]\nc & d";
|
||||
let unit = Unit::halign_from_source_with_template(1, "ll", source, 0);
|
||||
let VerticalItem::Halign(halign) = &unit.items[0] else {
|
||||
panic!("expected halign");
|
||||
};
|
||||
assert_eq!(halign.rows.len(), 2);
|
||||
assert_eq!(halign.row_gaps, vec![6 * 65_536]);
|
||||
assert_eq!(
|
||||
halign.height,
|
||||
halign.row_height(0) + halign.row_height(1) + 6 * 65_536
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn noalign_vertical_glue_spaces_rows() {
|
||||
let source = "a & b \\\\\n\\noalign{\\vskip 6pt}\nc & d \\\\\n";
|
||||
|
||||
Reference in new issue
Block a user