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,116 @@
|
||||
use super::*;
|
||||
|
||||
impl Executor {
|
||||
fn mark_class(&mut self, files: &mut impl SourceProvider) -> Result<u16, Error> {
|
||||
let n = self.integer(files)?;
|
||||
if !(0..=32767).contains(&n) {
|
||||
return self.fail("native mark class must be in 0..32767");
|
||||
}
|
||||
Ok(n as u16)
|
||||
}
|
||||
|
||||
pub(super) fn make_mark(
|
||||
&mut self,
|
||||
p: Primitive,
|
||||
span: Span,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<(), Error> {
|
||||
let class = if p == Primitive::Marks {
|
||||
self.mark_class(files)?
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let tokens = self.scan_expanded_group(files)?;
|
||||
self.box_nodes_created = self.box_nodes_created.saturating_add(1 + tokens.len());
|
||||
if self.box_nodes_created > self.limits.tokens {
|
||||
return self.fail("native mark token/node capacity exceeded");
|
||||
}
|
||||
let mark = NativeMark {
|
||||
class,
|
||||
tokens: tokens.into(),
|
||||
span,
|
||||
};
|
||||
if let Some(math) = self.math.last_mut() {
|
||||
math.nodes.push(MathNode::Mark(mark));
|
||||
} else if let Some(paragraph) = self.paragraph.as_mut() {
|
||||
paragraph.nodes.push(TextNode::Mark(mark));
|
||||
} else {
|
||||
let start = self.vertical.nodes.len();
|
||||
self.vertical.push(NativeVerticalNode::Mark(mark));
|
||||
self.emit_vertical(start);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn expand_split_mark(
|
||||
&mut self,
|
||||
p: Primitive,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<(), Error> {
|
||||
use Primitive::*;
|
||||
let class = if matches!(
|
||||
p,
|
||||
Splitfirstmarks | Splitbotmarks | Topmarks | Firstmarks | Botmarks
|
||||
) {
|
||||
self.mark_class(files)?
|
||||
} else {
|
||||
0
|
||||
};
|
||||
if matches!(
|
||||
p,
|
||||
Topmark | Firstmark | Botmark | Topmarks | Firstmarks | Botmarks
|
||||
) {
|
||||
self.native_page_mut()?;
|
||||
self.reads.insert(Dependency::PageMarks(class));
|
||||
let tokens = self
|
||||
.state
|
||||
.page_marks
|
||||
.get(&class)
|
||||
.and_then(|m| match p {
|
||||
Topmark | Topmarks => m.top.as_ref(),
|
||||
Firstmark | Firstmarks => m.first.as_ref(),
|
||||
_ => m.bottom.as_ref(),
|
||||
})
|
||||
.map_or_else(Vec::new, |t| {
|
||||
t.iter().cloned().map(InputToken::from).collect()
|
||||
});
|
||||
return self.push_kind(tokens, TokenInputKind::Mark);
|
||||
}
|
||||
self.reads.insert(Dependency::SplitMarks(class));
|
||||
let tokens = self
|
||||
.state
|
||||
.split_marks
|
||||
.get(&class)
|
||||
.map(|marks| {
|
||||
if matches!(p, Splitfirstmark | Splitfirstmarks) {
|
||||
&marks.first
|
||||
} else {
|
||||
&marks.bottom
|
||||
}
|
||||
})
|
||||
.map_or_else(Vec::new, |t| {
|
||||
t.iter().cloned().map(InputToken::from).collect()
|
||||
});
|
||||
self.push_kind(tokens, TokenInputKind::Mark)
|
||||
}
|
||||
|
||||
pub(super) fn collect_split_marks(
|
||||
&mut self,
|
||||
nodes: &[NativeVerticalNode],
|
||||
) -> Result<(), Error> {
|
||||
for n in nodes {
|
||||
self.tick()?;
|
||||
if let NativeVerticalNode::Mark(m) = n {
|
||||
self.state
|
||||
.split_marks
|
||||
.entry(m.class)
|
||||
.and_modify(|s| s.bottom = m.tokens.clone())
|
||||
.or_insert_with(|| SplitMarks {
|
||||
first: m.tokens.clone(),
|
||||
bottom: m.tokens.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user