Accept baselinestretch as the linespread factor
LaTeX classes often set leading through \renewcommand{\baselinestretch}
instead of \linespread. Both forms, including \def\baselinestretch, now
feed the same factor and scale the class baseline.
This commit is contained in:
1 parent
e43d5fcaaa
commit
1a74ece3ba
3 files changed
+28
-6
No files matched your search
+26
-4
@@ -671,10 +671,8 @@ fn class_baselineskip(font_size: i64) -> i64 {
|
||||
}
|
||||
}
|
||||
|
||||
/// `\linespread{factor}` in thousandths, clamped to a sane range.
|
||||
fn linespread_assignment(line: &str) -> Option<i64> {
|
||||
let rest = line.strip_prefix("\\linespread")?;
|
||||
let (argument, _) = braced_group(rest.trim_start())?;
|
||||
/// A `\linespread`-style factor in thousandths, clamped to a sane range.
|
||||
fn spread_percent(argument: &str) -> Option<i64> {
|
||||
let factor: f64 = argument.trim().parse().ok()?;
|
||||
if !factor.is_finite() {
|
||||
return None;
|
||||
@@ -682,6 +680,22 @@ fn linespread_assignment(line: &str) -> Option<i64> {
|
||||
Some(((factor * 1000.0).round() as i64).clamp(250, 5000))
|
||||
}
|
||||
|
||||
/// `\linespread{factor}` in thousandths.
|
||||
fn linespread_assignment(line: &str) -> Option<i64> {
|
||||
let rest = line.strip_prefix("\\linespread")?;
|
||||
let (argument, _) = braced_group(rest.trim_start())?;
|
||||
spread_percent(argument)
|
||||
}
|
||||
|
||||
/// `\renewcommand{\baselinestretch}{factor}` in thousandths.
|
||||
fn baselinestretch_assignment(line: &str) -> Option<i64> {
|
||||
let rest = line
|
||||
.strip_prefix("\\renewcommand{\\baselinestretch}")
|
||||
.or_else(|| line.strip_prefix("\\def\\baselinestretch"))?;
|
||||
let (argument, _) = braced_group(rest.trim_start())?;
|
||||
spread_percent(argument)
|
||||
}
|
||||
|
||||
/// Extract the option string of `\usepackage[opts]{geometry}` or `\geometry{opts}`.
|
||||
fn geometry_package_options(line: &str) -> Option<String> {
|
||||
if let Some(rest) = line.strip_prefix("\\geometry") {
|
||||
@@ -956,6 +970,10 @@ fn strip_page_geometry(source: &str) -> (String, PageGeometry) {
|
||||
geometry.tocdepth = Some(depth);
|
||||
continue;
|
||||
}
|
||||
if let Some(spread) = baselinestretch_assignment(trimmed) {
|
||||
geometry.linespread = Some(spread);
|
||||
continue;
|
||||
}
|
||||
if trimmed.starts_with("\\newcommand")
|
||||
|| trimmed.starts_with("\\renewcommand")
|
||||
|| trimmed.starts_with("\\providecommand")
|
||||
@@ -4930,6 +4948,10 @@ mod tests {
|
||||
|
||||
let (_, clamped) = geometry_and_body("\\linespread{9}\n\nBody text.");
|
||||
assert_eq!(clamped.linespread, Some(5000));
|
||||
|
||||
let (_, renamed) =
|
||||
geometry_and_body("\\renewcommand{\\baselinestretch}{1.25}\n\nBody text.");
|
||||
assert_eq!(renamed.linespread, Some(1250));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user