2 #! nix shell --impure --expr ``
3 #! nix with (builtins.getFlake "git+file://${toString ./.}/..").packages.${builtins.currentSystem};
7 #! nix pkgs.dejavu_fonts
9 #! nix pkgs.freefont_ttf
10 #! nix pkgs.gyre-fonts # TrueType substitutes for standard PostScript fonts
12 #! nix pkgs.liberation_ttf
14 #! nix pkgs.noto-fonts-emoji
15 #! nix pkgs.tex-gyre.adventor
16 #! nix pkgs.tex-gyre.bonum
17 #! nix pkgs.tex-gyre.chorus
18 #! nix pkgs.tex-gyre.cursor
19 #! nix pkgs.tex-gyre.heros
20 #! nix pkgs.tex-gyre.pagella
21 #! nix pkgs.tex-gyre.schola
22 #! nix pkgs.tex-gyre.termes
26 #! nix (pkgs.writeShellScriptBin "interpreter" ''
27 #! nix # used by luaotfload (lualatex)
28 #! nix export OSFONTDIR="${lib.concatStringsSep "//:" (map toString fonts)}"
34 #! nix (pkgs.texlive.combine {
35 #! nix inherit (pkgs.texlive)
36 #! nix collection-fontsrecommended
37 #! nix collection-langenglish
38 #! nix collection-langfrench
39 #! nix collection-latexrecommended
40 #! nix collection-luatex
50 #! nix --command interpreter
53 epubDir
=$(realpath -e "$(dirname "$epubPath")")
54 styleDir=$(realpath -e "$(dirname "$0")")/styles
56 pdfFile
="$outDir"/out.pdf
60 # Converting EPUB to PDF
64 --include-in-header "$styleDir"/epub.header.tex \
65 --filter "$epubDir"/filter \
67 --pdf-engine lualatex \
71 --top-level-division chapter \
72 -V documentclass
=scrbook \
73 -V classoption
=english \
74 -V mainfont
="TeX Gyre Termes" \
81 # Slicing on chapters and splitting into chunks of at most 18 pages (for easy binding)
82 mkdir -p "$outDir"/sections
83 pdftk
"$pdfFile" dump_data
| grep '^BookmarkPageNumber:' |
90 "$outDir"/sections
/sectionNum
="$sectionNum".pages
="$sectionPages".chunk
=%d.pdf \
91 --pages "$pdfFile" "$sectionPages" -- \
94 while read -r _BookmarkPageNumber sectionEnd
; do
95 test "$sectionEnd" != 1 || continue
96 sectionPages
=$sectionBegin-$((sectionEnd-1))
98 sectionNum
=$((sectionNum+1))
99 sectionBegin
=$sectionEnd
101 sectionPages
="$sectionBegin"-r1
105 # Converting to booklet
106 find "$outDir"/sections
-type f
|
108 while read -r pdfSection
; do
109 # Margins have already been set correctly by the geometry package in header.tex
110 # pdfbook2 fails to move the .pdf over filesystems
112 --paper "${paper:-a4paper}" \
113 --outer-margin "${outerMargin:-80}" \
114 --inner-margin "${innerMargin:-150}" \
115 --top-margin "${topmargin:-30}" \
116 --bottom-margin "${bottomMargin:-30}" \
120 # Split odd and even pages to print in the same direction
121 pdftk
"${pdfSection%.pdf}"-book.pdf
cat oddSouth output
"${pdfSection%.pdf}".book.odds.pdf
122 pdftk
"${pdfSection%.pdf}"-book.pdf
cat even output
"${pdfSection%.pdf}".book.even.pdf
123 rm "${pdfSection%.pdf}"-book.pdf