mirror of
https://github.com/lise-henry/crowbook
synced 2024-11-18 00:13:55 +01:00
add option to have custom command for latex->pdf
This commit is contained in:
parent
1f8f6129c2
commit
1db5f79107
@ -49,6 +49,9 @@ pub struct Book {
|
||||
pub nb_char: char,
|
||||
pub numbering_template: String, // template for chapter numbering
|
||||
pub verbose: bool,
|
||||
|
||||
// for latex
|
||||
pub tex_command: String,
|
||||
}
|
||||
|
||||
impl Book {
|
||||
@ -72,6 +75,7 @@ impl Book {
|
||||
output_html: None,
|
||||
output_pdf: None,
|
||||
output_tex: None,
|
||||
tex_command: String::from("pdflatex"),
|
||||
}
|
||||
}
|
||||
|
||||
@ -209,6 +213,7 @@ impl Book {
|
||||
"output_html" | "output-html" => self.output_html = Some(String::from(value)),
|
||||
"output_tex" | "output-tex" => self.output_tex = Some(String::from(value)),
|
||||
"output_pdf" | "output-pdf" => self.output_pdf = Some(String::from(value)),
|
||||
"tex_command" | "tex-command" => self.tex_command = String::from(value),
|
||||
"author" => self.author = String::from(value),
|
||||
"title" => self.title = String::from(value),
|
||||
"cover" => self.cover = Some(String::from(value)),
|
||||
|
@ -30,7 +30,7 @@ impl<'a> LatexRenderer<'a> {
|
||||
let content = try!(self.render_book());
|
||||
let mut zipper = try!(Zipper::new(&self.book.temp_dir, &vec!()));
|
||||
try!(zipper.write(&tex_file, &content.as_bytes()));
|
||||
zipper.generate_pdf(&tex_file, pdf_file)
|
||||
zipper.generate_pdf(&self.book.tex_command, &tex_file, pdf_file)
|
||||
} else {
|
||||
Err(Error::Render("no output pdf file specified in book config"))
|
||||
}
|
||||
|
@ -60,20 +60,21 @@ impl Zipper {
|
||||
let dir = try!(env::current_dir().map_err(|_| Error::Zipper("could not get current directory".to_owned())));
|
||||
try!(env::set_current_dir(&self.path).map_err(|_| Error::Zipper("could not change current directory".to_owned())));
|
||||
|
||||
let output = try!(command.args(&self.args)
|
||||
let res_output = command.args(&self.args)
|
||||
.output()
|
||||
.map_err(|e| Error::Zipper(format!("failed to execute process: {}", e))));
|
||||
.map_err(|e| Error::Zipper(format!("failed to execute process: {}", e)));
|
||||
try!(env::set_current_dir(dir).map_err(|_| Error::Zipper("could not change back to old directory".to_owned())));
|
||||
let output = try!(res_output);
|
||||
try!(fs::copy(self.path.join(file), file).map_err(|_| {
|
||||
println!("{}", str::from_utf8(&output.stdout).unwrap());
|
||||
println!("{}", &String::from_utf8_lossy(&output.stdout));
|
||||
Error::Zipper(format!("could not copy file {}", file))
|
||||
}));
|
||||
Ok(String::from_utf8_lossy(&output.stdout).into_owned())
|
||||
}
|
||||
|
||||
/// generate a pdf file into given file name
|
||||
pub fn generate_pdf(&mut self, tex_file: &str, pdf_file: &str) -> Result<String> {
|
||||
let mut command = Command::new("pdflatex");
|
||||
pub fn generate_pdf(&mut self, command: &str, tex_file: &str, pdf_file: &str) -> Result<String> {
|
||||
let mut command = Command::new(command);
|
||||
command.arg(tex_file);
|
||||
self.run_command(command, pdf_file)
|
||||
}
|
||||
@ -89,8 +90,8 @@ impl Zipper {
|
||||
|
||||
impl Drop for Zipper {
|
||||
fn drop(&mut self) {
|
||||
if !fs::remove_dir_all(&self.path).is_ok() {
|
||||
println!("Error in zipper: could not delete temporary directory");
|
||||
if let Err(err) = fs::remove_dir_all(&self.path) {
|
||||
println!("Error in zipper: could not delete temporary directory {}, error: {}", self.path.to_string_lossy(), err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user