Skip to content

Instantly share code, notes, and snippets.

@ethan605
Last active August 11, 2016 04:48
Show Gist options
  • Save ethan605/8de0bd2b75d28f2a245f23c9b2d09d08 to your computer and use it in GitHub Desktop.
Save ethan605/8de0bd2b75d28f2a245f23c9b2d09d08 to your computer and use it in GitHub Desktop.
# Patch for pygments/formatters/img.py
# Define font to use
DEFAULT_FONT_NAME_NIX = 'Menlo'
class FontManager(object):
# ... Other methods
def _get_nix_font_path(self, name, style):
# Fix 'fc-list' command to explore exact font to use
proc = subprocess.Popen(['fc-list', "%s:style=%s" % (name, style), 'file'], stdout=subprocess.PIPE)
stdout, _ = proc.communicate()
if proc.returncode == 0:
lines = stdout.splitlines()
for line in lines:
if line.startswith(b'Fontconfig warning:'):
continue
path = line.decode().strip().strip(':')
if path:
return path
return None
# Other methods ...
# Install Fontconfig with Brew
# using --universal flag for better font configs recogization
$ brew install fontconfig --universal
# Might use this to establish cache
$ fc-cache /Library/Fonts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment