49

By default, Sphinx documentation outputs a PDF that's formatted for duplex printing. So there is a blank page between the title page and the TOC, the TOC and the introduction, the introduction and the first section, etc.

My users are always going to look at the PDF online. So I would like to remove these blank pages.

This seems to be a vexed issue in Sphinx. See this email thread.

This user suggests two solutions, but neither work for me. Curiously, the first solution:

latex_elements = {
     'classoptions': ',oneside',
}

gives me ! Package babel Error: You haven't specified a language option.

The second option:

latex_font_size = '10pt,oneside'

runs, but produces a PDF that only has the odd-numbered pages of my document. Alas.

Does anyone know how to produce a PDF without these blank pages?

mzjn
  • 48,958
  • 13
  • 128
  • 248
AP257
  • 89,519
  • 86
  • 202
  • 261
  • 2
    Since your users are going to read this exclusively online, wouldn't it be more friendly to have Sphinx output, say, HTML, and save them the agony of online PDF viewing? – Brent.Longborough Feb 28 '12 at 08:35
  • @Brent.Longborough, this is just not realistic. HTML was not created for page layout, but today most everybody tries to use for ... page layout, even online. With so-so results. I prefer a good looking PDF, even online, to lots of HTML. Especially what comes out of Sphinx, unless you customize it with your own CSS. I regard HTML as a (mostly) working hack. Look up Display Postscript sometime if you are not familiar with it, imagine a web with that, it would be awesome. – Prof. Falken Feb 08 '13 at 10:02
  • `latex_font_size` didn't work for me either – Csaba Toth Nov 25 '19 at 21:10

1 Answers1

75

Put this in your source/conf.py configuration file in the "Options for LaTeX output" section:

latex_elements = {
  'extraclassoptions': 'openany,oneside'
}
funky-future
  • 3,716
  • 1
  • 30
  • 43
Noah Heldman
  • 6,724
  • 3
  • 40
  • 40
  • 30
    It's even better with `openany` parameter, it removes even the blank page after the table of contents. Example: `latex_elements = { 'classoptions': ',openany,oneside', 'babel' : '\\usepackage[polish]{babel}' }` – flegmatyk May 22 '11 at 11:26
  • 9
    Excellent, great tip! I'm still not ready to make the switch to polish though... ;) – Noah Heldman May 27 '11 at 18:50
  • @davidjb I don't get any empty pages at the end with `openany`. I went ahead and added it to the answer since it's so great. – Daniel Darabos Aug 24 '16 at 09:28
  • `latex_elements` is already defined inside a Sphinx quickstart `conf.py`, so for any one else using this example make sure to merge or delete the old definition to avoid the auto-generated code masking the new code. – Bryce Guinta Feb 04 '17 at 23:22
  • the 'babel' element in @flegmatyk answer is not necessary in current versions of Sphinx. – nsg May 17 '17 at 14:40
  • 3
    ``'extraclassoptions'`` is better for that than ``'classoptions'``: the latter is for internal use by Sphinx. See http://www.sphinx-doc.org/en/stable/config.html#confval-latex_elements (for some reason ``'extraclassoptions'`` got documented only at 1.6 but was available since 1.2) –  May 20 '17 at 13:14