sphinx-contrib / tikz

A Sphinx extension to draw pictures with the TikZ/PGF LaTeX package
Other
18 stars 15 forks source link

KeyError: 'preamble' #21

Open romintomasetti opened 2 months ago

romintomasetti commented 2 months ago

Describe the issue

Since the commit 1a91890c53941fc65052f1bd042bafb6dbba55a8, some of your logic has changed and made our documentation fail. Note that this commit seems to be included in the release 0.4.18 (https://pypi.org/project/sphinxcontrib-tikz/0.4.18/).

Here is the culprit: https://github.com/sphinx-contrib/tikz/blob/13575f602378d225fff99ef417c541d739f7fbe3/sphinxcontrib/tikz.py#L272-L275

In our configuration, when we do make html, it seems that the builder's latex_elements does not contain the preamble key.

A quick but ugly workaround is to add latex_elements = {} to our config.py. I do not consider this as a viable long-term fix.

@philexander I think the required fix would be along these lines (probably):

if config.tikz_latex_preamble: 
    latex += config.tikz_latex_preamble 
elif 'preamble' in config.latex_elements: 
    latex += config.latex_elements['preamble'] 

Thanks!

Trace output

     self.docwriter.write(doctree, destination)
  File "/usr/local/lib/python3.10/dist-packages/docutils/writers/__init__.py", line 80, in write
    self.translate()
  File "/usr/local/lib/python3.10/dist-packages/sphinx/writers/html.py", line 36, in translate
    self.document.walkabout(visitor)
  File "/usr/local/lib/python3.10/dist-packages/docutils/nodes.py", line 186, in walkabout
    if child.walkabout(visitor):
  File "/usr/local/lib/python3.10/dist-packages/docutils/nodes.py", line 186, in walkabout
    if child.walkabout(visitor):
  File "/usr/local/lib/python3.10/dist-packages/docutils/nodes.py", line 186, in walkabout
    if child.walkabout(visitor):
  [Previous line repeated 1 more time]
  File "/usr/local/lib/python3.10/dist-packages/docutils/nodes.py", line 178, in walkabout
    visitor.dispatch_visit(self)
  File "/usr/local/lib/python3.10/dist-packages/sphinx/util/docutils.py", line 582, in dispatch_visit
    method(node)
  File "/usr/local/lib/python3.10/dist-packages/sphinxcontrib/tikz.py", line 350, in html_visit_tikz
    fname = render_tikz(self, node, libs, node['stringsubst'])
  File "/usr/local/lib/python3.10/dist-packages/sphinxcontrib/tikz.py", line 275, in render_tikz
    latex += config.latex_elements['preamble']
KeyError: 'preamble'

(joint work with @maartenarnst)

romintomasetti commented 2 months ago

@philexander I'd be more than happy to create some action in this repo, to have some automated testing and avoid such regressions :wink:

philexander commented 2 months ago

@romintomasetti Thanks for reporting and sorry for this regression. I have fixed this issue and published version 0.4.19.

philexander commented 2 months ago

@romintomasetti Thank you for offering to create automated testing as a GitHub action. You are very welcome. I have given you write permissions. Tell me if this is insufficient, or if for some reason you nevertheless refrain from contributing.

romintomasetti commented 2 months ago

@philexander Here you are: #22.