Html 如何更改 ipython 笔记本中的字体

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22386359/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:14:12  来源:igfitidea点击:

How to change font in ipython notebook

htmlcssfontsipython-notebook

提问by cb4

I am fairly new to python and have no html experience. The question has been asked and either not answered at all or not answered in enough detail for me to set the default font within iPython (not change to browser). Specifically, what has to be put in the css file and which css file should be used? I am on a Windows system.

我对 python 相当陌生,没有 html 经验。这个问题已经被问到,要么根本没有回答,要么没有足够详细地回答我在 iPython 中设置默认字体(不更改为浏览器)。具体来说,css文件中必须放什么,应该使用哪个css文件?我在 Windows 系统上。

For reference, these are in answer to the linked SO questions below:

作为参考,这些是对下面链接的 SO 问题的回答:

  • in #1: an unnamed file in /usr/lib/python2.6/.../css/
  • in comment to #1: change monospace font in browser - worked but font is italic
  • in #2: custom.cssin profile subdirectory /static/custom/custom.css
  • in #1: 一个未命名的文件/usr/lib/python2.6/.../css/
  • 在对 #1 的评论中:在浏览器中更改等宽字体 - 工作但字体为斜体
  • 在 #2 中custom.css在 profile 子目录中/static/custom/custom.css

Related questions:

相关问题:

  1. Change ipython notebook font type
  2. Change font & background color in ipython notebook
  3. Changing (back to default) font in ipython notebook(unanswered) -
  1. 更改 ipython 笔记本字体类型
  2. 在 ipython 笔记本中更改字体和背景颜色
  3. 在 ipython 笔记本中更改(恢复为默认值)字体(未答复)-

Edit:Changing the monospace font in my browser worked, as suggested in an answer comment of #1. However the font is italic, which is not what is intended.

编辑:按照#1 的答案评论中的建议,更改浏览器中的等宽字体有效。但是字体是斜体的,这不是预期的。

采纳答案by titipata

You can hover to .ipythonfolder (i.e. you can type $ ipython locatein your terminal/bash to see where is your ipython is located)

您可以将鼠标悬停到.ipython文件夹(即您可以$ ipython locate在终端/bash 中输入以查看您的 ipython 所在的位置)

Then, in .ipython, you will see profile_defaultdirectory which is the default one. This directory will have static/custom/custom.cssfile located.

然后,在 中.ipython,您将看到profile_default默认目录。该目录将包含static/custom/custom.css文件。

You can now apply change to this custom.cssfile. There are a lot of styles in the custom.cssfile that you can use or search for. For example, you can see this link(which is my own customize custom.cssfile)

您现在可以对这个custom.css文件应用更改。文件中有很多样式custom.css可供您使用或搜索。例如,你可以看到这个链接(这是我自己的自定义custom.css文件)

Basically, this custom.cssfile apply changes to your browser. You can use inspect elements in your ipython notebook to see which elements you want to change. Then, you can changes to the custom.cssfile. For example, you can add these chunk to change font in .CodeMirror preto type Monaco

基本上,此custom.css文件会将更改应用于您的浏览器。您可以在 ipython 笔记本中使用检查元素来查看要更改的元素。然后,您可以更改custom.css文件。例如,您可以添加这些块以更改字体.CodeMirror pre以键入Monaco

.CodeMirror pre {font-family: Monaco; font-size: 9pt;}

Notethat now for Jupyter notebook version >= 4.1, the custom css file is moved to ~/.jupyter/custom/custom.cssinstead.

请注意,现在对于 Jupyter Notebook 版本 >= 4.1,自定义 css 文件~/.jupyter/custom/custom.css改为移动到。

回答by Konrad

I would also suggest that you explore the options offered by the jupyter themer. For more modest interface changes you may be satisfied with running the syntax:

我还建议您探索jupyter themer提供的选项。对于更适度的界面更改,您可能会对运行语法感到满意:

jupyter-themer [-c COLOR, --color COLOR]
                      [-l LAYOUT, --layout LAYOUT]
                      [-t TYPOGRAPHY, --typography TYPOGRAPHY]

where the options offered by themerwould provide you with a less onerous way of making some changes in to the look of Jupyter Notebook. Naturally, you may still to prefer edit the .cssfiles if the changes you want to apply are elaborate.

Themer提供的选项将为您提供一种不那么繁琐的方式来对 Jupyter Notebook 的外观进行一些更改。当然,.css如果您要应用的更改很详细,您可能仍然更喜欢编辑文件。

回答by DreamFlasher

The new location of the theme file is: ~/.jupyter/custom/custom.css

主题文件的新位置是: ~/.jupyter/custom/custom.css

回答by Ruthger Righart

In addition to the suggestion by Konrad here, I'd like to suggest jupyter themes, which seems to have more options, such as line-height, font size, cell width etc.

除了这里 Konrad 的建议之外,我还想建议jupyter themes,它似乎有更多选项,例如行高、字体大小、单元格宽度等。

Command line usage:

命令行用法:

jt  [-h] [-l] [-t THEME] [-f MONOFONT] [-fs MONOSIZE] [-nf NBFONT]
[-nfs NBFONTSIZE] [-tf TCFONT] [-tfs TCFONTSIZE] [-dfs DFFONTSIZE]
[-m MARGINS] [-cursw CURSORWIDTH] [-cursc CURSORCOLOR] [-vim]
[-cellw CELLWIDTH] [-lineh LINEHEIGHT] [-altp] [-P] [-T] [-N]
[-r] [-dfonts]

回答by praveen kumar yethirajula

Using Jupyterthemes, one can easily change look of notebook.

使用 Jupyterthemes,可以轻松更改笔记本的外观。

pip install jupyterthemes

jt -fs 15 

By default code font size is set to 11 . Trying above will change font size. It can be reset using.

默认情况下,代码字体大小设置为 11 。尝试以上将改变字体大小。可以使用重置。

jt -r 

This will reset all jupyter theme changes to default.

这会将所有 jupyter 主题更改重置为默认值。