Skip to content

Instantly share code, notes, and snippets.

@jelc53
Last active March 22, 2024 15:50
Show Gist options
  • Save jelc53/8b3799013c691c3ef0ddfaa900c54777 to your computer and use it in GitHub Desktop.
Save jelc53/8b3799013c691c3ef0ddfaa900c54777 to your computer and use it in GitHub Desktop.
# Make sure latex installed (example for mac below)
brew install --cask mactex
# Install texlive package to interpret sphinx rst docs
brew install texlive
# Open TeX Live Utility and install for "latexmk"
Tex Live Utility > latexmk > install
# (Option 1) You should now be able to run the following command from the sphinx docs directory
# creates latex and pdf files here: `./_build/latex/<sphinx-project-name.pdf>`
# reference: https://stackoverflow.com/questions/29172930/sphinx-pdf-output-using-latexpdf
make latexpdf
# (Option 2) Run component commands for making latexpdf one-by-one
# note, this helps for isolating latex compilation vs pdf build issues
poetry run sphinx-build -b latex source build/latex
make -C $build/latex all-pdf
# (Option 3) Automate using makefile below
# You can set these variables from the command line.
SPHINXOPTS ?=
SPHINXBUILD = sphinx-build
SOURCEDIR = docs/source
BUILDDIR = docs/build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# LaTeX and PDF targets
latex:
@$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
latexpdf:
@$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
# Note: for math specifically, sphinx (our default) expects you to use single backslash e.g. \sum_{i=0}^{n} \text{volume}_{i}
# but when executing makefile for latexpdf, replace with double backslash e.g. \\sum{i=0}^{n} \\text{volume}_{i}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment