Tex export functional

This commit is contained in:
Pierre HUBERT 2023-02-03 15:36:52 +01:00
parent ebfe4d6e7c
commit 85e0c3abc5

View File

@ -85,7 +85,15 @@ fn graphviz_export(tree: &TreeNode) -> String {
out
}
fn tex_escape_str(s: &str) -> String {
s.replace('_', "\\_")
.trim_start_matches('\n')
.replace("\n\n", "\n")
.replace('\n', "\\newline\n")
}
fn tex_export_inner(tree: &ObjectChild, out: &mut String, required: bool) {
out.push_str("\\begin{minipage}{0.45\\textwidth}\n");
let type_str = match &tree.node.r#type {
NodeType::Null => "NULL".to_string(),
NodeType::Boolean => "bool".to_string(),
@ -96,25 +104,37 @@ fn tex_export_inner(tree: &ObjectChild, out: &mut String, required: bool) {
NodeType::Integer => "integer".to_string(),
};
write!(out, "\\textbf{{{}}}", tree.name).unwrap();
write!(out, "\\textbf{{{}}}", tex_escape_str(&tree.name)).unwrap();
if required {
out.push_str("\\textcolor{red}{*}");
}
out.push_str("\n\\newline");
write!(out, "\\textit{{\\textcolor{{gray}}{{{type_str}}}}}").unwrap();
write!(
out,
"\\textit{{\\textcolor{{gray}}{{{}}}}}",
tex_escape_str(&type_str)
)
.unwrap();
if let Some(description) = &tree.node.description {
write!(out, "\\newline\n\textcolor{{gray}}{{{}}}", description).unwrap();
write!(
out,
"\\newline\n\\textcolor{{gray}}{{{}}}",
tex_escape_str(description)
)
.unwrap();
}
if let Some(example) = &tree.node.examples.get(0) {
write!(
out,
"\\newline\n\textcolor{{gray}}{{Exemple : {}}}",
example
"\\newline\n\\textcolor{{gray}}{{Exemple : {}}}",
tex_escape_str(example)
)
.unwrap();
}
out.push_str("\\end{minipage}\n");
}
fn tex_export(tree: &TreeNode) -> String {
@ -133,7 +153,7 @@ fn tex_export(tree: &TreeNode) -> String {
.unwrap_or(false),
);
out.push_str("\n\n");
out.push_str("\n\n \\vspace{0.2cm} \n\n");
}
}
_ => tex_export_inner(