diff --git a/src/lib/book.rs b/src/lib/book.rs index 17348ba..b4a4273 100644 --- a/src/lib/book.rs +++ b/src/lib/book.rs @@ -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)), diff --git a/src/lib/latex.rs b/src/lib/latex.rs index 4cb0c8d..4d65c81 100644 --- a/src/lib/latex.rs +++ b/src/lib/latex.rs @@ -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")) } diff --git a/src/lib/zipper.rs b/src/lib/zipper.rs index 929012a..588f5de 100644 --- a/src/lib/zipper.rs +++ b/src/lib/zipper.rs @@ -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 { - let mut command = Command::new("pdflatex"); + pub fn generate_pdf(&mut self, command: &str, tex_file: &str, pdf_file: &str) -> Result { + 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); } } }