Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:07
Show Gist options
  • Save tychoish/33ba7a20c97ae9c228e0 to your computer and use it in GitHub Desktop.
Save tychoish/33ba7a20c97ae9c228e0 to your computer and use it in GitHub Desktop.

Novel Makefile


This makefile-based build system provides a bit of extra gloss/configuration for using Sphinx and sffms to build conventional manuscripts and websites for novel-like hypertexts.

Usage Notes

This makefile is derives from the default Sphinx makefile, with a number of tweaks that I've been making to this configuration:

  • The PDF build system is much abbreviated, and included in the main makefile. This is a bit less conservative than the default for this file, but it works just as well in most situations. The output is also much less verbose.

  • The build is a lot less noisy. Errors are still printed, which makes it great for automated build systems (i.e. continuous integration.)

  • Sphinx will build two sites, one, in an outline/ directory would store the outline and working notes of a story, while the other in a source/ directory would store the actual text of the novel. *In practice, I also seem to keep another notes/ directory around for less formal and more early stage note taking.

  • There's a post-processing script for sffms that makes section headers work right for my usual structure. Tweak or remove at your discretion.

  • You must install Sphinx and sffms and have them accessible to the build process.


File: makefile

 SPHINXOPTS    = -c ./
 SPHINXBUILD   = sphinx-build
 PAPER	      =
 BUILDDIR      = build
 SFFMS_CLEANUP = bin/sffms-cleanup
 TITLE = name.title-of-book.pdf
 # Internal variables.
 PAPEROPT_a4	= -D latex_paper_size=a4
 PAPEROPT_letter = -D latex_paper_size=letter
 .PHONY: html sffms dirhtml singlehtml ms outline outline-single outline-pdf help
 	@echo "A build system for generating novels and outlines using 'Sphinx' and 'sffms.'"
 	@echo "All build products are located within '$(BUILDDIR).' Some related scritps are in,"
 	@echo "'bin/'. See <> for more information."
 	@echo ""
 	@echo "Targets:"
 	@echo ""
 	@echo "  outline - builds an html website of the outline."
 	@echo "  outline-single - builds a single html page version of the outline."
 	@echo "  outline-pdf - builds a pdf of the outline using Sphinx's LaTeX builder."
 	@echo ""
 	@echo "  html - builds a html site of the text, with each page in its own file."
 	@echo "  dirhtml - builds a html site with each page an index.html, in a directory."
 	@echo "  singlehtml - builds the text in a single page."
 	@echo ""
 	@echo "  ms - builds an sffms styled manuscript PDF named $(TITLE)"
 	@echo "  ms-tex - builds and processes a sffms TeX file."
 	@echo ""
 	@echo "  clean - removes $(BUILDDIR)/"
 # Outline Generation
 	$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) outline $(BUILDDIR)/outline
 	@echo "[OUTLINE] (html) build complete."
 	$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) outline $(BUILDDIR)/outline-single
 	@echo "[OUTLINE] (single-html) build complete."
 	$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) outline $(BUILDDIR)/outline-pdf
 	@echo "[OUTLINE] pdf build complete."
 # Sphinx (HTML) Build System - Novel
 	$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) source $(BUILDDIR)/html
 	@echo "[HTML] build complete."
 	$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) source $(BUILDDIR)/dirhtml
 	@echo "[DIR] build complete."
 	$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) source $(BUILDDIR)/singlehtml
 	@echo "[SINGLE] build complete."
 # Manuscript Build System - Novel
 SFFMS_CLEANUP = bin/sffms-cleanup
 	@$(SFFMS_CLEANUP) $(BUILDDIR)/sffms/*tex
 	@echo "[SFFMS] tex santized."
 	@mv $< $@
 	@echo "[SFFMS] pdf renamed. See: $@"
 	$(SPHINXBUILD) -b sffms $(ALLSPHINXOPTS) source $(BUILDDIR)/sffms
 	@echo "[SFFMS] tex generated."
 # PDF Build System
 PDFLATEXCOMMAND = TEXINPUTS=".:$(BUILDDIR)/sffms/:" pdflatex --interaction batchmode --output-directory $(BUILDDIR)/sffms/
 	@$(PDFLATEXCOMMAND) $(LATEXOPTS) '$<' >|$@.log
 	@echo "[PDF]: (1/3) pdflatex $<"
 #	@makeindex -s $(BUILDDIR)/latex/ '$(basename $<).idx' >>$@.log 2>&1
 #	@echo "[PDF]: (2/3) Indexing: $(basename $<).idx"
 	@$(PDFLATEXCOMMAND) $(LATEXOPTS) '$<' >>$@.log
 	@echo "[PDF]: (2/3) pdflatex $<"
 	@$(PDFLATEXCOMMAND) $(LATEXOPTS) '$<' >>$@.log
 	@echo "[PDF]: (3/3) pdflatex $<"
 	@echo "[PDF]: see '$@.log' for a full report of the pdf build process."
 # Meta
 	rm -rf build

The following file, used above, does a little bit of post-processing that makes using sffms with longer more structured works possible. Use, or not, as you wish:

File: bin/sffms-cleanup


 if [ "`uname`" = "Linux" ]; then
    SED_ARGS='-i -r'
 elif [ "`uname`" = "Darwin" ]; then
    SED_ARGS='-i "" -E'
    echo "You're probably using an unsupported system. Do some testing, edit this file, and try again."
    exit 1


 while [ `pcregrep -c -M "^.chapter(.*)\{(.*)\}\n+.newscene" $SFFMS_FILE` -gt 0 ]; do
     sed $SED_ARGS ':a;N;$!ba;s@(.)chapter.*\{(.*)\}\n{2}.newscene@\1chapter{\2}@m' $SFFMS_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment