Reputation: 3580
I would like to set default font size and font type via code in line within a python notebook.
For example, I use this to set plot size defaults:
params = {'legend.fontsize': 'x-large','figure.figsize': (15, 10),'axes.labelsize': 'x-large','axes.titlesize':'x-large',
'xtick.labelsize':'x-large','ytick.labelsize':'x-large'}
pylab.rcParams.update(params)
I use this to set window width defaults
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))
Is there a command that lets me set default markdown font to Arial size 24? Thank you!
Upvotes: 1
Views: 8387
Reputation: 38982
MarkdownCell.render
can be patched to render markdown cells to a specified font size.
Dump the snippet below in a code cell and run.
from IPython.core.display import Javascript, display
def set_markdown_font():
javascript = """
var _render = IPython.MarkdownCell.prototype.render;
if (_render.decorator === undefined) {
IPython.MarkdownCell.prototype.render = function () {
this.element.find('.rendered_html p').css('font-size', '30px');
return _render.apply(this, arguments);
}
IPython.MarkdownCell.prototype.render.decorator = true;
}
"""
display(Javascript(data=javascript))
set_markdown_font()
Edit
You can also target HTMLElement having .rendered_html
class and style them appropriately. I prefer this better (CSS over JS).
from IPython.core.display import display, HTML
display(HTML("<style>.rendered_html { font-size: 30px; }</style>"))
Upvotes: 3