1. Bruce Eckel
  2. Python 3 Patterns & Idioms
Issue #1 resolved

PDF Formatting so we can figure out code width

Bruce Eckel
repo owner created an issue

Here's a project for someone -- we need to modify the build system so that the PDF version of the book comes out in 7" x 9.25" page format (the same as most computer books, such as the Python Cookbook). This way we can verify whether 80 columns is OK for our code formatting before we get a lot of code invested. Also, we can start debugging issues with the print version early.

This will require learning more about Latex and how Sphinx produces it. If Sphinx can't be told directly to output in the desired format, it may require a Python script to post-process the Sphinx output.

Comments (9)

  1. yarko

    This should be done in conf.py. Thru some mucking around, I've worked this out.

    There is a papersize key of the latex_elements option. It sets up the latex \documentclass[] macro.

    This doesn't do what you want (letter size or A4).

    I did muck w/ sphinx.sty, and found the comments there that setup the size didn't quite work. BUT this seems to work (snipped from sphinx.sty):

    % Uncomment these two lines to ignore the paper size and make the page % size more like a typical published manual. %\renewcommand{\paperheight}{9in} % The above doesn't work; this does: \paperheight 9.25in %\renewcommand{\paperwidth}{8.5in} % typical squarish manual %\renewcommand{\paperwidth}{7in} % O'Reilly ``Programmming Python'' \paperwidth 7in % O'Reilly ``Programmming Python''

    Unfortunately, setting these as a pre-amble in conf.py is too late - the text gets lobbed off, so it appears these have to be set in sphinx.sty...

    All that would seem is that a local copy of sphinx.sty be setup, to be part of the document.

    I'll ask if there is a cleaner way on the list.

    Yarko.

    Yarko

  2. yarko

    Sorry - that got munged. I'll try again:

    % Uncomment these two lines to ignore the paper size and make the page 
    % size more like a typical published manual.
    %\renewcommand{\paperheight}{9in}
    % The above doesn't work; this does:
    %\paperheight 9in
    %\renewcommand{\paperwidth}{8.5in}   % typical squarish manual
    %\renewcommand{\paperwidth}{7in}     % O'Reilly ``Programmming Python''
    %\paperwidth 7in     % O'Reilly ``Programmming Python''
    

    Right now, it looks like you have to either change this in the Sphinx tree, or setup the makefile to overwrite the sphinx.sty in the _build/latex output directory before invoking the LaTeX tools (which is how I've done in makefile - you can grab my branch when I upload).

  3. yarko

    I think I've solved this - and put a pull request to you for it.

    At the moment, it involves a local copy of sphinx.sty - and is managed by the Makefile (Sphinx provides no help for this at the moment).

    We'll see if Georg comes up with a cleaner, less brute force solution.

    For now, this is what it takes (and I suspect is likely to be as good as it gets).

  4. Log in to comment