<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Jupyter Blog - Florence Haudin</title><link href="https://jasongrout.github.io/medium-archive/pelican/" rel="alternate"/><link href="https://jasongrout.github.io/medium-archive/pelican/feeds/author-florence-haudin.atom.xml" rel="self"/><id>https://jasongrout.github.io/medium-archive/pelican/</id><updated>2023-06-19T08:11:00+00:00</updated><subtitle>The Project Jupyter blog: news, releases, and community stories, archived from blog.jupyter.org.</subtitle><entry><title>A theme editor for JupyterLab</title><link href="https://jasongrout.github.io/medium-archive/pelican/posts/2023/a-theme-editor-for-jupyterlab/" rel="alternate"/><published>2023-06-19T08:11:00+00:00</published><updated>2023-06-19T08:11:00+00:00</updated><author><name>Florence Haudin</name></author><id>tag:jasongrout.github.io,2023-06-19:/medium-archive/pelican/posts/2023/a-theme-editor-for-jupyterlab/</id><summary type="html">&lt;p&gt;JupyterLab is a comprehensive web user interface for scientific and technical computing providing tools such as notebooks, text editors…&lt;/p&gt;
</summary><content type="html">&lt;p&gt;JupyterLab is a comprehensive web user interface for scientific and technical computing providing tools such as &lt;a href="https://jupyterlab.readthedocs.io/en/stable/user/notebook.html#notebook"&gt;notebooks&lt;/a&gt;, text editors, consoles, and terminals. Like many similar tools, it allows users to choose from light or dark color themes. However, users may want to further adjust the looks of the interface, just for fun or for specific personal preferences or needs.&lt;/p&gt;
&lt;p&gt;The ability to fine-tune contrast, color palettes, and fonts can be very useful for accessibility, an essential requirement for software to be usable by the whole community. There is an ongoing &lt;a href="https://jupyter-accessibility.readthedocs.io/"&gt;project-wide effort&lt;/a&gt; to improve accessibility in Jupyter. Choices of color palettes impact color-blind users while font choices can have a significant impact on people affected by dyslexia, or who suffer from migraines.&lt;/p&gt;
&lt;p&gt;This diversity of requirements and preferences shows that end users should have the means to adjust parameters and tweak existing themes. Subtle differences can improve comfort significantly.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;JupyterLab themes&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Theming in JupyterLab is enabled by the fact that most of the layout and colors of the UI are defined by a set of CSS variables. There is no need for a complete stylesheet: one can set values for the base parameters from which the appearance of the user interface is derived. This system ensures a consistent look and feel throughout the application.&lt;/p&gt;
&lt;p&gt;Custom themes provide a set of values for the base CSS variables and package the resulting CSS file in JupyterLab extensions. &lt;a href="https://github.com/search?q=jupyter+lab+theme"&gt;A search on GitHub&lt;/a&gt; returns 29 repositories defining such custom themes for JupyterLab.&lt;/p&gt;
&lt;p&gt;Creating a theme requires implementing values for &lt;em&gt;dozens&lt;/em&gt; of base CSS variables. This is often achieved by theme authors tweaking the values given in the default dark or light themes.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Generating a consistent palette, testing, and packaging the outcome in the form of a JupyterLab extension requires development skills and is neither direct nor trivial.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;A new tool for authoring JupyterLab themes&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To lower the bar for customizing JupyterLab we created a new tool providing a simple interface for tuning the JupyterLab appearance interactively, allowing theme authors to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;use the selected colors in their application and “pin down” the result in the configuration,&lt;/li&gt;
&lt;li&gt;export the outcome in a form amenable to packaging into a new JupyterLab theme.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The theme editor extension is a theme prototyping tool, a sandbox to test changes in colors, font family and font size, and a configuration tool for end users. It displays a reduced set of parameters one can play with, allowing users to select:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;colors through color pickers,&lt;/li&gt;
&lt;li&gt;numerical values from sliders (for font size, border radius and width),&lt;/li&gt;
&lt;li&gt;font families from a predefined dropdown list.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A screenshot of JupyterLab with the theme editor panel is displayed in Figure 1, with a notebook opened in light theme. Figure 2 shows different screenshots with different custom themes.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Screenshot of JupyterLab interface with the theme editor on the left panel and a notebook opened. The theme chosen is the light default one." src="https://jasongrout.github.io/medium-archive/pelican/posts/2023/a-theme-editor-for-jupyterlab/images/001-0_vj7tjopuS2GvZg3N.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Figure 1: The theme editor extension in JupyterLab.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
&lt;img alt="4 screenshots of the JupyterLab interface are shown to illustrate the kinds of themes that can be generated by the theme editor, with gray, blue, orange and pink tones and different font families." src="https://jasongrout.github.io/medium-archive/pelican/posts/2023/a-theme-editor-for-jupyterlab/images/002-0_5OLBiA8tmTbD1Nan.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Figure 2: Examples of dynamically editing the color and fonts scheme of JupyterLab with the theme editor.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Color palettes&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;For all the colors (accent, brand, border, error, info, layout, success, warn), the same logic is applied. The user picks a base color and a palette is automatically calculated using Microsoft’s &lt;a href="https://www.fast.design/docs/api/fast-colors.colorpalette"&gt;fast-colors&lt;/a&gt; library.&lt;/p&gt;
&lt;p&gt;Let’s take the specific example of the layout colors impacting the background of most elements of the interface. They are defined using &lt;em&gt;— jp-layout-colori&lt;/em&gt; CSS variables from white to light grays (for the light theme).&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nt"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;jp-layout-color0&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;white&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;jp-layout-color1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;white&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;jp-layout-color2&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;var&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;-md-grey-200&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;jp-layout-color3&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;var&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;-md-grey-400&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;jp-layout-color4&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;var&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;-md-grey-600&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The number of colors in the palette fits the number of colors in the CSS set of variables (here the palette contains 5 colors). There are different ways to define colors (hexadecimal, RGBA, HSLA). The latter format has the advantage of giving direct access to luminance &lt;em&gt;L&lt;/em&gt;, a measure of the lightness of a given color.&lt;/p&gt;
&lt;p&gt;An inverse layout palette is computed for use with most text elements. The luminance of the inverse layout color &lt;em&gt;L’&lt;/em&gt; is calculated as &lt;em&gt;1-L&lt;/em&gt; plus a correction depending on how &lt;em&gt;1-L&lt;/em&gt; is close to 0.5. There isn’t a general CSS rule in JupyterLab concerning elements on top of a background but some PRs were proposed to reinforce the coupling between inverse layout elements and layout backgrounds with the same color index. The contrast still needs to be improved though, by using other palettes or better corrections when defining the inverse layout colors.&lt;/p&gt;
&lt;p&gt;The full process just described from picking a layout color to resulting palettes and the corresponding interface is illustrated in Figure 3.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="The figure is divided into 3 parts. Part 1 is a screenshot with color picker with a green color selected. Part 2 is a capture showing the resulting palette calculated from this color choice. Finally, part 3 is a screenshot of JupyterLab interface with the different green tones calculated from the base color that has been picked." src="https://jasongrout.github.io/medium-archive/pelican/posts/2023/a-theme-editor-for-jupyterlab/images/003-0_vD9AcycD3qSCAJgu.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Figure 3: From a color to the layout, and inverse layout palettes with the resulting interface.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Font size and font family&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;As mentioned previously, font size and font family can be tuned too. Let’s take the example of the &lt;em&gt;— jp-ui-font-size[i]&lt;/em&gt; CSS variables defining the text size of most of the text elements in the interface:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nt"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;jp-ui-font-scale-factor&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;2&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;jp-ui-font-size0&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;8333em&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;jp-ui-font-size1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;13px&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c"&gt;/* Base font size */&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;jp-ui-font-size2&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;2em&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;jp-ui-font-size3&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;44em&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;A slider lets the user control the base font size associated with &lt;em&gt;— jp-ui-font-size1&lt;/em&gt;. The other font sizes are then calculated by applying a scale factor to the base font.&lt;/p&gt;
&lt;p&gt;Concerning font families, a non-exhaustive list is proposed (i.e., default browser fonts or Google fonts). It includes both standard accessible fonts (Arial, Courier, Helvetica, Sans Serif, system-ui, Times New Roman, Verdana) and less usual ones to create artistic or special interfaces with cursive fonts ( for instance Dancing Script or Single Day). Only 2 fonts are proposed for code: Space Mono and monospace.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Storing the new theme&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Once satisfied with a new theme, users can export it using a button at the top of the theme editor panel. This creates a &lt;em&gt;variable.css&lt;/em&gt; file that can be packaged in a theme extension (see the &lt;a href="https://github.com/jupyterlab/extension-cookiecutter-ts/"&gt;extension template&lt;/a&gt;). The new parameters are also synchronously saved in the settings editor and can be restored for the next JupyterLab opening if the boolean &lt;em&gt;useSettings&lt;/em&gt; is set to true. If not, the interface will look like in Figure 1: with light theme default CSS values. Resetting &lt;em&gt;useSettings&lt;/em&gt; to true will restore the formerly tuned parameters.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Future development&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The look and feel of the theme editor UI still needs to be improved. We will work on unifying the styling of all interfaces making use of &lt;a href="https://github.com/rjsf-team/react-jsonschema-form"&gt;react-jsonschema-form&lt;/a&gt;. It is already used for the JupyterLab settings editor, the notebook metadata editor of JupyterLab 4.0, and several extensions.&lt;/p&gt;
&lt;p&gt;Moreover, the current implementation is bound to fast-colors palettes and we may want to use a different approach, like decoupling the layout and inverse layout palettes to reach better contrasts or give more freedom in the color choices.&lt;/p&gt;
&lt;p&gt;Any help (e.g., filling issues for bugs or enhancement requests, opening pull requests) to improve &lt;a href="https://github.com/jupyterlab-contrib/jupyterlab-theme-editor"&gt;the extension&lt;/a&gt; is welcome.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Try it out&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You can install the &lt;a href="https://pypi.org/project/jupyter-theme-editor"&gt;PyPI package&lt;/a&gt; by running:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nx"&gt;pip&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;install&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;jupyter_theme_editor&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You can also try the theme editor on &lt;a href="https://mybinder.org/v2/gh/jupyterlab-contrib/jupyterlab-theme-editor/main?urlpath=lab"&gt;Binder&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Aknowledgement&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Many thanks to &lt;a href="https://twitter.com/ihuicatls"&gt;Isabel Paredes&lt;/a&gt; for drawing the palette icon!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;About the authors&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Florence Haudin is a scientific software developer at &lt;a href="https://twitter.com/QuantStack"&gt;QuantStack&lt;/a&gt;. She contributes to JupyterLab and to ipyleaflet.&lt;/p&gt;
&lt;p&gt;Frédéric Collonval supervised this work as a technical director at QuantStack. He is a member of the JupyterLab core team and authored several JupyterLab extensions.&lt;/p&gt;
</content><category term="accessibility"/><category term="extensions"/><category term="JupyterLab"/></entry></feed>