How to change Python comment font style in JupyterLab code cells and code editor?

Viewed 186

There's quite a lot answers about how to change font family for all contents. However, I want to make syntax-specific changes, for example, change Python comment font style from italic to normal. Could anyone help me? Thanks!

There is a similar question for doing the same thing in VS Code. How to change Python comment font style in the latest VS Code?

1 Answers

For JupyterLab 3.x you can install jupyterlab-fonts and configure it to swap the font of tokens with cm-comment class in the Advanced Settings Editor → Fonts:

{
  "styles": {
    ".CodeMirror-line span.cm-comment": {
      "fontFamily": "Consolas",
      "fontStyle": "normal"
    }
  }
}

comment font style

Alternatively you could:

  • write a very simple JupyterLab extension providing a single-line CSS equivalent of the above
  • open a feature request on jupyterlab-fonts/issues proposing a per-token customization from the GUI if you fancy that (and even better, contribute).
Related