Advance native LaTeX execution and preview
This commit is contained in:
1 parent
91f9d76b16
commit
2741546ca8
414 files changed
+99872
-933
No files matched your search
@@ -0,0 +1,289 @@
|
||||
//! Native box/mode/state -> hpack/vpack, independently compared with INITEX.
|
||||
#[path = "support/font_world.rs"]
|
||||
mod font_world;
|
||||
use font_world::FontFiles;
|
||||
use std::{fs, process::Command};
|
||||
use texrra_tex_core::execution::*;
|
||||
const SETUP: &str = r"\catcode123=1 \catcode125=2 \catcode35=6 \font\p=cmr10 \p \hsize=100pt \baselineskip=12pt \parfillskip=0pt plus1fil \boxmaxdepth=100pt \hbadness=10000 \vbadness=10000 ";
|
||||
fn run(body: &str) -> Execution {
|
||||
Executor::new(
|
||||
State::initex().with_etex(),
|
||||
Limits {
|
||||
steps: 1_000_000,
|
||||
..Limits::default()
|
||||
},
|
||||
)
|
||||
.run(
|
||||
SourceFile {
|
||||
name: "boxes.tex".into(),
|
||||
data: (format!("{SETUP}{body}\\end")).as_bytes().to_vec(),
|
||||
},
|
||||
&mut FontFiles,
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
fn messages(e: &Execution) -> Vec<String> {
|
||||
e.events
|
||||
.iter()
|
||||
.filter_map(|e| {
|
||||
if let Event::Message { text, .. } = e {
|
||||
Some(text.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
#[test]
|
||||
fn box_registers_scopes_moves_and_dimensions_preserve_native_contents() {
|
||||
let e = run(
|
||||
r"\setbox0=\vbox{\hbox{Ag}\kern3pt\hbox{bp}}{\setbox0=\hbox{X}\setbox1=\copy0\relax\ifhbox1\message{H}\fi}\ifvoid1\message{VOID}\fi\ifvbox0\message{V}\fi\wd0=40pt{\ht0=20pt}\message{\the\wd0/\the\ht0}\setbox2=\box0\relax\ifvoid0\message{MOVED}\fi\copy2",
|
||||
);
|
||||
assert_eq!(messages(&e), ["H", "VOID", "V", "40.0pt/20.0pt", "MOVED"]);
|
||||
let b = e.state.box_register(2).unwrap();
|
||||
assert_eq!(b.width, 40 * 65536);
|
||||
assert_eq!(b.height, 20 * 65536);
|
||||
assert!(e.state.box_register(0).is_none());
|
||||
let copy: Execution = serde_json::from_str(&serde_json::to_string(&e).unwrap()).unwrap();
|
||||
assert_eq!(copy, e);
|
||||
assert!(e.reads.contains(&Dependency::BoxRegister(2)));
|
||||
assert!(!e.document().unwrap().units.is_empty());
|
||||
}
|
||||
#[test]
|
||||
fn box_modes_group_types_prevdepth_and_restoration_are_real() {
|
||||
let e = run(
|
||||
r"\message{\the\prevdepth}\setbox0=\vbox{\ifinner\message{INNER-V}\fi\message{\the\currentgrouptype}\prevdepth=2pt\hbox{A}\message{\the\prevdepth}\vskip4pt\message{\the\prevdepth}\hrule\message{\the\prevdepth}\setbox1=\hbox{\ifinner\message{INNER-H}\fi\message{\the\currentgrouptype}X}\noindent A\ifinner\message{BAD}\fi\par}\message{\the\prevdepth/\the\currentgrouptype}",
|
||||
);
|
||||
assert_eq!(
|
||||
messages(&e),
|
||||
[
|
||||
"-1000.0pt",
|
||||
"INNER-V",
|
||||
"4",
|
||||
"0.0pt",
|
||||
"0.0pt",
|
||||
"-1000.0pt",
|
||||
"INNER-H",
|
||||
"3",
|
||||
"-1000.0pt/0"
|
||||
]
|
||||
);
|
||||
assert!(e.state.box_register(1).is_none());
|
||||
}
|
||||
#[test]
|
||||
fn unfinished_boxes_wrong_modes_and_unsupported_material_fail() {
|
||||
for text in [
|
||||
r"\vbox{",
|
||||
r"\vbox{\end}",
|
||||
r"\hbox{\vskip1pt}",
|
||||
r"A\prevdepth=1pt",
|
||||
r"\vbox{\write0{bad}}",
|
||||
r"\vbox{\endgroup}",
|
||||
] {
|
||||
let result = Executor::default().run(
|
||||
SourceFile {
|
||||
name: "bad.tex".into(),
|
||||
data: text.as_bytes().to_vec(),
|
||||
},
|
||||
&mut FontFiles,
|
||||
);
|
||||
assert!(result.is_err(), "{text}");
|
||||
}
|
||||
let text = format!("{}{}", r"\vbox{".repeat(40), "}".repeat(40));
|
||||
assert!(
|
||||
Executor::default()
|
||||
.run(
|
||||
SourceFile {
|
||||
name: "depth.tex".into(),
|
||||
data: text.into_bytes(),
|
||||
},
|
||||
&mut FontFiles
|
||||
)
|
||||
.unwrap_err()
|
||||
.message
|
||||
.contains("capacity")
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn native_packing_dimensions_badness_and_diagnostics_match_actual_initex() {
|
||||
let dir = std::env::temp_dir().join(format!("texrra-box-oracle-{}", std::process::id()));
|
||||
fs::create_dir_all(&dir).unwrap();
|
||||
#[derive(Default)]
|
||||
struct Host(Vec<String>);
|
||||
impl SourceProvider for Host {
|
||||
font_world::font_resources!();
|
||||
fn read(&mut self, _: &str, _: &str) -> Result<SourceFile, String> {
|
||||
Err("no files".into())
|
||||
}
|
||||
fn observe_message(&mut self, text: &str) -> Result<(), String> {
|
||||
self.0.push(text.into());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
let mut cases = Vec::new();
|
||||
// Formerly rejected as unimplemented; retain the same legal box body in
|
||||
// the real INITEX success oracle now that signed flexibility is supported.
|
||||
cases.push(r"\setbox0=\vbox{\vskip0pt plus-1pt}".into());
|
||||
for kind in ["vbox", "vtop"] {
|
||||
for spec in ["", "to0pt", "to10pt", "to30pt", "spread5pt", "spread-3pt"] {
|
||||
for material in [
|
||||
r"",
|
||||
r"\kern3pt",
|
||||
r"\hbox{Ag}",
|
||||
r"\hbox{Ag}\kern2pt\hbox{bp}",
|
||||
r"\hbox{A}\vskip2pt plus3pt minus1pt\hbox{gp}",
|
||||
r"\vskip1pt plus1fil\hbox{Ag}",
|
||||
r"\hbox{A}\vss\hbox{gp}",
|
||||
r"\hbox{A}\vskip0pt plus1fill\hbox{gp}",
|
||||
r"\hbox{Ag}\hrule width12pt height2pt depth1pt\hbox{bp}",
|
||||
r"\vbox{\hbox{Ag}\kern2pt}\hbox{bp}",
|
||||
] {
|
||||
cases.push(format!(r"\setbox0=\{kind} {spec}{{{material}}}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
for spec in ["", "to0pt", "to10pt", "to50pt", "spread5pt", "spread-3pt"] {
|
||||
for material in [
|
||||
"",
|
||||
r"Ag bp",
|
||||
r"Ag\hskip2pt plus3pt minus1pt bp",
|
||||
r"Ag\hskip1pt plus1fil bp",
|
||||
r"A\vbox{\hbox{g}\kern2pt}B",
|
||||
] {
|
||||
cases.push(format!(r"\setbox0=\hbox {spec}{{{material}}}"));
|
||||
}
|
||||
}
|
||||
for max in [0, 1, 2, -1] {
|
||||
cases.push(format!(
|
||||
r"\boxmaxdepth={max}pt\setbox0=\vbox{{\hbox{{gp}}}}"
|
||||
));
|
||||
}
|
||||
for threshold in [0, 99, 100, 10000] {
|
||||
for fuzz in [0, 1, 100] {
|
||||
cases.push(format!(
|
||||
r"\vbadness={threshold}\vfuzz={fuzz}pt\setbox0=\vbox to5pt{{\kern10pt}}"
|
||||
));
|
||||
cases.push(format!(
|
||||
r"\vbadness={threshold}\vfuzz={fuzz}pt\setbox0=\vbox to20pt{{\vskip10pt plus5pt}}"
|
||||
));
|
||||
}
|
||||
}
|
||||
cases.extend(
|
||||
[
|
||||
r"\vbadness=10000\setbox0=\vbox to20pt{\vbadness=0\vskip10pt plus5pt}",
|
||||
r"\vbadness=0\setbox0=\vbox to20pt{\vbadness=10000\vskip10pt plus5pt}",
|
||||
r"\setbox0=\vbox{\boxmaxdepth=0pt\hbox{gp}}",
|
||||
r"\setbox0=\vbox{Alpha beta gamma delta epsilon zeta eta theta iota kappa lambda.\par}",
|
||||
r"\setbox0=\vbox{\hbox{Ag}\prevdepth=-1000pt\hbox{bp}}",
|
||||
r"\setbox0=\vbox{\hbox{Ag}\prevdepth=2pt\hbox{bp}}",
|
||||
]
|
||||
.into_iter()
|
||||
.map(str::to_owned),
|
||||
);
|
||||
for body in [
|
||||
r"\vbadness=-1\setbox0=\vbox{}",
|
||||
r"\vbadness=-1\setbox0=\vbox to20pt{}",
|
||||
r"\vbadness=-1\setbox0=\vbox to20pt{\vfil}",
|
||||
r"\vbadness=-1\setbox0=\vbox{\kern2pt}",
|
||||
r"\hbadness=-1\setbox0=\hbox to20pt{}",
|
||||
r"\hbadness=-1\setbox0=\hbox spread2pt{Ag\hskip0pt plus1fil}",
|
||||
r"\hbadness=-1\setbox0=\vbox{Alpha beta gamma delta epsilon zeta eta theta.\par}",
|
||||
r"\setbox0=\vbox{\parskip=4pt\noindent A\par\noindent\par B\par}",
|
||||
] {
|
||||
cases.push(body.into());
|
||||
}
|
||||
cases.extend(
|
||||
[
|
||||
r"\setbox0=\hbox{Ag}{\setbox0=\hbox{X}}",
|
||||
r"\setbox0=\hbox{Ag}{\global\setbox0=\vbox{\hbox{X}}}",
|
||||
r"\setbox0=\hbox{Ag}{\wd0=40pt}",
|
||||
r"\setbox0=\hbox{Ag}{\ht0=20pt\dp0=4pt}",
|
||||
r"\setbox0=\hbox{Ag}{\setbox1=\box0\relax}",
|
||||
r"\setbox0=\hbox{A}{\setbox0=\hbox{B}\setbox1=\box0\relax}",
|
||||
r"\globaldefs=1{\setbox0=\hbox{A}{\setbox0=\hbox{B}}}",
|
||||
r"\globaldefs=1{\setbox0=\hbox{\globaldefs=-1 A}}",
|
||||
r"\setbox32767=\vbox{\hbox{Ag}}\setbox0=\copy32767\relax",
|
||||
r"\wd0=10pt\ht0=20pt\dp0=4pt",
|
||||
]
|
||||
.into_iter()
|
||||
.map(str::to_owned),
|
||||
);
|
||||
cases.extend([
|
||||
r"\setbox0=\vbox\relax{\hbox{Ag}}",
|
||||
r"\let\bgroup={\let\egroup=}\setbox0=\vbox\bgroup\hbox{Ag}\egroup",
|
||||
r"\let\bgroup={\let\egroup=}\def\open{\ifnum\currentgrouptype=4\bgroup\else\errmessage{wrong group}\fi}\setbox0=\vbox\relax\open\hbox{Ag}\egroup",
|
||||
].into_iter().map(str::to_owned));
|
||||
for (i, body) in cases.iter().enumerate() {
|
||||
let common = format!(
|
||||
"{SETUP}{body}\\message{{PACK=\\number\\wd0,\\number\\ht0,\\number\\dp0,\\the\\badness;}}\\end\n"
|
||||
);
|
||||
let mut host = Host::default();
|
||||
let e = Executor::new(
|
||||
State::initex().with_etex(),
|
||||
Limits {
|
||||
steps: 1_000_000,
|
||||
..Limits::default()
|
||||
},
|
||||
)
|
||||
.run(
|
||||
SourceFile {
|
||||
name: "oracle.tex".into(),
|
||||
data: common.as_bytes().to_vec(),
|
||||
},
|
||||
&mut host,
|
||||
)
|
||||
.unwrap_or_else(|e| panic!("case {i}: {body}: {e}"));
|
||||
fs::write(dir.join("probe.tex"), common).unwrap();
|
||||
let output = match Command::new("pdftex")
|
||||
.args([
|
||||
"-ini",
|
||||
"-etex",
|
||||
"-interaction=nonstopmode",
|
||||
"-halt-on-error",
|
||||
"probe.tex",
|
||||
])
|
||||
.current_dir(&dir)
|
||||
.output()
|
||||
{
|
||||
Ok(o) => o,
|
||||
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
|
||||
eprintln!("pdftex absent: box oracle skipped");
|
||||
fs::remove_dir_all(dir).unwrap();
|
||||
return;
|
||||
}
|
||||
Err(e) => panic!("{e}"),
|
||||
};
|
||||
let log = fs::read_to_string(dir.join("probe.log")).unwrap();
|
||||
assert!(output.status.success(), "case {i}: {body}\n{log}");
|
||||
let expected = format!(
|
||||
"PACK={};",
|
||||
log.split("PACK=")
|
||||
.nth(1)
|
||||
.unwrap()
|
||||
.split(';')
|
||||
.next()
|
||||
.unwrap()
|
||||
.replace('\n', "")
|
||||
);
|
||||
assert_eq!(
|
||||
messages(&e).last().unwrap(),
|
||||
&expected,
|
||||
"case {i}: {body}\n{log}"
|
||||
);
|
||||
for label in ["Underfull", "Loose", "Tight", "Overfull"] {
|
||||
let native = host
|
||||
.0
|
||||
.iter()
|
||||
.filter(|s| s.starts_with(&format!("\n{label} \\")))
|
||||
.count();
|
||||
let reference = log.matches(&format!("{label} \\")).count();
|
||||
assert_eq!(
|
||||
native, reference,
|
||||
"diagnostics case {i}: {body}\n{log}\n{:?}",
|
||||
host.0
|
||||
);
|
||||
}
|
||||
}
|
||||
eprintln!("{} native box hpack/vpack INITEX cases passed", cases.len());
|
||||
fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
Reference in new issue
Block a user