Skip to content

Commit

Permalink
Add tex.cover option
Browse files Browse the repository at this point in the history
  • Loading branch information
crowdagger committed May 13, 2024
1 parent fca4301 commit 5cbd8f8
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ ChangeLog
* Use rust-i18n for internationalization instead of hackish (and unmaintained) crowbook-intl
* HTML:
* When hovering a mouse hover a footnote, display its content to the side of the page.
* LaTeX:
* Add `tex.cover` option to embed the cover image in the PDF file

0.16.1 (2023-08-04)
-----------------------
Expand Down
1 change: 1 addition & 0 deletions lang/lib/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ opt:
tex_command: LaTeX command to use for generating PDF
tex_tmpl: Path of a LaTeX template file
tex_tmpl_add: Inline code added in the LaTeX template
tex_cover: "Add cover to the LaTeX/PDF file"
tex_class: LaTeX class to use
tex_title: If true, generate a title with \\maketitle
tex_paper_size: Specifies the size of the page
Expand Down
6 changes: 3 additions & 3 deletions lang/lib/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ ui:
waiting: "en attente..."
options: "mise en place des options"
chapters: "Analyse des chapitres"
processing: Analyse...
processing: "Analyse..."
processing_file: "Analyse de %{file} en cours..."
finished: "Terminé"
generated: "généré %{path}"
error: ERREUR
error: "ERREUR"
error:
markdown: "Erreur dans l'analyse du Markdown : %{error}"
config: "Erreur dans l'analyse du fichier de configuration : "
Expand Down Expand Up @@ -81,7 +81,7 @@ format:
debug:
yaml_replace: "Inline YAML block replaced %{key} previously set to %{old_val} to %{new_val}"
yaml_set: "Inline YAML block set %{key} to %{value}"
yaml_ignore: "Ignoring YAML block:\n%{block}"
yaml_ignore: "Bloc YAML ignoré:\n%{block}"
found_yaml_block: "Found something that looked like a YAML block:\n%{block}"
found_yaml_block2: "... but it didn't parse correctly as YAML('%{error}'), so treating it like Markdown."
msg:
Expand Down
2 changes: 2 additions & 0 deletions src/lib/bookoptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ epub.toc.extras:bool:true # {epub_toc}
epub.escape_nb_spaces:bool:true # {nb_spaces}
# {tex_opt}
tex.cover:bool:false # {tex_cover}
tex.highlight.theme:str # {tex_theme}
tex.links_as_footnotes:bool:true # {tex_links}
tex.command:str:xelatex # {tex_command}
Expand Down Expand Up @@ -291,6 +292,7 @@ output.odt:path # {removed}
titlepage_xhtml = t!("opt.titlepage_xhtml"),
epub_toc = t!("opt.epub_toc"),

tex_cover = t!("opt.tex_cover"),
tex_links = t!("opt.tex_links"),
tex_command = t!("opt.tex_command"),
tex_tmpl = t!("opt.tex_tmpl"),
Expand Down
14 changes: 13 additions & 1 deletion src/lib/latex.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2016-2020 Élisabeth HENRY.
// Copyright (C) 2016-2024 Élisabeth HENRY.
//
// This file is part of Crowbook.
//
Expand Down Expand Up @@ -228,6 +228,7 @@ impl<'a> LatexRenderer<'a> {
data.insert("tex_title".into(), self.book.options.get_bool("tex.title").unwrap().into());
data.insert("papersize".into(), self.book.options.get_str("tex.paper.size").unwrap().into());
data.insert("stdpage".into(), self.book.options.get_bool("tex.stdpage").unwrap().into());

data.insert("use_url".into(), self.book.features.url.into());
data.insert("use_taskitem".into(), self.book.features.taskitem.into());
data.insert("use_tables".into(), self.book.features.table.into());
Expand All @@ -237,6 +238,17 @@ impl<'a> LatexRenderer<'a> {
data.insert("tex_lang".into(), tex_lang.into());
let tex_tmpl_add = self.book.options.get_str("tex.template.add").unwrap_or("".into());
data.insert("additional_code".into(), tex_tmpl_add.into());
let mut use_cover = false;
if self.book.options.get_bool("tex.cover").unwrap() {
if let Ok(cover_path) = self.book.options.get_path("cover") {
if !cover_path.is_empty() {
use_cover = true;
data.insert("cover_path".into(), cover_path.into());
}
}
}
data.insert("use_cover".into(), use_cover.into());


if let Ok(tex_font_size) = self.book.options.get_i32("tex.font.size") {
data.insert("has_tex_size".into(), true.into());
Expand Down
15 changes: 15 additions & 0 deletions templates/latex/template.tex
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@
<# if book #>
% Redefine the \maketitle command, only for book class (not used if stdpage option is set to true)
\renewcommand{\maketitle}{
<# if use_cover #>
% cover
\includepdf{<<cover_path>>}
\newpage
% Empty left page
\thispagestyle{empty}
\cleardoublepage

<# endif #>

% First page with only the title
\thispagestyle{empty}
\vspace*{\stretch{1}}
Expand Down Expand Up @@ -202,6 +212,11 @@
}
<# endif #>

<# if use_cover #>
% Only included if tex.cover is set to true
\usepackage{pdfpages}
<# endif #>

<# if use_images #>
% Only included if document contains images
\usepackage{graphicx}
Expand Down

0 comments on commit 5cbd8f8

Please sign in to comment.