Progress in rst2pdf-sphinx builder

190 views
Skip to first unread message

Roberto Alsina

unread,
Jul 21, 2009, 5:49:19 PM7/21/09
to sphin...@googlegroups.com, docutils...@lists.sourceforge.net, rst2pdf...@googlegroups.com
I finally had a few hours to hack today, and I think I fixed footnotes and the
toctree, at least for the document I am trying to handle ;-).

You can see the output here:
http://lateral.netmanagers.com.ar/static/tutorial-5.pdf

Specifically, the improvement is the TOC in page 115 and the footnote
numbering is now correct across source files.

Don't worry about the TOC being in a strange place, I can move it and intend
to generate the same "parts" as the LaTeX builder does, as soon as I can clean
up the document title.

I would *love* if someone else would try this with his own sphinx documents
since there is probably a lot I am not even looking at.

Currently you need to use this fork of sphinx:

http://bitbucket.org/gminick/sphinx-rst2pdf-builder

And the SVN version of rst2pdf:

http://code.google.com/p/rst2pdf/source/checkout

--
("\''/").__..-''"`-. . Roberto Alsina
`9_ 9 ) `-. ( ).`-._.`) KDE Developer (MFCH)
(_Y_.)' ._ ) `._`. " -.-' http://lateral.netmanagers.com.ar
_..`-'_..-_/ /-'_.' The 6,855th most popular site of Slovenia
(l)-'' ((i).' ((!.' according to alexa.com (27/5/2007)

Roger Binns

unread,
Jul 21, 2009, 11:37:56 PM7/21/09
to sphin...@googlegroups.com, docutils...@lists.sourceforge.net
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Roberto Alsina wrote:
> I would *love* if someone else would try this with his own sphinx documents
> since there is probably a lot I am not even looking at.

I am trying to give it a go as the latex -> pdf conversion generated an
unusable document for me.

> http://code.google.com/p/rst2pdf/source/checkout

This ultimately failed for me. I am not quite sure how many thousand
dependencies it has, but several failed to build and then whatever setup
extension it uses was happy with the Ubuntu packages I installed.
However it ended up wanting simplejson 1.9.2, wasn't happy with the
Ubuntu simplejson package (1.9.2-1build1) and the simplejson 1.9.2 it
downloaded has a syntax error in its setup.py. (Specificially error:
Setup script exited with error in simplejson setup command: test_suite
must be a list). And I am running Python 2.6 so it could just use the
Python standard library json module anyway.

Roger
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkpmiZEACgkQmOOfHg372QRg+wCfYbDVNWM+SCur6CbOOqTvszwp
kRwAni3n34wXTgkaZj8FjBjXegQ7JyGl
=QfBt
-----END PGP SIGNATURE-----

Roberto Alsina

unread,
Jul 21, 2009, 11:46:42 PM7/21/09
to sphin...@googlegroups.com
On Wednesday 22 July 2009 00:37:56 Roger Binns wrote:
> Roberto Alsina wrote:
> > I would *love* if someone else would try this with his own sphinx
> > documents since there is probably a lot I am not even looking at.
>
> I am trying to give it a go as the latex -> pdf conversion generated an
> unusable document for me.
>
> > http://code.google.com/p/rst2pdf/source/checkout
>
> This ultimately failed for me. I am not quite sure how many thousand
> dependencies it has,

Just a dozen or so :-)

> but several failed to build and then whatever setup
> extension it uses was happy with the Ubuntu packages I installed.

It's just setuptools.

> However it ended up wanting simplejson 1.9.2, wasn't happy with the
> Ubuntu simplejson package (1.9.2-1build1) and the simplejson 1.9.2 it
> downloaded has a syntax error in its setup.py. (Specificially error:
> Setup script exited with error in simplejson setup command: test_suite
> must be a list). And I am running Python 2.6 so it could just use the
> Python standard library json module anyway.

Remove it from setup.py then, it should work just fine.
I can't remove it by default, because it's supposed to work with python 2.4.

Roberto Alsina

unread,
Jul 23, 2009, 1:09:58 PM7/23/09
to sphin...@googlegroups.com, rst2pdf...@googlegroups.com
A couple more days, and it seems the rst2pdf builder for sphinx (so you can
create PDFs without LaTeX) is almost finished. In fact, I think it's *maybe*
good enough to think about merging it into sphinx proper, or turn it into a
plugin.

Since my last progress report there have been a bunch of changes:

* The toctree works much better
* A LaTeX-like cover page was added
* pdf_documents option similar to latex_documents
* Syntax highlighting was fixed
* footnotes are prettier

And many smaller tweaks.

Here's the usual test document (the spanish translation of the python
tutorial):

http://lateral.netmanagers.com.ar/static/tutorial-7.pdf

Also as usual, to test it you need this sphinx fork:

http://bitbucket.org/gminick/sphinx-rst2pdf-builder

And this rst2pdf:

Roger Binns

unread,
Jul 24, 2009, 2:46:23 PM7/24/09
to sphin...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Roberto Alsina wrote:
> Remove it from setup.py then, it should work just fine.

I had assumed it was one the dependencies that was insisting on
simplejson, but fortunately it was the top level setup.py so that did
turn out to be easy.

The generated and then edited Makefile/conf.py for my docs predates your
work. Consequently the build gives this message:

> WARNING: no "pdf_documents" config value found; no documents will be written
> build succeeded, 1 warning.

Can I suggest either giving a URL as part of that message to information
on what it should be set to, or just defaulting to using the project and
version to generate a suitable config value?

I used sphinx-quickstart to generate a dummy Makefile/conf.py to see
what the values should be. It looks like some of the keys and dummy
values are copied from Latex and so don't make too much sense! It also
isn't clear what the defaults are (eg is compressed on or off by default?)

The build fails for me. There are an initial bunch of warnings about
duplicate explicit targets and then an exception. Details are lower
down. You will probably find it easiest to work against my project to
diagnose. Some of the doc is generated, so here the complete steps you
need to run to try out the pdf generator:

$ hg clone https://apsw.googlecode.com/hg/ apsw
$ cd apsw
$ python setup.py build_ext --inplace --fetch-sqlite
$ make docs # don't worry about htmlhelp not building
$ cd doc
$ make VERSION=1.2.3 pdf # rerun this each time to get pdf build

These are the warnings and error:

> sphinx-build -q -b pdf -d build/doctrees . build/pdf
> <string>:: (WARNING/2) Duplicate explicit target name: "(connection method)".
> <string>:: (WARNING/2) Duplicate explicit target name: "(blob method)".
> <string>:: (WARNING/2) Duplicate explicit target name: "(connection method)".
> <string>:: (WARNING/2) Duplicate explicit target name: "(blob method)".
> <string>:: (WARNING/2) Duplicate explicit target name: "(cursor method)".
> <string>:: (WARNING/2) Duplicate explicit target name: "(cursor method)".
> <string>:: (WARNING/2) Duplicate explicit target name: "[1]".
> <string>:: (WARNING/2) Duplicate explicit target name: "[1]".
> <string>:: (WARNING/2) Duplicate explicit target name: "(cursor method)".
> <string>:: (WARNING/2) Duplicate explicit target name: "(cursor method)".
> <string>:: (WARNING/2) Duplicate explicit target name: "[1]".
> Exception occurred:
> File "/usr/lib/python2.6/dist-packages/docutils/nodes.py", line 1556, in unknown_visit
> if (node.document.settings.strict_visitor
> AttributeError: 'NoneType' object has no attribute 'settings'

Roger
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkpqAXsACgkQmOOfHg372QQ5BgCffHZV+vW250Z+BIf0nO2PkB7i
8vEAnjVIrfVZnxVZblp1rBNdtKM351Om
=ztf6
-----END PGP SIGNATURE-----

Roberto Alsina

unread,
Jul 24, 2009, 3:08:39 PM7/24/09
to sphin...@googlegroups.com
On Friday 24 July 2009 15:46:23 Roger Binns wrote:
> The build fails for me. There are an initial bunch of warnings about
> duplicate explicit targets and then an exception. Details are lower
> down. You will probably find it easiest to work against my project to
> diagnose. Some of the doc is generated, so here the complete steps you
> need to run to try out the pdf generator:

Will take a look at it tonight.

I am currently trying to run the django docs thtough rst2pdf and it's just
*this* close to working :-)

Roberto Alsina

unread,
Jul 24, 2009, 3:46:56 PM7/24/09
to sphin...@googlegroups.com
On Friday 24 July 2009 16:08:39 Roberto Alsina wrote:
> On Friday 24 July 2009 15:46:23 Roger Binns wrote:
> > The build fails for me. There are an initial bunch of warnings about
> > duplicate explicit targets and then an exception. Details are lower
> > down. You will probably find it easiest to work against my project to
> > diagnose. Some of the doc is generated, so here the complete steps you
> > need to run to try out the pdf generator:
>
> Will take a look at it tonight.
>
> I am currently trying to run the django docs thtough rst2pdf and it's just
> *this* close to working :-)

And it passed :-)

There are some obvious bugs in the output, but if it can produce a freaking
665-page manual which uses custom extensions to sphinx there is hope yet!

http://lateral.netmanagers.com.ar/static/django.pdf

The problem with apsw I have not figured out yet, though.

Jacob Kaplan-Moss

unread,
Jul 24, 2009, 3:53:24 PM7/24/09
to sphin...@googlegroups.com
On Fri, Jul 24, 2009 at 12:46 PM, Roberto
Alsina<ral...@netmanagers.com.ar> wrote:
> And it passed :-)

That's totally awesome. Can you share what you did to make this
happen? Did you need to change anything to Django's config to make
this work? Feel free to email me off-list if you don't want to derail.

Jacob

Georg Brandl

unread,
Aug 4, 2009, 5:39:52 PM8/4/09
to sphin...@googlegroups.com
Roberto Alsina schrieb:

> A couple more days, and it seems the rst2pdf builder for sphinx (so you can
> create PDFs without LaTeX) is almost finished. In fact, I think it's *maybe*
> good enough to think about merging it into sphinx proper, or turn it into a
> plugin.
>
> Since my last progress report there have been a bunch of changes:
>
> * The toctree works much better
> * A LaTeX-like cover page was added
> * pdf_documents option similar to latex_documents
> * Syntax highlighting was fixed
> * footnotes are prettier
>
> And many smaller tweaks.
>
> Here's the usual test document (the spanish translation of the python
> tutorial):
>
> http://lateral.netmanagers.com.ar/static/tutorial-7.pdf
>
> Also as usual, to test it you need this sphinx fork:
>
> http://bitbucket.org/gminick/sphinx-rst2pdf-builder
>
> And this rst2pdf:
>
> http://code.google.com/p/rst2pdf/source/checkout

Very impressive! I think it would be best to release it as an extension
right now, since Sphinx 1.0 will take some time yet, and we'll merge it
after it has seen more widespread testing.

cheers,
Georg

Roberto Alsina

unread,
Aug 4, 2009, 5:48:34 PM8/4/09
to sphin...@googlegroups.com
On Tuesday 04 August 2009 18:39:52 Georg Brandl wrote:
> Very impressive! I think it would be best to release it as an extension
> right now, since Sphinx 1.0 will take some time yet, and we'll merge it
> after it has seen more widespread testing.

Would love to. Any pointers as to how to do this as an extension?
The code is pretty much limited to builders/pdf.py and writers/pdf.py plus
some minimal stuff in config.py and the quickstart script.

Wojtek Walczak

unread,
Aug 5, 2009, 4:22:01 AM8/5/09
to sphin...@googlegroups.com
Roberto Alsina napisał(a):

Roberto,

>> Very impressive! I think it would be best to release it as an extension
>> right now, since Sphinx 1.0 will take some time yet, and we'll merge it
>> after it has seen more widespread testing.
>
> Would love to. Any pointers as to how to do this as an extension?
> The code is pretty much limited to builders/pdf.py and writers/pdf.py plus
> some minimal stuff in config.py and the quickstart script.

I have created a base for the extension. It's available here:

http://tosh.pl/gminick/code/pdfbuilder.py

I have also updated it a bit to work with Sphinx's code from the main
repository (moduleindex instead of sys.env.modules), so you may have
to update your version of Sphinx to check it out.

Unfortunately, it won't work yet. It throws an error when I try to build
the docs:

Exception occurred:
File
"/usr/local/lib/python2.6/site-packages/rst2pdf-0.11-py2.6.egg/rst2pdf/utils.py",
line 37, in parseRaw
elements.append(Spacer(int(tokens[1]), int(tokens[2])))
ValueError: invalid literal for int() with base 10: '3cm'

I guess you will know how to fix it :-) In case you don't, please let me
know, I will investigate it further.

--
Regards,
Wojtek Walczak,
http://tosh.pl/gminick/

Christophe de VIENNE

unread,
Aug 5, 2009, 4:49:50 AM8/5/09
to sphin...@googlegroups.com


2009/8/5 Wojtek Walczak <gmi...@tosh.pl>


Roberto Alsina napisał(a):

Roberto,

>> Very impressive!  I think it would be best to release it as an extension
>> right now, since Sphinx 1.0 will take some time yet, and we'll merge it
>> after it has seen more widespread testing.
>
> Would love to. Any pointers as to how to do this as an extension?
> The code is pretty much limited to builders/pdf.py and writers/pdf.py plus
> some minimal stuff in config.py and the quickstart script.

I have created a base for the extension. It's available here:

http://tosh.pl/gminick/code/pdfbuilder.py

I have also updated it a bit to work with Sphinx's code from the main
repository (moduleindex instead of sys.env.modules), so you may have
to update your version of Sphinx to check it out.
 
I think the extension should really target the 0.6.x version of Sphinx because I guess a lot of people are interested in it and since the 0.6.x branch is pretty stable and usable, moving to the trunk might not be an option (this is my case at the very least).

Thanks

Christophe

Christophe de VIENNE

unread,
Aug 5, 2009, 4:54:04 AM8/5/09
to sphin...@googlegroups.com
Hi Roberto,

You extension looks very promising !

I was wondering how easy it would be to customize the PDF output with it :
 - Can we provide stylesheets ?
 - Is is possible / planned to add chapter numbering ?

Thanks a lot,

Christophe

Wojtek Walczak

unread,
Aug 5, 2009, 4:58:19 AM8/5/09
to sphin...@googlegroups.com
Christophe de VIENNE napisał(a):

>> I have created a base for the extension. It's available here:
>>
>> http://tosh.pl/gminick/code/pdfbuilder.py
>>
>> I have also updated it a bit to work with Sphinx's code from the main
>> repository (moduleindex instead of sys.env.modules), so you may have
>> to update your version of Sphinx to check it out.
>
>
> I think the extension should really target the 0.6.x version of Sphinx
> because I guess a lot of people are interested in it and since the 0.6.x
> branch is pretty stable and usable, moving to the trunk might not be an
> option (this is my case at the very least).

In such case changing these lines in pdfbuilder.py:

---
149 # This is stolen from the HTML builder
150 moduleindex = self.env.domaindata['py']['modules']
151 if self.config.pdf_use_modindex and moduleindex:
152 modules = sorted(((mn, ('#module-' + mn, sy, pl, dep))
153 for (mn, (fn, sy, pl, dep)) in moduleindex.iteritems()),
154 key=lambda x: x[0].lower())
---

into:

---
149 # This is stolen from the HTML builder
150
151 if self.config.pdf_use_modindex and sys.env.modules:
152 modules = sorted(((mn, ('#module-' + mn, sy, pl, dep))
153 for (mn, (fn, sy, pl, dep)) in
sys.env.modules.iteritems()),
154 key=lambda x: x[0].lower())
---

should be enough (IIRC) :)

Roberto Alsina

unread,
Aug 5, 2009, 6:17:11 AM8/5/09
to sphin...@googlegroups.com
On Wednesday 05 August 2009 05:22:01 Wojtek Walczak wrote:
> Unfortunately, it won't work yet. It throws an error when I try to build
> the docs:
>
> Exception occurred:
> File
> "/usr/local/lib/python2.6/site-packages/rst2pdf-0.11-py2.6.egg/rst2pdf/util
>s.py", line 37, in parseRaw
> elements.append(Spacer(int(tokens[1]), int(tokens[2])))
> ValueError: invalid literal for int() with base 10: '3cm'
>
> I guess you will know how to fix it :-) In case you don't, please let me
> know, I will investigate it further.

That's because your rst2pdf is too old, this needs current SVN.

Roberto Alsina

unread,
Aug 5, 2009, 6:18:32 AM8/5/09
to sphin...@googlegroups.com
On Wednesday 05 August 2009 05:54:04 Christophe de VIENNE wrote:
> Hi Roberto,
>
> You extension looks very promising !
>
> I was wondering how easy it would be to customize the PDF output with it :
> - Can we provide stylesheets ?

Sure, there are a bunch included with rst2pdf, including one called sphinx
that tries to look a bit like the web output.

> - Is is possible / planned to add chapter numbering ?

Sure. The TOC support is incomplete, it lacks that and a working maxdepth.

Georg Brandl

unread,
Aug 14, 2009, 6:49:29 AM8/14/09
to sphin...@googlegroups.com
Wojtek Walczak schrieb:

> Roberto Alsina napisał(a):
>
> Roberto,
>
>>> Very impressive! I think it would be best to release it as an extension
>>> right now, since Sphinx 1.0 will take some time yet, and we'll merge it
>>> after it has seen more widespread testing.
>>
>> Would love to. Any pointers as to how to do this as an extension?
>> The code is pretty much limited to builders/pdf.py and writers/pdf.py plus
>> some minimal stuff in config.py and the quickstart script.
>
> I have created a base for the extension. It's available here:
>
> http://tosh.pl/gminick/code/pdfbuilder.py
>
> I have also updated it a bit to work with Sphinx's code from the main
> repository (moduleindex instead of sys.env.modules), so you may have
> to update your version of Sphinx to check it out.

I just want to add that you should not base it on trunk; the details of
the domain API are not yet stable.

Georg

Reply all
Reply to author
Forward
0 new messages