Preview the arXiv template without warnings
The archived class file expands \maketitle, \section and \keywords into LaTeX internals that route-D does not model, so the template's title block, headings and keywords were replaced by LaTeX machinery and 20+ control words reached layout. Keep \maketitle, \thanks and the heading commands out of generic macro expansion so the native title block and section parser see them; scrub the author metadata (\href labels, ORCID \includegraphics, text-style wrappers, line breaks and \And) into plain text; turn \keywords into a "Keywords: ..." paragraph; expand \lipsum[n]/[a-b] to filler paragraphs; drop `%` comments and external \bibliography/\bibliographystyle commands (an inline thebibliography still supplies References); and start a new block when center/flushleft/ flushright follows text on the same chunk. The arXiv fixture now previews with zero warnings in two pages, covered by a JSON-level regression test. Remaining class support is still semantic rather than a TeX VM.
This commit is contained in:
1 parent
1b7baa0257
commit
21d48866de
3 files changed
+371
-10
No files matched your search
@@ -48,7 +48,7 @@ floats (`\floatsep`, `\textfloatsep`, `\intextsep`, `\topfraction`,
|
||||
`\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and
|
||||
absolute limits, splitting), marks, Rust output hook, multi-page PDF, and the
|
||||
route-D service endpoints (`/api/route-d/preview|pdf|edit`, project preview and
|
||||
PDF opt-in with `?engine=route-d`). 971 workspace tests are green and no oracle
|
||||
PDF opt-in with `?engine=route-d`). 975 workspace tests are green and no oracle
|
||||
fixture is ignored. Preview JSON also carries a `warnings` array naming
|
||||
environments route-D cannot lay out and control words that survived layout, so
|
||||
unsupported source is reported instead of being silently typeset.
|
||||
@@ -381,6 +381,14 @@ Acceptance: `article.cls` at 10/11/12pt matches pdfLaTeX page count exactly;
|
||||
the journal class matches page count within one page and column geometry within
|
||||
1mm.
|
||||
|
||||
Progress: the arXiv template's class (`arxiv.sty`) previews with no warnings in
|
||||
two pages. `\title`/`\author`/`\thanks` stay on the native title path, heading
|
||||
commands are kept for the native section parser instead of expanding their class
|
||||
redefinitions, `\keywords` becomes a plain paragraph, `\lipsum[n]` expands to
|
||||
filler text, comments and external `\bibliography` commands are dropped, and a
|
||||
`center`/`flushleft`/`flushright` environment that follows text starts its own
|
||||
block. Class files are still mapped semantically rather than executed by a VM.
|
||||
|
||||
### P7 — Service and incrementality
|
||||
|
||||
Scope:
|
||||
|
||||
+7
-4
@@ -370,7 +370,7 @@ Math coverage includes fractions/roots, scripts, `\left...\right` with body-scal
|
||||
|
||||
Paragraph units carry a `ParagraphFont`; `Unit::paragraph_with_face` and `Unit::paragraph_with_style_and_face` select Roman, bold, italic, mono, or sans. The corresponding Computer Modern TFM (`cmr10`, `cmbx10`, `cmti10`, `cmbxti10`, `cmtt10`, `cmss10`, `cmssbx10`, `cmssi10`, `cmcsc10`) supplies advances, kerns, ligatures, and italic correction for layout, the display list selects the matching face, and the PDF writes Computer Modern Type1 outlines for each built-in face (`cmr10`/`cmbx10`/`cmti10`/`cmbxti10`/`cmtt10`/`cmss10`/`cmssbx10`/`cmssi10`/`cmcsc10`, plus `cmmi10` for mathematical italic letters, `cmsy10` for math symbols and `cmex10` for big operators), falling back to Liberation subsets only for characters the Type1 encodings cannot address; those fallback glyphs keep their Unicode text under PDF extraction, so accented and Greek words round-trip; Type1 faces carry a ToUnicode CMap built from the requested characters, so glyphs whose names are ambiguous in the Adobe Glyph List (capital Omega, which would otherwise extract as U+2126) keep their intended code points. `Engine::edit` preserves the face when reflowing an edited paragraph.
|
||||
|
||||
The crate currently has 434 unit tests plus ten route-D integration tests and forty-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 971 tests (434 route-D unit, 349 engine binary unit, 10 route-D integration, 42 oracle, 71 v1 integration, 60 server, 4 engine unit, 1 core unit), with none ignored. v1 remains the live server path.
|
||||
The crate currently has 434 unit tests plus ten route-D integration tests and forty-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 975 tests (434 route-D unit, 353 engine binary unit, 10 route-D integration, 42 oracle, 71 v1 integration, 60 server, 4 engine unit, 1 core unit), with none ignored. v1 remains the live server path.
|
||||
|
||||
### M0 incremental demo
|
||||
|
||||
@@ -485,9 +485,12 @@ deliberately open rather than approximated:
|
||||
Class files contribute multi-line `\newcommand`/`\def`/`\newenvironment`
|
||||
bodies: the source is joined at balanced braces and the whole definition is
|
||||
captured, while `\ifhmode`/`\ifvmode`/`\ifmmode` resolve as the
|
||||
horizontal/vertical/math approximations. The arXiv class preamble no longer
|
||||
leaks into the body: the template now previews as four pages instead of one
|
||||
page of `\NeedsTeXFormat`/`\fancyhf` text.
|
||||
horizontal/vertical/math approximations. The arXiv class now previews with
|
||||
no warnings in two pages: `\maketitle`/`\thanks` stay on the native title
|
||||
path, heading commands are not expanded through class redefinitions,
|
||||
`\keywords` becomes a plain paragraph, `\lipsum[n]` expands to filler text,
|
||||
comments and external `\bibliography` commands are dropped, and
|
||||
`center`/flush environments that follow text start their own block.
|
||||
- Page hashes cover rendered items/insertions/marks/floats, not source-dependency
|
||||
metadata, so replaying an earlier page cannot change its hash merely by
|
||||
re-attaching source hashes.
|
||||
|
||||
+355
-5
@@ -1230,6 +1230,26 @@ fn expand_macros(source: &str, macros: &[MacroDefinition]) -> String {
|
||||
changed = true;
|
||||
continue;
|
||||
}
|
||||
if let Some((command, used)) = control_sequence(rest) {
|
||||
if matches!(
|
||||
command.as_str(),
|
||||
"\\maketitle"
|
||||
| "\\thanks"
|
||||
| "\\section"
|
||||
| "\\subsection"
|
||||
| "\\subsubsection"
|
||||
| "\\paragraph"
|
||||
| "\\chapter"
|
||||
| "\\part"
|
||||
) {
|
||||
// The native title block reads \title/\author/\date
|
||||
// directly; expanding a class-file \maketitle definition
|
||||
// would typeset the whole LaTeX machinery instead.
|
||||
output.push_str(&command);
|
||||
index += used;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if let Some((expanded, used)) = expand_macro_at(rest, macros) {
|
||||
output.push_str(&expanded);
|
||||
index += used;
|
||||
@@ -4555,7 +4575,13 @@ fn geometry_and_body(source: &str) -> (String, PageGeometry) {
|
||||
// instead of being typeset as text at the top of page one.
|
||||
let source = lift_at_begin_document(source);
|
||||
let source = collapse_definition_bodies(&source);
|
||||
let source = strip_tex_comments(&source);
|
||||
let source = collapse_braced_command(&source, "\\newgeometry");
|
||||
// Class files write the title metadata across lines, especially author
|
||||
// blocks with forced line breaks and thanks notes.
|
||||
let source = collapse_braced_command(&source, "\\title");
|
||||
let source = collapse_braced_command(&source, "\\author");
|
||||
let source = collapse_braced_command(&source, "\\date");
|
||||
let (stripped, mut geometry) = strip_page_geometry(&source);
|
||||
dedupe_macros(&mut geometry.macros);
|
||||
// Removed assignments can leave blank lines at the edges; they are not
|
||||
@@ -4576,6 +4602,8 @@ fn geometry_and_body(source: &str) -> (String, PageGeometry) {
|
||||
&mut geometry.environments,
|
||||
);
|
||||
body = expand_environments(&body, &geometry.environments);
|
||||
body = expand_keywords(&body);
|
||||
body = drop_bibliography_commands(&body);
|
||||
body = expand_saveboxes(&body, &mut geometry.macros);
|
||||
dedupe_macros(&mut geometry.macros);
|
||||
let macros = geometry.macros.clone();
|
||||
@@ -4615,11 +4643,157 @@ fn geometry_and_body(source: &str) -> (String, PageGeometry) {
|
||||
);
|
||||
let today = today_string();
|
||||
body = expand_today(&body, &today);
|
||||
body = expand_lipsum(&body);
|
||||
(body, geometry)
|
||||
}
|
||||
|
||||
/// Remove a `thebibliography` environment from the body and return its
|
||||
/// `\bibitem{key}` entries in order.
|
||||
/// Start a new block when a display environment follows text on the same
|
||||
/// chunk, e.g. "The documentation is at\n\begin{center}...".
|
||||
fn split_block_environments(chunk: &str) -> Vec<&str> {
|
||||
const OPENINGS: [&str; 3] = [
|
||||
"\\begin{center}",
|
||||
"\\begin{flushleft}",
|
||||
"\\begin{flushright}",
|
||||
];
|
||||
let mut pieces = Vec::new();
|
||||
let mut rest = chunk;
|
||||
loop {
|
||||
let next = OPENINGS
|
||||
.iter()
|
||||
.filter_map(|opening| rest.find(opening).map(|position| (position, *opening)))
|
||||
.min_by_key(|(position, _)| *position);
|
||||
match next {
|
||||
Some((position, _)) if position > 0 && !rest[..position].trim().is_empty() => {
|
||||
pieces.push(&rest[..position]);
|
||||
rest = &rest[position..];
|
||||
}
|
||||
_ => break,
|
||||
}
|
||||
}
|
||||
pieces.push(rest);
|
||||
pieces
|
||||
}
|
||||
|
||||
/// Remove `%` comments; TeX never typesets them.
|
||||
fn strip_tex_comments(source: &str) -> String {
|
||||
source
|
||||
.lines()
|
||||
.map(strip_tex_comment)
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
/// `\bibliography{...}` and `\bibliographystyle{...}` need an external .bib
|
||||
/// run that route-D does not implement; dropping them keeps the command from
|
||||
/// reaching layout. An inline `thebibliography` still supplies References.
|
||||
fn drop_bibliography_commands(body: &str) -> String {
|
||||
let mut out = String::new();
|
||||
let mut rest = body;
|
||||
loop {
|
||||
let next = ["\\bibliographystyle", "\\bibliography"]
|
||||
.iter()
|
||||
.filter_map(|command| rest.find(command).map(|position| (position, *command)))
|
||||
.min_by_key(|(position, _)| *position);
|
||||
let Some((position, command)) = next else {
|
||||
out.push_str(rest);
|
||||
break;
|
||||
};
|
||||
out.push_str(&rest[..position]);
|
||||
let after = &rest[position + command.len()..];
|
||||
let trimmed = after.trim_start();
|
||||
if let Some((_name, used)) = braced_group(trimmed) {
|
||||
rest = &trimmed[used..];
|
||||
} else {
|
||||
rest = after;
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Turn `\keywords{...}` into a plain "Keywords: ..." paragraph. Class files
|
||||
/// implement it with \addvspace and \rightskip machinery that route-D does not
|
||||
/// model yet.
|
||||
fn expand_keywords(body: &str) -> String {
|
||||
let mut out = String::with_capacity(body.len());
|
||||
let mut rest = body;
|
||||
while let Some(index) = rest.find("\\keywords") {
|
||||
out.push_str(&rest[..index]);
|
||||
let after = &rest[index + "\\keywords".len()..];
|
||||
let trimmed = after.trim_start();
|
||||
let Some((inner, used)) = braced_group(trimmed) else {
|
||||
out.push_str("\\keywords");
|
||||
rest = after;
|
||||
continue;
|
||||
};
|
||||
let words = inner
|
||||
.replace("\\AND", ", ")
|
||||
.replace("\\and", ", ")
|
||||
.split_whitespace()
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ");
|
||||
out.push_str("Keywords: ");
|
||||
out.push_str(&words);
|
||||
rest = &trimmed[used..];
|
||||
}
|
||||
out.push_str(rest);
|
||||
out
|
||||
}
|
||||
|
||||
/// The first paragraphs of the standard Lorem ipsum filler text, used by
|
||||
/// `\lipsum[n]` in templates. The Latin text is public domain.
|
||||
const LIPSUM_PARAGRAPHS: [&str; 10] = [
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
|
||||
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.",
|
||||
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.",
|
||||
"Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.",
|
||||
"Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.",
|
||||
"Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae.",
|
||||
"Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur. At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores.",
|
||||
"Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur. Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur.",
|
||||
"Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt.",
|
||||
"Sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.",
|
||||
];
|
||||
|
||||
/// Expand the `lipsum` package's filler command (`\lipsum[n]`, `\lipsum[a-b]`,
|
||||
/// and bare `\lipsum`).
|
||||
fn expand_lipsum(body: &str) -> String {
|
||||
let mut out = String::with_capacity(body.len());
|
||||
let mut rest = body;
|
||||
while let Some(index) = rest.find("\\lipsum") {
|
||||
out.push_str(&rest[..index]);
|
||||
let after = &rest[index + "\\lipsum".len()..];
|
||||
let trimmed = after.trim_start();
|
||||
if let Some(inner) = trimmed.strip_prefix('[') {
|
||||
if let Some((spec, tail)) = inner.split_once(']') {
|
||||
out.push_str(&lipsum_paragraphs(spec));
|
||||
rest = tail;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
out.push_str(&lipsum_paragraphs("1-10"));
|
||||
rest = trimmed;
|
||||
}
|
||||
out.push_str(rest);
|
||||
out
|
||||
}
|
||||
|
||||
fn lipsum_paragraphs(spec: &str) -> String {
|
||||
let spec = spec.trim();
|
||||
let (start, end) = if let Some((start, end)) = spec.split_once('-') {
|
||||
let start = start.trim().parse::<usize>().unwrap_or(1);
|
||||
let end = end.trim().parse::<usize>().unwrap_or(start);
|
||||
(start, end)
|
||||
} else {
|
||||
let value = spec.parse::<usize>().unwrap_or(1);
|
||||
(value, value)
|
||||
};
|
||||
let start = start.clamp(1, LIPSUM_PARAGRAPHS.len());
|
||||
let end = end.clamp(start, LIPSUM_PARAGRAPHS.len());
|
||||
LIPSUM_PARAGRAPHS[start - 1..end].join("\n\n")
|
||||
}
|
||||
|
||||
fn extract_bibliography(body: &mut String) -> Vec<(String, String)> {
|
||||
let begin = r"\begin{thebibliography}";
|
||||
let end = r"\end{thebibliography}";
|
||||
@@ -5557,11 +5731,15 @@ fn paragraphs_with_spacing(
|
||||
equation_start: u32,
|
||||
spacing: ListSpacing,
|
||||
) -> Result<Vec<SourceParagraph>, String> {
|
||||
let paragraphs: Vec<&str> = split_display_chunks(source)
|
||||
.into_iter()
|
||||
.map(str::trim)
|
||||
.filter(|paragraph| !paragraph.is_empty())
|
||||
.collect();
|
||||
let mut paragraphs: Vec<&str> = Vec::new();
|
||||
for chunk in split_display_chunks(source) {
|
||||
for piece in split_block_environments(chunk) {
|
||||
let piece = piece.trim();
|
||||
if !piece.is_empty() {
|
||||
paragraphs.push(piece);
|
||||
}
|
||||
}
|
||||
}
|
||||
if paragraphs.is_empty() {
|
||||
return Err("route-D preview needs at least one paragraph".to_string());
|
||||
}
|
||||
@@ -9090,9 +9268,127 @@ fn clean_title_value(text: &str) -> String {
|
||||
let joined = out.replace("\\and", ", ");
|
||||
let mut normalized = joined.split_whitespace().collect::<Vec<_>>().join(" ");
|
||||
normalized = normalized.replace(" ,", ",");
|
||||
normalized = scrub_title_metadata(&normalized);
|
||||
normalized.trim().to_string()
|
||||
}
|
||||
|
||||
/// Strip author/title metadata commands that have no text of their own.
|
||||
fn scrub_title_metadata(text: &str) -> String {
|
||||
let text = href_to_label(text);
|
||||
let mut text = text;
|
||||
for command in [
|
||||
"\\emph",
|
||||
"\\textit",
|
||||
"\\textbf",
|
||||
"\\textsc",
|
||||
"\\textsf",
|
||||
"\\textrm",
|
||||
"\\textup",
|
||||
"\\texttt",
|
||||
"\\textmd",
|
||||
"\\textnormal",
|
||||
"\\url",
|
||||
"\\mbox",
|
||||
] {
|
||||
text = replace_command_group(&text, command);
|
||||
}
|
||||
for command in ["\\includegraphics", "\\hspace", "\\vspace", "\\rule"] {
|
||||
text = drop_command_group(&text, command);
|
||||
}
|
||||
for declaration in [
|
||||
"\\scshape",
|
||||
"\\footnotesize",
|
||||
"\\small",
|
||||
"\\normalsize",
|
||||
"\\bfseries",
|
||||
"\\itshape",
|
||||
"\\centering",
|
||||
"\\relax",
|
||||
] {
|
||||
text = text.replace(declaration, "");
|
||||
}
|
||||
text.replace("\\\\", " ")
|
||||
.replace("\\AND", ", ")
|
||||
.replace("\\And", ", ")
|
||||
.replace("\\and", ", ")
|
||||
}
|
||||
|
||||
/// `\href{url}{label}` keeps the visible label.
|
||||
fn href_to_label(text: &str) -> String {
|
||||
let mut out = String::new();
|
||||
let mut rest = text;
|
||||
while let Some(index) = rest.find("\\href") {
|
||||
out.push_str(&rest[..index]);
|
||||
let after = &rest[index + "\\href".len()..];
|
||||
let trimmed = after.trim_start();
|
||||
let Some((_url, used)) = braced_group(trimmed) else {
|
||||
rest = after;
|
||||
continue;
|
||||
};
|
||||
let tail = trimmed[used..].trim_start();
|
||||
if let Some((label, label_used)) = braced_group(tail) {
|
||||
out.push_str(&label);
|
||||
rest = &tail[label_used..];
|
||||
} else {
|
||||
rest = tail;
|
||||
}
|
||||
}
|
||||
out.push_str(rest);
|
||||
out
|
||||
}
|
||||
|
||||
/// `\command{body}` becomes `body`.
|
||||
fn replace_command_group(text: &str, command: &str) -> String {
|
||||
let mut out = String::new();
|
||||
let mut rest = text;
|
||||
while let Some(index) = rest.find(command) {
|
||||
let after = &rest[index + command.len()..];
|
||||
if after.starts_with(|character: char| character.is_ascii_alphabetic()) {
|
||||
out.push_str(&rest[..index + command.len()]);
|
||||
rest = after;
|
||||
continue;
|
||||
}
|
||||
out.push_str(&rest[..index]);
|
||||
let trimmed = after.trim_start();
|
||||
if let Some((body, used)) = braced_group(trimmed) {
|
||||
out.push_str(&body);
|
||||
rest = &trimmed[used..];
|
||||
} else {
|
||||
rest = after;
|
||||
}
|
||||
}
|
||||
out.push_str(rest);
|
||||
out
|
||||
}
|
||||
|
||||
/// Drop `\command[options]{body}`.
|
||||
fn drop_command_group(text: &str, command: &str) -> String {
|
||||
let mut out = String::new();
|
||||
let mut rest = text;
|
||||
while let Some(index) = rest.find(command) {
|
||||
let after = &rest[index + command.len()..];
|
||||
if after.starts_with(|character: char| character.is_ascii_alphabetic()) {
|
||||
out.push_str(&rest[..index + command.len()]);
|
||||
rest = after;
|
||||
continue;
|
||||
}
|
||||
out.push_str(&rest[..index]);
|
||||
let mut trimmed = after.trim_start();
|
||||
if let Some(options) = trimmed.strip_prefix('[')
|
||||
&& let Some((_options, tail)) = options.split_once(']')
|
||||
{
|
||||
trimmed = tail.trim_start();
|
||||
}
|
||||
if let Some((_body, used)) = braced_group(trimmed) {
|
||||
rest = &trimmed[used..];
|
||||
} else {
|
||||
rest = after;
|
||||
}
|
||||
}
|
||||
out.push_str(rest);
|
||||
out
|
||||
}
|
||||
|
||||
fn title_block(text: String, size: f64, space_before: i64) -> SourceParagraph {
|
||||
SourceParagraph {
|
||||
width: None,
|
||||
@@ -13743,6 +14039,60 @@ A definition.
|
||||
assert_eq!(after.space_shrink, 5 * SCALE);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block_environment_after_text_starts_a_new_block() {
|
||||
let blocks = paragraphs("The link is at\n\\begin{center}\nCentered\n\\end{center}\n")
|
||||
.expect("blocks");
|
||||
assert_eq!(blocks.len(), 2);
|
||||
assert_eq!(blocks[0].text.trim(), "The link is at");
|
||||
assert!(
|
||||
blocks[1].centered,
|
||||
"center environment must center its block"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn comments_and_external_bibliography_commands_are_dropped() {
|
||||
let source = "\\documentclass{article}\n\\begin{document}\n\nVisible text. % \\newblock hidden\n\n\\bibliographystyle{plain}\n\\bibliography{references}\n\\end{document}\n";
|
||||
let (body, _) = geometry_and_body(source);
|
||||
assert!(!body.contains("newblock"), "{body}");
|
||||
assert!(!body.contains("bibliography"), "{body}");
|
||||
assert!(body.contains("Visible text."), "{body}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arxiv_template_previews_without_warnings() {
|
||||
let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||
let template = std::fs::read_to_string(root.join("fixtures/arxiv-template/template.tex"))
|
||||
.expect("template");
|
||||
let sty =
|
||||
std::fs::read_to_string(root.join("fixtures/arxiv-template/arxiv.sty")).expect("sty");
|
||||
let assembled = template.replace("\\usepackage{arxiv}", &sty);
|
||||
let json = preview_json(&assembled).expect("preview");
|
||||
let value: serde_json::Value = serde_json::from_str(&json).expect("JSON");
|
||||
assert_eq!(value["status"], "ok");
|
||||
assert_eq!(
|
||||
value["warnings"].as_array().map(Vec::len),
|
||||
Some(0),
|
||||
"{}",
|
||||
value["warnings"]
|
||||
);
|
||||
assert!(
|
||||
value["pageCount"].as_u64().unwrap_or(0) >= 2,
|
||||
"expected at least two pages"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lipsum_expands_to_filler_paragraphs() {
|
||||
let source = "\\documentclass{article}\n\\begin{document}\n\n\\lipsum[1]\n\n\\lipsum[2-3]\n\n\\lipsum\n\n\\end{document}\n";
|
||||
let (body, _) = geometry_and_body(source);
|
||||
assert!(!body.contains("\\lipsum"), "{body}");
|
||||
assert!(body.contains("Lorem ipsum"), "{body}");
|
||||
let blocks = paragraphs(&body).expect("paragraphs");
|
||||
assert!(blocks.len() >= 4, "{} blocks", blocks.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multiline_macro_definitions_do_not_leak_into_the_body() {
|
||||
let source = "\\documentclass{article}\n\\newcommand{\\kw}[1]{%\n \\textbf{#1}%\n}\n\\def\\and{\\ifhmode\n\\fi}\n\\begin{document}\n\nSee \\kw{Hi} and \\and there.\n\n\\end{document}\n";
|
||||
|
||||
Reference in new issue
Block a user