Adds mathmode, without tests

This commit is contained in:
Dandaedre 2024-06-19 17:37:57 +02:00
parent afee1540cc
commit 5394cc0c51
2 changed files with 15 additions and 6 deletions

View File

@ -116,9 +116,11 @@ pub(crate) static STR_TO_TARGET_FULL: phf::Map<&'static str, TableTargets> = phf
};
/// The regex for finding and replacing all stars with a custom DD
pub(crate) static RE: Lazy<Regex> = regex_static::lazy_regex!(r"★+");
// / The regex for finding all (+/-) and replacing them with mathmode
// pub(crate) static RE: Lazy<Regex> = regex_static::lazy_regex!(r"\([+-]*\)");
pub(crate) static RE_STARS: Lazy<Regex> = regex_static::lazy_regex!(r"★+");
/// The regex for finding and replacing all +/- stars with a custom DD
pub(crate) static RE_PLUS_STARS: Lazy<Regex> = regex_static::lazy_regex!(r"([\+-])(★+)");
/// The regex for finding all (+/-) and replacing them with mathmode
pub(crate) static RE_MATHS: Lazy<Regex> = regex_static::lazy_regex!(r"\([\+-]+\)");
impl From<&str> for TableGenerationTarget {
fn from(value: &str) -> Self {

View File

@ -10,7 +10,10 @@ use std::{
};
use crate::{
table_structs::{TableArgs, TableGenerationTarget, TableTargets, RE, STR_TO_TARGET_FULL},
table_structs::{
TableArgs, TableGenerationTarget, TableTargets, RE_MATHS, RE_PLUS_STARS, RE_STARS,
STR_TO_TARGET_FULL,
},
table_types::{ClassesArray, GenericArray, RecordClass, WriteTable},
Config,
};
@ -141,7 +144,7 @@ pub fn export_tsv(
/// Replace all instances of unrepresentable utf8 or non escaped characters with latex ones
pub fn make_latex_string(arg: &str) -> String {
let temp = arg
let res = arg
.replace('🩸', "\\blood")
.replace('⚡', "\\gauge")
.replace('☽', "\\slash")
@ -153,9 +156,13 @@ pub fn make_latex_string(arg: &str) -> String {
.replace('🗘', "\\reload")
.replace('½', "\\sfrac{1}{2}")
.replace('&', "\\&");
let res = RE.replace_all(&temp, |caps: &Captures| {
let res = RE_PLUS_STARS.replace_all(&res, |caps: &Captures| {
format!("\\ddmod{{{}}}{{{}}}", &caps[1], caps[2].chars().count())
});
let res = RE_STARS.replace_all(&res, |caps: &Captures| {
format!("\\ddlvl{{{}}}", caps[0].chars().count())
});
let res = RE_MATHS.replace_all(&res, |caps: &Captures| format!("${}$", &caps[0]));
res.to_string()
}