Skip to content

Commit 9d23511

Browse files
committed
Fix the hierarchy for the Front Matter in LaTeX
This is an ugly hack but necessary for the LaTeX generation. Basically the problem is that in order to get the Chapters as \chapters generated there needs to be a ### heading present before the *** Front Matter ***. If not Sphinx will generate the chapters as \part in LaTeX. I tried conditional `.. only:: latex` syntax but that does not work with top level section (needs always to be one level lower). So I ended up to hack this by inserting the needed ### heading via Makefile for the LaTeX version only (the HTML version would be messed up if this header is present). Drawbacks: * I use `git checkout` to make sure the `index.rst` is pristine before adding my the header. This means any changes to that file need to be committed before running `make`. * The PDF version contains the "Front Matter" entry in the TOC
1 parent 957a8a8 commit 9d23511

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

text/Makefile

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,32 @@ ebook: epub mobi
231231

232232
latex: latex-letter latex-a4
233233

234-
latex-letter: specs results images
234+
latex-letter: specs results images
235+
@echo
236+
@echo "Applying horrible LaTeX hack..."
237+
git checkout $(SOURCEDIR)/index.rst # make sure we have pristine index.rst
238+
cp $(SOURCEDIR)/index.rst $(SOURCEDIR)/index.rst.orig
239+
(echo "#####\nDUMMY\n#####"; cat $(SOURCEDIR)/index.rst.orig) > $(SOURCEDIR)/index.rst
240+
@echo
235241
$(SPHINXBUILD) -b latex -t latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
242+
@echo "Reverting horrible LaTeX hack..."
243+
git checkout $(SOURCEDIR)/index.rst # revert back to pristine index.rst
236244
@echo
237245
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
238246
@echo "Run \`make' in that directory to run these through (pdf)latex" \
239247
"(use \`make latexpdf' here to do that automatically)."
240248

241-
latex-a4: specs results images
249+
250+
latex-a4: specs results images
251+
@echo
252+
@echo "Applying horrible LaTeX hack..."
253+
git checkout $(SOURCEDIR)/index.rst # make sure we have pristine index.rst
254+
cp $(SOURCEDIR)/index.rst $(SOURCEDIR)/index.rst.orig
255+
(echo "#####\nDUMMY\n#####"; cat $(SOURCEDIR)/index.rst.orig) > $(SOURCEDIR)/index.rst
256+
@echo
242257
$(SPHINXBUILD) -b latex -t latex -t a4 $(ALLSPHINXOPTS) $(BUILDDIR)/latex-a4
258+
@echo "Reverting horrible LaTeX hack..."
259+
git checkout $(SOURCEDIR)/index.rst # revert back to pristine index.rst
243260
@echo
244261
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex-a4."
245262
@echo "Run \`make' in that directory to run these through (pdf)latex" \

0 commit comments

Comments
 (0)