Fixed Tex

This commit is contained in:
ef3d0c3e 2024-07-26 21:15:06 +02:00
parent 8c71258212
commit 23ac532061
2 changed files with 708 additions and 2801 deletions

3493
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -68,6 +68,7 @@ impl From<&TexKind> for ElemKind {
#[derive(Debug)] #[derive(Debug)]
struct Tex { struct Tex {
pub(self) location: Token, pub(self) location: Token,
pub(self) mathmode: bool,
pub(self) kind: TexKind, pub(self) kind: TexKind,
pub(self) env: String, pub(self) env: String,
pub(self) tex: String, pub(self) tex: String,
@ -176,7 +177,7 @@ impl Element for Tex {
let preamble = document let preamble = document
.get_variable(format!("tex.{}.preamble", self.env).as_str()) .get_variable(format!("tex.{}.preamble", self.env).as_str())
.map_or("".to_string(), |var| var.to_string()); .map_or("".to_string(), |var| var.to_string());
let prepend = if self.kind == TexKind::Inline { let prepend = if self.mathmode {
"".to_string() "".to_string()
} else { } else {
document document
@ -184,11 +185,10 @@ impl Element for Tex {
.map_or("".to_string(), |var| var.to_string() + "\n") .map_or("".to_string(), |var| var.to_string() + "\n")
}; };
let latex = match self.kind { let latex = if self.mathmode {
TexKind::Inline => {
Tex::format_latex(&fontsize, &preamble, &format!("${{{}}}$", self.tex)) Tex::format_latex(&fontsize, &preamble, &format!("${{{}}}$", self.tex))
} } else {
_ => Tex::format_latex(&fontsize, &preamble, &format!("{prepend}{}", self.tex)), Tex::format_latex(&fontsize, &preamble, &format!("{prepend}{}", self.tex))
}; };
if let Some(mut con) = compiler.cache() { if let Some(mut con) = compiler.cache() {
@ -236,7 +236,8 @@ impl TexRule {
); );
Self { Self {
re: [ re: [
Regex::new(r"\$\|(?:\[((?:\\.|[^\\\\])*?)\])?(?:((?:\\.|[^\\\\])*?)\|\$)?").unwrap(), Regex::new(r"\$\|(?:\[((?:\\.|[^\\\\])*?)\])?(?:((?:\\.|[^\\\\])*?)\|\$)?")
.unwrap(),
Regex::new(r"\$(?:\[((?:\\.|[^\\\\])*?)\])?(?:((?:\\.|[^\\\\])*?)\$)?").unwrap(), Regex::new(r"\$(?:\[((?:\\.|[^\\\\])*?)\])?(?:((?:\\.|[^\\\\])*?)\$)?").unwrap(),
], ],
properties: PropertyParser::new(props), properties: PropertyParser::new(props),
@ -403,6 +404,7 @@ impl RegexRule for TexRule {
parser.push( parser.push(
document, document,
Box::new(Tex { Box::new(Tex {
mathmode: index == 1,
location: token, location: token,
kind: tex_kind, kind: tex_kind,
env: tex_env.to_string(), env: tex_env.to_string(),