Configurable lateX template
This commit is contained in:
parent
a9951ab37e
commit
15dcadf739
|
@ -4,19 +4,20 @@ use std::process::Command;
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
pub fn linear(content: &str, output: PathBuf, basesize: &u8, metadata: Vec<(String, String)>) -> Result<u8> {
|
pub fn linear(content: &str, output: PathBuf, basesize: &u8, metadata: Vec<(String, String)>, template: &Option<String>) -> Result<u8> {
|
||||||
let mut pandoc = pandoc::new();
|
let mut pandoc = pandoc::new();
|
||||||
pandoc.set_input(pandoc::InputKind::Pipe(content.to_string()));
|
pandoc.set_input(pandoc::InputKind::Pipe(content.to_string()));
|
||||||
pandoc.set_input_format(pandoc::InputFormat::Commonmark, Vec::new());
|
pandoc.set_input_format(pandoc::InputFormat::Commonmark, Vec::new());
|
||||||
pandoc.set_output_format(pandoc::OutputFormat::Latex, Vec::new());
|
pandoc.set_output_format(pandoc::OutputFormat::Latex, Vec::new());
|
||||||
pandoc.add_option(pandoc::PandocOption::PdfEngine("pdflatex".into()));
|
pandoc.add_option(pandoc::PandocOption::PdfEngine("pdflatex".into()));
|
||||||
// TODO: configurable template
|
|
||||||
pandoc.set_latex_template("eisvogel");
|
|
||||||
//pandoc.set_variable("links-as-notes", "true");
|
|
||||||
for (key, value) in metadata {
|
for (key, value) in metadata {
|
||||||
pandoc.set_variable(&key, &value);
|
pandoc.set_variable(&key, &value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if template.is_some() {
|
||||||
|
pandoc.set_latex_template(&template.as_ref().unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
let mut current_size = basesize.clone();
|
let mut current_size = basesize.clone();
|
||||||
let mut sheets: Option<u8> = None;
|
let mut sheets: Option<u8> = None;
|
||||||
while current_size <= basesize + 10 {
|
while current_size <= basesize + 10 {
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -37,9 +37,13 @@ struct Cli {
|
||||||
book: bool,
|
book: bool,
|
||||||
|
|
||||||
#[structopt(short = "s", long = "size", default_value = "11")]
|
#[structopt(short = "s", long = "size", default_value = "11")]
|
||||||
/// The smallest size
|
/// The smallest size to generate the PDF with
|
||||||
size: u8,
|
size: u8,
|
||||||
|
|
||||||
|
#[structopt(short = "t", long = "template")]
|
||||||
|
/// The lateX template to use
|
||||||
|
template: Option<String>,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
|
@ -76,19 +80,19 @@ fn main() -> Result<()> {
|
||||||
tmp.push(hasher.finish().to_string());
|
tmp.push(hasher.finish().to_string());
|
||||||
tmp.set_extension("pdf");
|
tmp.set_extension("pdf");
|
||||||
|
|
||||||
let pages_count = generate::linear(&content, tmp.clone(), &cli.size, metadata)?;
|
let pages_count = generate::linear(&content, tmp.clone(), &cli.size, metadata, &cli.template)?;
|
||||||
println!("Intermediary step: generated linear output to {:?} ({} pages)", &tmp, pages_count);
|
println!("Intermediary step: generated linear output to {:?} ({} pages)", &tmp, pages_count);
|
||||||
generate::book(&tmp, &output)?;
|
generate::book(&tmp, &output)?;
|
||||||
println!("Generated A5 booklet output to {:?}", output);
|
println!("Generated A5 booklet output to {:?}", output);
|
||||||
},
|
},
|
||||||
(false, true) => {
|
(false, true) => {
|
||||||
// Only linear output
|
// Only linear output
|
||||||
let pages_count = generate::linear(&content, output.clone(), &cli.size, metadata)?;
|
let pages_count = generate::linear(&content, output.clone(), &cli.size, metadata, &cli.template)?;
|
||||||
println!("Generated linear A4 output to {:?} ({} pages)", output, pages_count);
|
println!("Generated linear A4 output to {:?} ({} pages)", output, pages_count);
|
||||||
},
|
},
|
||||||
(false, false) => {
|
(false, false) => {
|
||||||
// Both outputs
|
// Both outputs
|
||||||
let pages_count = generate::linear(&content, output.clone(), &cli.size, metadata)?;
|
let pages_count = generate::linear(&content, output.clone(), &cli.size, metadata, &cli.template)?;
|
||||||
println!("Generated linear A4 output to {:?} ({} pages)", output, pages_count);
|
println!("Generated linear A4 output to {:?} ({} pages)", output, pages_count);
|
||||||
let mut book_output = output.clone();
|
let mut book_output = output.clone();
|
||||||
book_output.set_extension("book.pdf");
|
book_output.set_extension("book.pdf");
|
||||||
|
|
Loading…
Reference in New Issue