diff --git a/Makefile b/Makefile index e1393e5..ad96fc7 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/default.nix b/default.nix index 1f4c1ac..335a5ee 100644 --- a/default.nix +++ b/default.nix @@ -2,6 +2,8 @@ with import {}; mkShell { buildInputs = [ + pdftk + ruby pandoc (texlive.combine { inherit (texlive) diff --git a/intro.tex b/intro.tex index 5edc7bb..d2e39d9 100644 --- a/intro.tex +++ b/intro.tex @@ -72,8 +72,8 @@ \end{titlepage} \pagebreak -\section*{Foreword} -% TODO +\section*{Table of Contents} +\input{generated.toc} \pagebreak \section{Project Introduction} diff --git a/toc.rb b/toc.rb new file mode 100644 index 0000000..a661848 --- /dev/null +++ b/toc.rb @@ -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