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

Unable to use snippets-latex backend #91

Open
dunnl opened this issue Nov 5, 2022 · 3 comments
Open

Unable to use snippets-latex backend #91

dunnl opened this issue Nov 5, 2022 · 3 comments

Comments

@dunnl
Copy link

dunnl commented Nov 5, 2022

I haven't been able to use the snippets-latex backend with any frontend due to a failing assertion. For example, based on the line here, I think I should be able to successfully run the following command in the recipes directory.

alectryon fragments.v.json --backend snippets-latex

But an assertion in the LaTeX syntax highlighter fails

assert tex.startswith(PYGMENTS_LATEX_PREFIX) and tex.endswith(PYGMENTS_LATEX_SUFFIX), tex

Traceback (most recent call last):
  File "/nix/store/dk1jycphjcdvignvfvrmhzp4lsgxv1ka-python3.10-alectryon-1.4.0/bin/.alectryon-wrapped", line 9, in <module>
    sys.exit(main())
  File "/nix/store/dk1jycphjcdvignvfvrmhzp4lsgxv1ka-python3.10-alectryon-1.4.0/lib/python3.10/site-packages/alectryon/cli.py", line 920, in main
    sys.exit(max(process_pipelines(args), default=0))
  File "/nix/store/dk1jycphjcdvignvfvrmhzp4lsgxv1ka-python3.10-alectryon-1.4.0/lib/python3.10/site-packages/alectryon/cli.py", line 914, in process_pipelines
    state = call_pipeline_step(step, state, ctx)
  File "/nix/store/dk1jycphjcdvignvfvrmhzp4lsgxv1ka-python3.10-alectryon-1.4.0/lib/python3.10/site-packages/alectryon/cli.py", line 856, in call_pipeline_step
    return step(state, **{p: ctx[p] for p in params})
  File "/nix/store/dk1jycphjcdvignvfvrmhzp4lsgxv1ka-python3.10-alectryon-1.4.0/lib/python3.10/site-packages/alectryon/cli.py", line 360, in dump_latex_snippets
    for snippet in snippets:
  File "/nix/store/dk1jycphjcdvignvfvrmhzp4lsgxv1ka-python3.10-alectryon-1.4.0/lib/python3.10/site-packages/alectryon/latex.py", line 323, in gen
    yield self.gen_fragments(fragments)
  File "/nix/store/dk1jycphjcdvignvfvrmhzp4lsgxv1ka-python3.10-alectryon-1.4.0/lib/python3.10/site-packages/alectryon/latex.py", line 318, in gen_fragments
    self.gen_fragment(fr)
  File "/nix/store/dk1jycphjcdvignvfvrmhzp4lsgxv1ka-python3.10-alectryon-1.4.0/lib/python3.10/site-packages/alectryon/latex.py", line 280, in gen_fragment
    self.gen_sentence(fr)
  File "/nix/store/dk1jycphjcdvignvfvrmhzp4lsgxv1ka-python3.10-alectryon-1.4.0/lib/python3.10/site-packages/alectryon/latex.py", line 270, in gen_sentence
    self.gen_input(s)
  File "/nix/store/dk1jycphjcdvignvfvrmhzp4lsgxv1ka-python3.10-alectryon-1.4.0/lib/python3.10/site-packages/alectryon/latex.py", line 239, in gen_input
    self.gen_code(fr.input)
  File "/nix/store/dk1jycphjcdvignvfvrmhzp4lsgxv1ka-python3.10-alectryon-1.4.0/lib/python3.10/site-packages/alectryon/latex.py", line 189, in gen_code
    with Concat(*self.highlight_enriched(code)) as block:
  File "/nix/store/dk1jycphjcdvignvfvrmhzp4lsgxv1ka-python3.10-alectryon-1.4.0/lib/python3.10/site-packages/alectryon/core.py", line 132, in highlight_enriched
    return self.highlight(obj.contents)
  File "/nix/store/dk1jycphjcdvignvfvrmhzp4lsgxv1ka-python3.10-alectryon-1.4.0/lib/python3.10/site-packages/alectryon/latex.py", line 186, in highlight
    return [Raw(self.highlighter(s, prefix="", suffix=""), verbatim=True)]
  File "/nix/store/dk1jycphjcdvignvfvrmhzp4lsgxv1ka-python3.10-alectryon-1.4.0/lib/python3.10/site-packages/alectryon/pygments.py", line 219, in __call__
    return self.highlighter(code, **{**self.kwargs, **kwargs})
  File "/nix/store/dk1jycphjcdvignvfvrmhzp4lsgxv1ka-python3.10-alectryon-1.4.0/lib/python3.10/site-packages/alectryon/pygments.py", line 198, in highlight_latex
    assert tex.startswith(PYGMENTS_LATEX_PREFIX) and tex.endswith(PYGMENTS_LATEX_SUFFIX), tex
AssertionError: \PY{k+kn}{Goal} \PY{k+kt}{True}\PY{o}{.}

I don't understand the purpose of this assertion. Am I invoking the backend incorrectly? (In which case, how should I invoke it?) The documentation on snippets-latex is scant, but perhaps I could add some if I can get it working.

@cpitclaudel
Copy link
Owner

cpitclaudel commented Nov 7, 2022

Thanks for the report. The issue was fixed in 40ff2af , which hasn't been part of an actual release yet.

For context, it was due to the (somewhat) recent release of pygments 2.12.0, which (in commit 231366c7106f66f67f3f27c86ee51434419fcda2), started recognizing the nowrap option: previously, all latex generated by pygments was wrapped in {Verbatim} tags, which Alectryon had to remove.

@cpitclaudel
Copy link
Owner

I will try to make a new release soon. However, I'd also like to patch a few things for compatibility with more recent sphinx versions. Please ping me if nothing has happened within a week or so.

(In the meantime, pip can install from a git repository, or you can downgrade pygments using pip install 'pygments<2.12.0'

@ana-borges
Copy link

Hi @cpitclaudel, it seems there hasn't been a new release after all, so this is the requested ping. In the meantime I'm fine using an old pygments version.

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

3 participants