I created Pygments
customized lexer and style:
acetexlexer.py
(lexer file),acedracula.py
(style file),
that work pretty well since the following command returns the expected result:
pygmentize -O style=acedracula -x -l acetexlexer.py:AceTexLexer test.tex
But I can't get them to work with Sphinx, despite extensive research on the Internet.
I tried for instance the following setup, partially based on:
- https://github.com/AdaCore/aunit/blob/v21.0.0/doc/share/ada_pygments.py
- https://github.com/AdaCore/aunit/blob/v21.0.0/doc/share/conf.py
that I found from:
https://github.com/sphinx-doc/sphinx/issues/9544
At the root of the
source
of the project, I created a_pygments
subdirectory containing the lexer and style files (acetexlexer.py
andacedracula.py
).The relevant lines of
acetexlexer.py
are:from pygments.lexer import inherit, bygroups from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Punctuation, Generic, Other, Whitespace from pygments.lexers.markup import TexLexer __all__ = ['AceTexLexer'] class AceTexLexer(TexLexer): aliases = ['xtex', 'xlatex']
The relevant lines of my
conf.py
are:import os import sys sys.path.insert(0, os.path.abspath('.')) sys.path.append(os.path.abspath("./_ext")) sys.path.append(os.path.abspath("./_pygments")) def setup(app): from acetexlexer import AceTexLexer app.add_lexer('xlatex', acetexlexer.AceTexLexer)
But, when I run:
sphinx-build -v -j auto source build/html source/test.md
I get:
[...]/source/test.md:16: WARNING: Pygments lexer name 'xlatex' is not known.
What am I doing wrong?