1

I have created a pygments style, which uses the same colors as xcode, and named it xcode.py:

from pygments.style import Style
from pygments.token import Keyword, Name, Comment, String, Error, \
     Number, Operator, Generic

class xcodeStyle(Style):
    default_style = ""
    styles = {
        Text:           '#000000',
        Comment:        '#008426',
        String:         '#D92823',
        Number:         '#2F2ECF',
        Keyword:        '#C22A9C',
        Name.Class:     '#753EA3'
    }

I tried placing it in /Library/Python/2.7/site-packages/pygments/styles but when I list the available styles with

from pygments.styles import get_all_styles
styles = list(get_all_styles())
print styles

my style doesn't get recognized. Any ideas why?

ruben1691
  • 353
  • 3
  • 20
  • Did you resolve this issue? I'm having the same problem. – RazerM Jan 12 '15 at 11:11
  • Yes and no. I ended up going through the source code on BitBucket and found an xcode style built in. So I simply installed the source (v2.0 Beta) and that was it. I just checked and when running `pygmentize -L` in the terminal the new style is not even listed. So I guess pygmentize doesn't know it exists, but when I use the style it works. I use it in LaTex with the minted package and it works like a charm – ruben1691 Jan 13 '15 at 09:55
  • I realised that I had already installed Pygments with Python 2, so my installed styles in the Python 3 directory were ignored, naturally, because the Python 2 `pygmentize` appears first in PATH. – RazerM Jan 13 '15 at 13:44

1 Answers1

0

Indeed, it's not quite clear how to add custom pygments style from their official docs. But I've figured it out after a while.

Sphinx has a conf.py parameter https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-pygments_style Which could be a fully-qualified name of a custom Pygments style class. This is what we should use.

OK, the steps:

  • Create a python module, e.g. my_fancy_style.py with your style class MyFancyStyle

  • Put my_fancy_style.py in the same dir where your conf.py is located.

  • Uncomment/write in conf.py lines, so sphinx will be able to find your class

import os
import sys
sys.path.insert(0, os.path.abspath('.'))
# ...
pygments_style = 'my_fancy_style.MyFancyStyle'

That's it!

vitvlkv
  • 782
  • 7
  • 13