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 change pygments_style in _config.yml #2105

Open
martinSDT opened this issue Jan 23, 2024 · 2 comments
Open

Unable to change pygments_style in _config.yml #2105

martinSDT opened this issue Jan 23, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@martinSDT
Copy link

martinSDT commented Jan 23, 2024

Hello all

Describe the bug

When I add to the _config.yml file

sphinx:
  recursive_update: true
  config:
    pygments_style: pygments.styles.xcode.XcodeStyle

I expect the style "xcode" to be used to highlight syntax in code blocks
But instead code blocks are always colored the same way, whatever the provided pygments_style

I tried to assign a class that does not exist (pygments.styles.xcode.XcodeStyle2) and this results in an error during book building

Exception occurred:
  File "C:\Users\Martin\AppData\Roaming\Python\Python39\site-packages\sphinx\highlighting.py", line 89, in get_style
    return getattr(import_module(module), stylename)
AttributeError: module 'pygments.styles.xcode' has no attribute 'XcodeStyle2'

=> This suggests that the pygments style is somehow "read" (when an existing class is provided), but not used as I would expect.

I would like to customize the syntax highlighting and thus first need to check the possibility to change pygments_style before diving into custom lexer, custom style, etc.

Reproduce the bug

  1. Unzip the sample source code mynewbook.zip
    It contains a MATLAB code block in the file mynewbook/markdown.md
    And the option below in _config.yml
sphinx:
  recursive_update: true
  config:
    pygments_style: pygments.styles.xcode.XcodeStyle
  1. Build the book with
jupyter-book build mynewbook/
  1. Observe that the code highlighting is the same with and without the pygments_style option.
  2. To see the expected output, you can go to this page https://pygments.org/demo/
    Select
    Language = Matlab
    Style = xcode
    And paste the following code under Enter some code :
rxnList = {'PCHOLP_hs_f', 'PLA2_2_f', 'SMS_f','PCHOLP_hs_b', 'PLA2_2_b', 'SMS_b'};
c = [1, 1, 1, 1, 1, 1]; % This is a comment
d = 10;
ineqSense = 'G';
modelConstrained = constrainRxnListAboveBound(modelIrrev, rxnList, C, d, ineqSense);

image

Thanks in advance for your help and time ! :)

List your environment

Jupyter Book : 0.15.1
External ToC : 0.3.1
MyST-Parser : 0.18.1
MyST-NB : 0.17.2
Sphinx Book Theme : 1.0.1
Jupyter-Cache : 0.6.1
NbClient : 0.7.4

Python 3.9
OS : Windows 11

@martinSDT martinSDT added the bug Something isn't working label Jan 23, 2024
Copy link

welcome bot commented Jan 23, 2024

Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.

If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).

Welcome to the EBP community! 🎉

@72757373656c6c
Copy link

I see that you are using the Sphinx Book Theme which inherits from pydata. The pydata doc says "Configure pygments themes" using:

html_theme_options = {
   ...
   "pygment_light_style": "tango",
   "pygment_dark_style": "monokai"
}

And,

Danger
The native Sphinx option pygments_style will be overwritten by this theme.

Any difference if you use pygment_{light,dark}_style?

I am having a similar issue with the sphinx_book_theme. Can't seem to change the default styles tango and monokai to anything else. If I use a nonexistent style, I get a message, "Highlighting style atest not found by pygments, falling back to tango.". But if I use a valid style from the output of pygmentize -L styles, there is no message but pygment style doesn't change either in the html output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants