Automatically generate custom table of contents.

This commit is contained in:
Danila Fedorin 2020-05-29 13:28:04 -07:00
parent a4a46c8330
commit 28e3a7a068
4 changed files with 58 additions and 3 deletions

View File

@ -2,6 +2,7 @@ archive.pdf: intro.pdf requirements.pdf design-doc.pdf \
binary/techreview-ryan.pdf techreview-daniel.pdf binary/techreview-matt.pdf \
binary/blog-ryan.pdf blog-daniel.pdf binary/blog-matt.pdf \
readme.pdf resources.pdf reflection.pdf listings.pdf images.pdf review.pdf todo.pdf
ruby toc.rb
pdfjam --no-tidy --outfile archive.pdf -- intro.pdf requirements.pdf design-doc.pdf \
binary/techreview-ryan.pdf techreview-daniel.pdf binary/techreview-matt.pdf \
binary/blog-ryan.pdf blog-daniel.pdf binary/blog-matt.pdf \
@ -72,7 +73,10 @@ review-collar.tex: external/collar/REVIEW.md
review.pdf: review-app.tex review-server.tex review-collar.tex review.tex
pdflatex review.tex
intro.pdf: intro.tex
generated.toc:
touch generated.toc
intro.pdf: intro.tex generated.toc
pdflatex intro.tex
blog-daniel.pdf: external/blog-daniel/blog.tex

View File

@ -2,6 +2,8 @@ with import <nixpkgs> {};
mkShell {
buildInputs = [
pdftk
ruby
pandoc
(texlive.combine {
inherit (texlive)

View File

@ -72,8 +72,8 @@
\end{titlepage}
\pagebreak
\section*{Foreword}
% TODO
\section*{Table of Contents}
\input{generated.toc}
\pagebreak
\section{Project Introduction}

49
toc.rb Normal file
View File

@ -0,0 +1,49 @@
def all_pages(name, pdf)
return [:pdf, name, pdf]
end
def all_no_entry(name, pdf)
return [:pdf_no_entry, name, pdf]
end
def section_offset(name, page)
return [:section, name, page]
end
pdf_structure = [
all_no_entry("Introduction", "intro.pdf"),
all_pages("Requirements Document", "requirements.pdf"),
all_pages("Design Document", "design-doc.pdf"),
all_pages("Ryan Alder's Tech Review", "binary/techreview-ryan.pdf"),
all_pages("Danila Fedorin's Tech Review", "techreview-daniel.pdf"),
all_pages("Matthew Sessions' Tech Review", "binary/techreview-matt.pdf"),
all_pages("Ryan Alder's Blog Posts", "binary/blog-ryan.pdf"),
all_pages("Danila Fedorin's Blog Posts", "blog-daniel.pdf"),
all_pages("Matthew Sessions' Blog Posts", "binary/blog-matt.pdf"),
all_pages("Project Documentation and READMEs", "readme.pdf"),
all_pages("Learning Resources", "resources.pdf"),
all_pages("Conclusions and Reflections", "reflection.pdf"),
all_pages("Appendix 1: Essential Code Listings", "listings.pdf"),
all_pages("Appendix 2: Project Images", "images.pdf"),
all_pages("Appendix 2: Code Review Changes", "review.pdf"),
all_pages("Appendix 4: Remaining Work", "todo.pdf")
]
toc = File.open("generated.toc", "w")
page_tally = 1
section_counter = 1
pdf_structure.each do |entry|
next unless entry[0] == :pdf or entry[0] == :pdf_no_entry
type, name, pdf = entry
page_count = `pdftk #{pdf} dump_data | grep NumberOfPages`.split(":")[1].to_i
output = "\\contentsline {section}{\\numberline {#{section_counter}}#{name}}{#{page_tally}}%"
if type == :pdf
toc.puts output
puts output
end
section_counter += 1
page_tally += page_count
end