Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: 'preamble' #21

Open
romintomasetti opened this issue Apr 15, 2024 · 4 comments
Open

KeyError: 'preamble' #21

romintomasetti opened this issue Apr 15, 2024 · 4 comments

Comments

@romintomasetti
Copy link
Collaborator

romintomasetti commented Apr 15, 2024

Describe the issue

Since the commit 1a91890, 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:

tikz/sphinxcontrib/tikz.py

Lines 272 to 275 in 13575f6

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

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
Copy link
Collaborator Author

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

inducer added a commit to inducer/meshmode that referenced this issue Apr 15, 2024
inducer added a commit to inducer/meshmode that referenced this issue Apr 15, 2024
inducer added a commit to inducer/meshmode that referenced this issue Apr 15, 2024
@philexander
Copy link
Collaborator

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

@philexander
Copy link
Collaborator

@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
Copy link
Collaborator Author

@philexander Here you are: #22.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants