question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

rst2pdf does not work with the Sphinx glossary directive

See original GitHub issue

When using rst2pdf with the Sphinx glossary directive, rst2pdf raises the following ValueError for the first defined term in the glossary:

ValueError: format not resolved, probably missing URL scheme or undefined destination target for 'term-abs'

For the above example, the glossary directive starts with:

.. glossary::

    ABS
      Anti-Lock Braking System

And the glossary directive generates a term-% destination target for each defined term in the glossary.

Description of problem

To reproduce the problem:

  1. Install the following requirements.txt file with pip in a python 3.6 environment (I am using Ubuntu 18.04LTS).
    sphinx==3.2.0
    rst2pdf==0.97
    
  2. Create a new documentation project, configuring rst2pdf in conf.py:
    extensions = [
        ...
        'rst2pdf.pdfbuilder',
        ...
    ]
    pdf_documents = [ ( 'index', u'rst2pdf', project, author ), ]
    
  3. Modify the Makefile to use Python 3:
    SPHINXBUILD   ?= python3 $(shell which sphinx-build)
    
  4. Add a glossary to the index.rst:
    .. glossary::
    
        RST
          Restructured Text
    
  5. Build a pdf:
    make pdf
    

I am proposing that rst2pdf adds support for the Sphinx glossary directive directive, which would make rst2pdf that much more useful for dissertations and technical documents.

I have already tried hacking the rst2pdf code to get this working, but while I am highly proficient in python, some guidance with Sphinx and rst2pdf would be appreciated.

What is the expected output? What do you see instead?

I am expecting that a pdf file is generated, but the build fails with the following stack-trace:

Traceback (most recent call last):
  File "/home/smith/.local/lib/python3.6/site-packages/rst2pdf/pdfbuilder.py", line 146, in write
    docwriter.write(doctree, destination)
  File "/usr/local/lib/python3.6/dist-packages/docutils/writers/__init__.py", line 78, in write
    self.translate()
  File "/home/smith/.local/lib/python3.6/site-packages/rst2pdf/pdfbuilder.py", line 646, in translate
    compressed=self.compressed)
  File "/home/smith/.local/lib/python3.6/site-packages/rst2pdf/createpdf.py", line 643, in createPdf
    pdfdoc.multiBuild(elements)
  File "/home/smith/.local/lib/python3.6/site-packages/reportlab/platypus/doctemplate.py", line 1153, in multiBuild
    self.canv.save()
  File "/home/smith/.local/lib/python3.6/site-packages/reportlab/pdfgen/canvas.py", line 1244, in save
    self._doc.SaveToFile(self._filename, self)
  File "/home/smith/.local/lib/python3.6/site-packages/reportlab/pdfbase/pdfdoc.py", line 219, in SaveToFile
    data = self.GetPDFData(canvas)
  File "/home/smith/.local/lib/python3.6/site-packages/reportlab/pdfbase/pdfdoc.py", line 245, in GetPDFData
    return self.format()
  File "/home/smith/.local/lib/python3.6/site-packages/reportlab/pdfbase/pdfdoc.py", line 427, in format
    IOf = IO.format(self)
  File "/home/smith/.local/lib/python3.6/site-packages/reportlab/pdfbase/pdfdoc.py", line 875, in format
    fcontent = format(self.content, document, toplevel=1)   # yes this is at top level
  File "/home/smith/.local/lib/python3.6/site-packages/reportlab/pdfbase/pdfdoc.py", line 80, in format
    f = element.format(document)
  File "/home/smith/.local/lib/python3.6/site-packages/reportlab/pdfbase/pdfdoc.py", line 1612, in format
    return D.format(document)
  File "/home/smith/.local/lib/python3.6/site-packages/reportlab/pdfbase/pdfdoc.py", line 683, in format
    L = [(format(PDFName(k),document)+b" "+format(dict[k],document)) for k in keys]
  File "/home/smith/.local/lib/python3.6/site-packages/reportlab/pdfbase/pdfdoc.py", line 683, in <listcomp>
    L = [(format(PDFName(k),document)+b" "+format(dict[k],document)) for k in keys]
  File "/home/smith/.local/lib/python3.6/site-packages/reportlab/pdfbase/pdfdoc.py", line 80, in format
    f = element.format(document)
  File "/home/smith/.local/lib/python3.6/site-packages/reportlab/pdfbase/pdfdoc.py", line 1778, in format
    if f is None: raise ValueError("format not resolved, probably missing URL scheme or undefined destination target for '%s'" % self.name)
ValueError: format not resolved, probably missing URL scheme or undefined destination target for 'term-abs'

🖥 Versions

$ python3 -V
Python 3.6.9
$ pip3 freeze | grep rst2pdf
rst2pdf==0.97
$ pip3 freeze | grep reportlab
reportlab==3.5.47
$ pip3 freeze | grep Sphinx
Sphinx==3.2.0

Which operating system are you using?

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:        18.04
Codename:       bionic

I also have to install textlive-font-utils on Ubuntu, which is at version 2017.20180305-2.

Additional information

I need this change to be able to simply generate pdf’s for small to medium technical documentation without getting entrenched in the complexities of latexpdf. I am quite certain this will be of generic value to other users writing documentation requiring glossaries.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
smipi1commented, Aug 12, 2020

With a little guidance on the rst2pdf and Sphinx architectures, I am fairly certain that I can make a pull-request for this. Can someone provide some guidance?

0reactions
akrabatcommented, Aug 4, 2022

@Jeffmackinnon is this issue still around? I still see this issue for Glossary term even though I have removed the term.

@sachin-suresh-rapyuta, this issue has not be resolved and we would love help to fix it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

rst2pdf/CHANGES.rst at main - GitHub
Note that value of pdf_real_footnotes is not False if not explicitly set. ... Fixed: sphinx+rst2pdf now works with automodule directive Sphinx >= 1.4...
Read more >
How to use rst2pdf
1 Introduction. This document explains how to use rst2pdf. Here is the very short version: rst2pdf.py mydocument.txt -o mydocument.pdf.
Read more >
Adding header and footer to PDF generated using rst2pdf and ...
Although RST does support header and foot directives, the Sphinx documentation explicitly warns against using them. I think it might be possible ...
Read more >
Directives - Sphinx documentation
The content of the directive should be written in complete sentences and include all appropriate punctuation. Example: .. note:: This function is not...
Read more >
Sphinx Documentation - API Manual
Sphinx should work with docutils version 0.4 or some (not broken) SVN trunk ... This is not to be used for simple constant...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found