mirror of
https://github.com/lise-henry/crowbook
synced 2024-09-26 00:30:52 +02:00
Add frame around code blocks in latex
This commit is contained in:
parent
ba32705827
commit
7837310f22
@ -333,9 +333,13 @@ impl<'a> Renderer for LatexRenderer<'a> {
|
||||
}
|
||||
Token::CodeBlock(ref language, ref vec) => {
|
||||
self.escape = false;
|
||||
let res = self.render_vec(vec)?;
|
||||
let mut res = self.render_vec(vec)?;
|
||||
// Remove trailing newline
|
||||
if res.ends_with('\n') {
|
||||
res.pop();
|
||||
}
|
||||
self.escape = true;
|
||||
let mut res = if self.book.options.get_str("rendering.highlight").unwrap() == "syntect" {
|
||||
res = if self.book.options.get_str("rendering.highlight").unwrap() == "syntect" {
|
||||
self.syntax.to_tex(&res, language)
|
||||
} else {
|
||||
format!("\\begin{{spverbatim}}
|
||||
@ -343,8 +347,9 @@ impl<'a> Renderer for LatexRenderer<'a> {
|
||||
\\end{{spverbatim}}",
|
||||
code = res)
|
||||
};
|
||||
res.push_str("\n\n");
|
||||
// res.push_str("{\\vspace{1em}}\n");
|
||||
res = format!("\\begin{{mdframed}}
|
||||
{}
|
||||
\\end{{mdframed}}", res);
|
||||
Ok(res)
|
||||
}
|
||||
Token::Rule => Ok(String::from("\\HRule\n")),
|
||||
|
@ -65,7 +65,7 @@ impl Syntax {
|
||||
for (style, text) in regions.into_iter() {
|
||||
let mut content = escape::tex(text).into_owned();
|
||||
content = content.replace('\n', "\\\\\n")
|
||||
.replace(' ', "\\hphantom{ }");
|
||||
.replace(' ', "\\hphantom{ }\\allowbreak{}");
|
||||
content = format!("\\texttt{{{}}}", content);
|
||||
if style.foreground != BLACK {
|
||||
let r = style.foreground.r as f32 / 255.0;
|
||||
@ -88,11 +88,7 @@ impl Syntax {
|
||||
}
|
||||
result.push_str(&content);
|
||||
}
|
||||
format!("{{\\vspace{{1em}}}}
|
||||
\\begin{{sloppypar}}
|
||||
{{\\setlength{{\\parindent}}{{0cm}}{}}}
|
||||
\\end{{sloppypar}}",
|
||||
result)
|
||||
format!("{{\\sloppy {}}}", result)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,10 +11,11 @@
|
||||
\usepackage[<<&tex_lang>>]{babel}
|
||||
|
||||
\usepackage{fancyhdr}
|
||||
\usepackage{spverbatim}
|
||||
\usepackage{booktabs}
|
||||
\usepackage{spverbatim}
|
||||
\usepackage{graphicx}
|
||||
\usepackage{color}
|
||||
\usepackage{mdframed}
|
||||
<<#initials>> % only if use_initials is set to true
|
||||
\usepackage{lettrine}
|
||||
<</initials>>
|
||||
@ -25,7 +26,6 @@
|
||||
\usepackage[anythingbreaks]{breakurl}
|
||||
<</xelatex>>
|
||||
|
||||
% TODO: provide a way to configure
|
||||
\usepackage[<<&papersize>>, top=2cm, bottom=1.5cm,
|
||||
<<#book>> left=2.5cm,right=1.5cm<</book>><<^book>> left=2cm,right=2cm<</book>>]{geometry}%A5 by default
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user