Abdul Saboor1
Jun 18, 2025
1My University is somewhere in the middle of nowhere
IPySlides Documentation
```multicol .block-green
toc[True]`## Table of contents`
+++
Extra content for current section which is on right
```
IPySlides Documentation
Interactive Slides in IPython Notebook. Only one instance can exist. settings
are passed to Slides.settings()
if you like to set during initialization.
To suppress unwanted print from other libraries/functions, use:
with slides.suppress_stdout():
some_function_that_prints() # This will not be printed
print('This will not be printed either')
display('Something') # This will be printed
The traitlets callables under settings returns settings back to enable chaining
without extra typing, like Slides.settings.logo().layout()...
.
Slides.instance()
class method to keep older settings. Slides()
apply default settings every time.slides.demo()
to see a demo of some features.slides.docs()
to see documentation.Slides.create
is much faster than adding them one by one.Create New View for Output
for optimized display.Windowing mode
in Notebook settings to defer
or none
.Slides.xmd_syntax
for extended markdown syntax, especially variables formatting.Slides.fmt
to pick variables from local scope.Slides
can be indexed same way as list for sorted final indices. For indexing slides with given number, use comma as Slides[number,] -> Slide
or access many via list as Slides[[n1,n2,..]] -> tuple[Slide]
. Use indexing with given number to apply persistent effects such as CSS.
Initialize a button to jump to given target slide when clicked.
text
is the text to be displayed on button.
kwargs
are passed to ipywidgets.Button
function.
.display()
method to display button in a slide..set_target()
method under target slide.goto_button
is converted to a link in exported slides that can be clicked to jump to slide..set_target()
on a previous slides and .display()
on a later slide to create a link that jumps backwards.IPySlides Documentation
Besides function below, you can add slides with %%slide number [-m]
magic as well.
Build slides with a single unified command in three ways:
slides.build(number, callable)
to create a slide from a callable(slide)
immediately, e.g. lambda s: slides.write(1,2,3)
or as a decorator.with slides.build(number):
creates single slide. Equivalent to %%slide number
magic.fsep()
from top import or Slides.fsep()
to split content into frames.for item in fsep.iter(iterable):
block to automatically add frame separator.fsep(True)
/fsep.iter(...,stack=True)
to join content of frames incrementally.slides.build(number, str | fmt)
creates many slides with markdown content. Equivalent to %%slide number -m
magic in case of one slide.--
and slides separator is triple dashes ---
. Same applies to Slides.sync_with_file
too.%++
to join content of frames incrementally.multicol
before --
creates incremental columns if %++
is provided.slides.xmd_syntax
for extended markdown usage.Slides.sync_with_file
too.var
in notebook.fmt(str, **kwargs)
, varaiables are picked from kwargs
or local scope and can't be changed later. Useful in python scripts.number
could be used as -1
.integer in px
in markdown or Slides.this.yoffset(integer)
to make all frames align vertically to avoid jumps in increments.build_(...)
(with underscore at end) in python file instead of build(-1,...)
.Auto update slides when content of markdown file changes. You can stop syncing using Slides.unsync
function.
interval is in milliseconds, 500 ms default. Read Slides.build
docs about content of file.
The variables inserted in file content are used from top scope.
To debug a linked file, use EOF on its own line to keep editing and clearing errors.
IPySlides Documentation
Use slide handle or Slides[number,]
to apply these methods becuase index can change on new builds.
Set yoffset (in perect) for frames to have equal height in incremental content.
Set animation of this slide. Provide None if need to stop animation. Use main_all and frame to set animation to all slides.
Adds background image to this slide. src
can be a url or a local image path or an svg str.
filter is a CSS filter like blur(5px), grayscale() etc.
This function enables you to add a slide purely with an image, possibly with opacity=1
and contain = True
.
Update display of this slides including reloading citations, widgets etc.
Return source code of this slide, markdwon or python or None if no source exists. kwargs are passed to Slides.code.from_string
.
Show this slide in cell.
Attributes at the root level of the dictionary are only picked if they are related to background. Each call will reset previous call if props given explicitly, otherwise not.
Slides.css_syntax
for information on how to write CSS dictionary.slides.html('style',props)
, you can set CSS variables at top level here including theme variables
--fg[1,2,3]-color
,--bg[1,2,3]-color
and --[accent, pointer]-color
to tweek appearance of individual or all slides.CSS is formatted using a props
nested dictionary to simplify the process.
There are few special rules in props
:
'.A': {'.B': ... }
becomes .A .B {...}
in CSS.'.A': {'^:hover': ...}
becomes .A:hover {...}
in CSS. You can also use '.A:hover'
directly but it will restrict other nested keys to hover only.'.A': {'font-size': ('20px','2em')}
becomes .A {font-size: 20px; font-size: 2em;}
in CSS.Read about specificity of CSS selectors here.
props = {
".A": {
"z-index": "2",
".B": {
"font-size": [
"24px",
"2em"
],
"^:hover": {
"opacity": "1"
}
},
"> h1": {
"padding": "0",
"@media screen and (min-width: 650px)": {
"padding": "2em"
}
},
".C p": {
"font-size": "14px"
}
},
".D": {
"transform": "translate(-2px,1px)",
"^, h1": {
"background": "red",
"span, i": {
"color": "whitemoke",
"@keyframes animation-name": {
"from": {
"opacity": 0
},
"to": {
"opacity": 1
}
}
}
}
}
}
Output of html('style',props)
, set_css(props)
etc. functions. Top selector would be different based on where it is called.
<style>
.SlideArea .A {
z-index : 2;
}
.SlideArea .A .B {
font-size : 24px;
font-size : 2em;
}
.SlideArea .A .B:hover {
opacity : 1;
}
.SlideArea .A > h1 {
padding : 0;
}
@media screen and (min-width: 650px) {
.SlideArea .A > h1 {
padding : 2em;
}
}
.SlideArea .A .C p {
font-size : 14px;
}
.SlideArea .D {
transform : translate(-2px,1px);
}
.SlideArea .D,
.SlideArea .D h1 {
background : red;
}
.SlideArea .D span,
.SlideArea .D i,
.SlideArea .D h1 span,
.SlideArea .D h1 i {
color : whitemoke;
}
@keyframes animation-name {
from {
opacity : 0;
}
to {
opacity : 1;
}
}
</style>
IPySlides Documentation
# self is in scope, auto picked, also fmt can be parsed on display
display(self.fmt('%{self.version!r} %{self.xmd_syntax}'))
'5.6.0'
Extended Markdown
Extended syntax for markdown is constructed to support almost full presentation from Markdown.
Slides-specific syntax
---
is used to split text in slides inside markdown content of Slides.build
function or markdown file.
Double dashes --
is used to split text in frames. Alongwith this %++
can be used to increment text on framed slide.Slides.set_citations
function.
With citations mode set as 'footnote', you can add refs`ncol_refs` to add citations anywhere on slide. If ncol_refs
is not given, it will be picked from layout settings.Slides.docs()
for creating a TOC
accompanied by section summary.General syntax
version >= 4.5
) to display objects inside markdown as they are displayed in a Notebook cell.
Custom objects serialized with Slides.serializer
or serialized by ipyslides
should be displayed without :nb
whenever possible to appear in correct place in all contexts. e.g.
a matplotlib's figure fig
as shown in %{fig:nb}
will only capture text representation inplace and actual figure will be shown at end, while %{fig}
will be shown exactly in place.Slide[number,].rebuild(**kwargs)
to force update variables if some error happens. This is useful for setting unique values of a variable on each slide.fmt(content, **vars)
will not expose encapsulated vars
for updates later, like static stuff but useful inside python scripts to pick local scope variable.rebuild > __main__
. Outer scope variables are overwritter by inner scope variables.%{var.attr}
and indexing like %{var[0]}
/%{var["key"]}
will be update only if var
itself is changed.%{variable:nb} breaks the DOM flow, e.g. if you use it inside heading, you will see two headings above and below it with splitted text. Its fine to use at end or start or inside paragraph.
:nb
format spec. str.format
method, so f-string like literal expressions are not supported, but you don't need to supply variables, just enclose text in Slides.fmt
.locals()
/globals()
). To use variables from a nested scope, use Slides.fmt
.+++
:
```multicol widthA widthB .class1.class2
Column A
+++
Column B
```
Item 1 Header
: Item 1 details
Item 1 Header
: Item 1 details
👉
print('Hello, I was highlighted from a code block!')
::: block-yellow
Some **bold text**
👉
Some bold text
Note
Above block syntax is enabled using customblocks which is added by default and can be used to build nested html blocks.
Slides.extender
to extend additional syntax using Markdown extensions such as
markdown extensions and
PyMdown-Extensions.['tables', 'footnotes', 'attr_list', 'md_in_html', 'customblocks', 'def_list']
.Slides.serializer
function. Having a
__format__
method in your class enables to use {obj} syntax in python formatting and %{obj} in extended Markdown.Other options (that can also take extra args [python code as strings] as func[arg1,x=2,y=A]`arg0`) include:
IPySlides Documentation
Besides functions below, you can add content to slides with %%xmd
,%xmd
as well.
Write objs
to slides in columns. To create rows in a column, wrap objects in a list or tuple.
You can optionally specify widths
as a list of percentages for each column.
css_class
can have multiple classes separated by space, works only for multiple columns.
Write any object that can be displayed in a cell with some additional features:
Slides.hold(func,...)
. Only body of the function will be displayed/printed. Return value will be ignored.ipywidgets
or ipyvolume
by passing them directly.matplotlib
, plotly
altair
, bokeh
etc. by passing them directly.Slides.code
API.Slides.alt
function to display obj/widget on slides and alternative content/screenshot in exported slides.Slides.clip
to add screenshots from clipboard.ipywidgets.[HTML, Output, Box]
and their subclasses will be displayed as Slides.alt(html_converter_func, widget)
. The value of exported HTML will be most recent.ipyslides.utils
module that are also linked to Slides
object._repr_html_
method, you can create one for your own objects/third party objects by:Slides.serializer
API. IPython's display
automatically takes care of such objects on export to html.IPython.core.formatters
API for third party libraries.Note
Slides.frozen
to avoid display formatting and markdown parsing over objects in write
and for some kind of objects in display
too.write
is a robust command that can handle most of the cases. If nothing works, repr(obj)
will be displayed.repr(obj)
by Slides.hold(func, ...)
e.g. Slides.hold(plt.show)
. This can also be used to delay display until it is captured in a column.display(obj, metadata = {'text/html': 'html repr by user'})
for any object to display object as it is and export its HTML representation in metadata.write
is equivalent to parse
command.Slides.cols
, but content type is limited in that case.Parse extended markdown and display immediately.
If you need output html, use returns = True
but that won't display variables.
Example
# Normal Markdown
```multicol 40 60
# First column is 40% width
If 40 60 was not given, all columns will be of equal width, this paragraph will be inside info block due to class at bottom
{.info}
+++
# Second column is 60% wide
This \%{var_name} (or legacy \`{var_name}\`) can be substituted with `fmt` function or from notebook if whole slide is built with markdown.
```
```python
# This will not be executed, only shown
```
|| Inline-column A || Inline-column B ||
python .friendly
or multicol .Sucess.info
.python .friendly
will be highlighted with friendly theme from pygments.multicol
.::: class_type
syntax accepts extra classes in quotes, for example ::: multicol "Success" "info"
.jupyter-only
and export-only
that control appearance of content in different modes.Nested blocks are not supported.
Slides.xmd_syntax
.Slides.extender
or ipyslides.xmd.extender
to add markdown extensions.Save image from clipboard to file with a given quality when you paste in given area on slides.
Pasting UI is automatically enabled and can be disabled in settings panel.
On next run, it loads from saved file under Slides.clips_dir
.
If obj
is given (any object), that is directly shown on slides without any parsing and pasted image is exported.
If no obj
is passed, both slides and exported HTML shares same image view.
On each paste, existing image is overwritten and stays persistent for later use. You can use these clips
in other places with Slides.image("clip:filename")
as well.
Slides.alt('clip:test.png', obj)
is same as display(obj);Slides.clip('test.png', export_only=True)
.
If you have an HTML serialization function for a widget, pass it directly to write
or use alt(func, widget)
instead.
That will save you the hassel of copy pasting screenshots. ipywidgets
's HTML
, Box
and Output
widgets and their subclasses directly give
html representation if used inside write
command.
**kwargs are passed to Slides.image
function.
On Linux, you need xclip or wl-paste installed.
IPySlides Documentation
You can use notes`notes content` in markdown.\n{.note .success}\n
This is experimental feature, and may not work as expected.
Add notes to current slide. Content could be any object except javascript and interactive widgets.
In markdown, you can use notes`notes content`.
IPySlides Documentation
Create source code object from file, text or callable. kwargs
are passed to ipyslides.formatter.highlight
.
Execute and displays source code in the context manager. kwargs
are passed to ipyslides.formatter.highlight
function.
Useful when source is written inside context manager itself.
If returns
is False (by default), then source is displayed before the output of code. Otherwise you can assign the source to a variable and display it later anywhere.
Usage:
with source.context(returns = True) as s:
do_something()
write(s) # or s.display(), write(s)
#s.raw, s.value are accesible attributes.
#s.focus_lines, s.show_lines are methods that are used to show selective lines.
Returns source object from a given callable [class,function,module,method etc.] with show_lines
and focus_lines
methods. kwargs
are passed to ipyslides.formatter.highlight
Returns source object with show_lines
and focus_lines
methods. name
is alternate used name for language.
kwargs
are passed to ipyslides.formatter.highlight
.
It tries to auto detect lanaguage from filename extension, if language
is not given.
Creates source object from string. name
is alternate used name for language. kwargs
are passed to ipyslides.formatter.highlight
.
IPySlides Documentation
IPySlides Documentation
Apply settings to slides programatically. Fewer settings are available as widgets.
Settings can be nested or individual attributes as set as well. For example:
Slides.settings(layout = {"aspect": 16/10}) # Top
Slides.settings.layout(aspect = 16/10) # Individual
Slides.settings.layout.aspect = 16/10 # Attribute
All settings calls including top level returns settings instance to apply method chaining.
e.g. Slides.settings.layout(aspect = 16/10).footer(text="ABC").logo(...)
.
Set code block styles. background and color may be needed for some styles.
Set fonts of text and code and size.
Set footer attributes of slides.
Set layout of slides.
Set logo for all slides.
Set theme value. colors and code have their own nested traits.
Toggle ON/OFF checks in settings panel.
IPySlides Documentation
clipboard image
clip[caption='clipboard image']`test.png`
Save image from clipboard to file with a given quality when you paste in given area on slides.
Pasting UI is automatically enabled and can be disabled in settings panel.
On next run, it loads from saved file under Slides.clips_dir
.
If obj
is given (any object), that is directly shown on slides without any parsing and pasted image is exported.
If no obj
is passed, both slides and exported HTML shares same image view.
On each paste, existing image is overwritten and stays persistent for later use. You can use these clips
in other places with Slides.image("clip:filename")
as well.
Slides.alt('clip:test.png', obj)
is same as display(obj);Slides.clip('test.png', export_only=True)
.
If you have an HTML serialization function for a widget, pass it directly to write
or use alt(func, widget)
instead.
That will save you the hassel of copy pasting screenshots. ipywidgets
's HTML
, Box
and Output
widgets and their subclasses directly give
html representation if used inside write
command.
**kwargs are passed to Slides.image
function.
On Linux, you need xclip or wl-paste installed.
This is a simple slider widget that can be used to control the animation with an observer function.
You need to provide parameters like nframes
and interval
(milliseconds) to control the animation.
The value
trait can be observed to get the current frame index.
The cyclic
trait can be set to True
to make the animation cyclic and only works when loop mode is ON.
from plotly.graph_objects import FigureWidget
fig = FigureWidget()
fig.add_scatter(y=[1, 2, 3, 4, 5])
widget = slides.AnimationSlider() # assuming slides is the instance of Slides app
def on_change(change):
value = change['new']
fig.data[0].color = f'rgb({int(value/widget.nframes*100)}, 100, 100)' # change color based on frame index
widget.observe(on_change, names='value')
display(widget, fig) # display it in the notebook
This widget can be passed to ipywidgets.interactive
as keyword argument to create a dynamic control for the animation.
from ipywidgets import interact
@interact(frame=widget)
def show_frame(frame):
print(frame)
Alerts text!
Format a block like in LATEX beamer with objs
in columns and immediately display it. Format rows by given an obj as list of objects.
block_<red,green,blue,yellow,cyan,magenta,gray>
.write
command for details of objs
and widths
.Write bokeh figure as HTML string to use in ipyslide.utils.write
.
Parameters
A powerful bullet list. iterable
could be list of anything that you can pass to write
command.
marker
could be a unicode charcter or string, only effects unordered list.
Colors text, fg
and bg
should be valid CSS colors
Returns HTML containing multiple columns of given widths. This alongwith rows
can create grid.
Show/Hide Content in collapsed html.
Returns documentation of an obj
. You can prepend a class/module name. members is True/List of attributes to show doc of.
Add error without breaking execution.
Markdown string wrapper that will be parsed with given kwargs lazily. If markdown contains variables not in kwargs, it will try to resolve them from local/global namespace and raise error if name is nowhere. Use inside python scripts when creating slides. In notebook, variables are automatically resolved, although you can still use it there.
Being as last expression of notebook cell or using self.parse() will parse markdown content.
Display object as it it and export metadata if not str. A frozen object may not appear in exported html if metadata is not given.
Returned object has a display method, or can be directly passed to display/write commands.
Highlight code (any python object that has a source or str of code) with given language and style.
pygments.styles.get_all_styles()
, then style will be applied immediately.If you want plain inline highlight, use Slides.
.or
ipyslides.utils.hl
Returns html node with given children and node attributes like style, id etc. If an ttribute needs '-' in its name, replace it with '_'.
tag
can be any valid html tag name. A tag
that ends with /
will be self closing e.g. hr/
will be <hr/>
. Empty tag gives unwrapped children.
children
expects:
slides[number,].set_css
otherwise. See Slides.css_syntax
to learn about requirements of styles in dict.Example:
html('img',src='ir_uv.jpg') #Returns IPython.display.HTML("<img src='ir_uv.jpg'></img>") and displas image if last line in notebook's cell.
To keep an image persistently embeded, use ipyslides.utils.imge
function instead of just an html tag.
Display src
in an iframe. kwrags
are passed to IPython.display.IFrame
Displays PNG/JPEG files or image data etc, kwrags
are passed to IPython.display.Image.
crop
is a tuple of (left, top, right, bottom) in percentage of image size to crop the image.
css_props
are applied to figure
element, so you can control top layout and nested img tag.
You can provide following to data
parameter:
Slides.clip('image.png')
. Returns an IMG
object which can be exported to other formats (if possible):
IMG.to_pil()
returns PIL.Image
or None.IMG.to_numpy()
returns image data as numpy array for use in plotting libraries or None.Send inside notifications for user to know whats happened on some button click. Send 'x' in content to clear previous notification immediately.
Write matplotib figure as HTML string to use in ipyslide.utils.write
.
Parameters
Keep shape of text as it is (but apply dedent), preserving whitespaces as well.
Creates single compact object instead of publishing multiple display data. Create grid using cols
as children.
Context manager to set working directory to given path and return to previous working directory when done.
Returns signature of a callable. You can prepend a class/module name.
Add a class to a given object, whether a widget or html/IPYthon object. CSS inline style properties should be given with names including '-' replaced with '_' but values should not. Only a subset of inline properties take effect if obj is a widget.
Objects other than widgets will be wrapped in a 'div' tag. Use html
function if you need more flexibility.
Suppress output of a block of code. If stdout
is False, only display data is suppressed.
Suppress stdout in a block of code, especially unwanted print from functions in other modules.
Display svg file or svg string/bytes with additional customizations.
crop
is a tuple of (left, top, right, bottom) in percentage of image size to crop the image.
css_props
are applied to figure
element, so you can control top layout and nested svg tag.
kwrags
are passed to IPython.display.SVG. You can provide url/string/bytes/filepath for svg.
Creates a table of given data like DataFrame, but with rich elements.
data
should be a 2D matrix-like. headers
is a list of column names. widths
is a list of widths for each column.
Example:
import pandas as pd
df = pd.DataFrame({'A': [1,2,3], 'B': [4,5,6]})
slides.table(df.values, headers=df.columns, widths=[1,2])
slides.table([[1,2,3],[4,5,6]], headers=['A','B','C'], widths=[1,2,3])
Formats text in a box for writing e.g. inline refrences. css_props
are applied to box and -
should be _
like font-size
-> font_size
.
text
is not parsed to general markdown i.e. only bold italic etc. applied, so if need markdown, parse it to html before. You can have common CSS for all textboxes using class text-box
.
Returns today's date in given format.
Returns html node with given height in em
.
Wraps a given obj in a parent with 'zoom-child' class or add 'zoom-self' to widget, whether a widget or html/IPYthon object
IPySlides Documentation
Use syntax cite`key` to add citations which should be already set by Slides.set_citations(data, mode)
method.
Citations are written on suitable place according to given mode. Number of columns in citations are determined by
Slides.settings.layout(..., ncol_refs = int)
. 1
Add sections in slides to separate content by section`text`. Corresponding table of contents can be added with toc`title`.
Set citations from dictionary or file that should be a JSON file with citations keys and values, key should be cited in markdown as cite`key`.
mode
for citations should be one of ['inline', 'footnote']. Number of columns in citations are determined by Slides.settings.layout(..., ncol_refs=N)
.
Note
Citation A
IPySlides Documentation
Enhanced interactive widget with multiple callbacks, grid layout and fullscreen support.
This function is used for quick dashboards. Subclass InteractBase
for complex applications.
Features:
Basic Usage:
from ipyslides.interaction import interactive, callback, monitor
import ipywidgets as ipw
import plotly.graph_objects as go
fig = go.FigureWidget()
@callback('out-plot', timeit=True) # check execution time
def update_plot(x, y, fig):
fig.data = []
fig.add_scatter(x=[0, x], y=[0, y])
def resize_fig(fig, fs):
fig.layout.autosize = False # double trigger
fig.layout.autosize = True # plotly's figurewidget always make trouble with sizing
# Above two functions can be merged since we can use changed detection
@monitor # check execution time
def respond(x, y, fig , fs, changed):
if 'fs' in changed: # or changed('fs')
fig.layout.autosize = False # double trigger
fig.layout.autosize = True
else:
fig.data = []
fig.add_scatter(x=[0, x], y=[0, y])
dashboard = interactive(
update_plot,
resize_fig, # responds to fullscreen change
# respond, instead of two functions
x = ipw.IntSlider(0, 0, 100),
y = ipw.FloatSlider(0, 1),
fig = ipw.fixed(fig),
changed = '.changed', # detect a change in parameter
fs = '.isfullscreen', # detect fullscreen change on instance itself
)
Parameters:
*funcs
: One or more callback functionsrelayout()
method for details:fullscreen
at root level of dict to apply styles in fullscreen mode[Button, ToggleButton, ToggleButtons].add_class('content-width-button')
to fix button widths easily.**kwargs
: Widget parametersWidget Parameters:
changed = '.changed'
to detect which parameters of a callback changed by checking changed('param') -> Bool
in a callback.f(fig, v)
where v='fig.selected'
.ipywidgets.Button
for manual updates on callbacks besides global auto_update
. Add tooltip for info on button when not synced.btn.clicked
attribute to run code based on which button was clicked.Widget Updates:
@callback
.CSS Classes:
Notes:
Python dictionary to CSS
CSS is formatted using a props
nested dictionary to simplify the process.
There are few special rules in props
:
'.A': {'.B': ... }
becomes .A .B {...}
in CSS.'.A': {'^:hover': ...}
becomes .A:hover {...}
in CSS. You can also use '.A:hover'
directly but it will restrict other nested keys to hover only.'.A': {'font-size': ('20px','2em')}
becomes .A {font-size: 20px; font-size: 2em;}
in CSS.Read about specificity of CSS selectors here.
Tips:
write('First column', C2)
where C2 = Slides.hold(Slides.ei.interact, f, x = 5) or Slides.ei.interactive(f, x = 5)
.Slides.capture_content
to display later in a specific place.
import time
@self.ei.interact(auto_update=False, grid_css = dict({'.out-main': dict(height='2em')},background='var(--bg2-color)'), date = False) # self is Slides here
def update_time(date):
local_time = time.localtime()
objs = ['Time: {3}:{4}:{5}'.format(*local_time)] # Print time in HH:MM:SS format
if date:
objs.append('Date: {0}/{1}/{2}'.format(*local_time))
self.cols(*objs).display()
Time: 21:38:57
import datetime
@self.on_load # self is Slides here
def push_toast(slide):
t = datetime.datetime.now()
time = t.strftime('%H:%M:%S')
self.notify(f'Notification at {time} form slide {slide.index} and frame {slide.indexf}', timeout=5)
Decorator for running a function when slide is loaded into view. No return value is required. Use this to e.g. notify during running presentation. func accepts single arguemnet, slide.
See Slides.docs()
for few examples.
IPySlides Documentation
You can style or colorize your content and text. Provide CSS for that using Slides.html("style",...)
or use some of the available styles. See these styles with Slides.css_styles
property as below:
self.write(('You can **style**{.error} or **color["teal"]`colorize`** your *content*{: style="color:hotpink;"} and *color["hotpink","yellow"]`text`*. '
'Provide **CSS**{.info} for that using hl`Slides.html("style",...)` or use some of the available styles. '
'See these **styles**{.success} with `Slides.css_styles` property as below:'))
self.css_styles.display()
c.display()
IPySlides Documentation
pygments is used for syntax highlighting 1.
You can highlight code using highlight
function 2 or within markdown using code blocks enclosed with three backticks:
import ipyslides as isd
import React, { Component } from "react";
s is assigned variable to this slide:
s.set_css({
'--bg1-color': 'linear-gradient(45deg, var(--bg3-color), var(--bg2-color), var(--bg3-color))',
'.highlight': {'background':'#8984'}
})
self.styled('## Layout and Theme Settings', 'info', border='1px solid red').display()
self.doc(self.settings,'Slides', members=True,itself = True).display()
IPySlides Documentation
You can parse and view a markdown file. The output you can save by exporting notebook in other formats.
Auto update slides when content of markdown file changes. You can stop syncing using Slides.unsync
function.
interval is in milliseconds, 500 ms default. Read Slides.build
docs about content of file.
The variables inserted in file content are used from top scope.
To debug a linked file, use EOF on its own line to keep editing and clearing errors.
Demo slides with a variety of content.
Create presentation from docs of IPySlides.
Build html slides that you can print.
Slides.clip
or Slides.alt(image_filename, ...)
to keep PNG view of a widget. alt
or clip
functionality as well.Save as PDF
option instead of Print PDF in browser to make links work in output PDF. Alsp enable background graphics in print dialog.IPySlides Documentation
IPySlides Documentation
self.write("## Adding content on frames incrementally yoffset`0`")
self.frozen(widget := (code := s.get_source()).as_widget()).display()
self.fsep(stack=True) # frozen in above line get oldest metadata for export
def highlight_code(slide): widget.value = code.focus_lines(range(slide.indexf + 1)).value
self.on_load(highlight_code)
for ws, cols in self.fsep.iter(zip([None, (2,3),None], [(0,1),(2,3),(4,5,6,7)])):
cols = [self.html('h1', f"{c}",style="background:var(--bg3-color);margin-block:0.05em !important;") for c in cols]
self.write(*cols, widths=ws)
IPySlides Documentation
self.write("## Adding content on frames incrementally yoffset`0`")
self.frozen(widget := (code := s.get_source()).as_widget()).display()
self.fsep(stack=True) # frozen in above line get oldest metadata for export
def highlight_code(slide): widget.value = code.focus_lines(range(slide.indexf + 1)).value
self.on_load(highlight_code)
for ws, cols in self.fsep.iter(zip([None, (2,3),None], [(0,1),(2,3),(4,5,6,7)])):
cols = [self.html('h1', f"{c}",style="background:var(--bg3-color);margin-block:0.05em !important;") for c in cols]
self.write(*cols, widths=ws)
IPySlides Documentation
self.write("## Adding content on frames incrementally yoffset`0`")
self.frozen(widget := (code := s.get_source()).as_widget()).display()
self.fsep(stack=True) # frozen in above line get oldest metadata for export
def highlight_code(slide): widget.value = code.focus_lines(range(slide.indexf + 1)).value
self.on_load(highlight_code)
for ws, cols in self.fsep.iter(zip([None, (2,3),None], [(0,1),(2,3),(4,5,6,7)])):
cols = [self.html('h1', f"{c}",style="background:var(--bg3-color);margin-block:0.05em !important;") for c in cols]
self.write(*cols, widths=ws)
IPySlides Documentation
self.write("## Adding content on frames incrementally yoffset`0`")
self.frozen(widget := (code := s.get_source()).as_widget()).display()
self.fsep(stack=True) # frozen in above line get oldest metadata for export
def highlight_code(slide): widget.value = code.focus_lines(range(slide.indexf + 1)).value
self.on_load(highlight_code)
for ws, cols in self.fsep.iter(zip([None, (2,3),None], [(0,1),(2,3),(4,5,6,7)])):
cols = [self.html('h1', f"{c}",style="background:var(--bg3-color);margin-block:0.05em !important;") for c in cols]
self.write(*cols, widths=ws)
IPySlides Documentation
self.write("## Adding content on frames incrementally yoffset`0`")
self.frozen(widget := (code := s.get_source()).as_widget()).display()
self.fsep(stack=True) # frozen in above line get oldest metadata for export
def highlight_code(slide): widget.value = code.focus_lines(range(slide.indexf + 1)).value
self.on_load(highlight_code)
for ws, cols in self.fsep.iter(zip([None, (2,3),None], [(0,1),(2,3),(4,5,6,7)])):
cols = [self.html('h1', f"{c}",style="background:var(--bg3-color);margin-block:0.05em !important;") for c in cols]
self.write(*cols, widths=ws)
IPySlides Documentation
self.write("## Adding content on frames incrementally yoffset`0`")
self.frozen(widget := (code := s.get_source()).as_widget()).display()
self.fsep(stack=True) # frozen in above line get oldest metadata for export
def highlight_code(slide): widget.value = code.focus_lines(range(slide.indexf + 1)).value
self.on_load(highlight_code)
for ws, cols in self.fsep.iter(zip([None, (2,3),None], [(0,1),(2,3),(4,5,6,7)])):
cols = [self.html('h1', f"{c}",style="background:var(--bg3-color);margin-block:0.05em !important;") for c in cols]
self.write(*cols, widths=ws)
IPySlides Documentation
self.write("## Adding content on frames incrementally yoffset`0`")
self.frozen(widget := (code := s.get_source()).as_widget()).display()
self.fsep(stack=True) # frozen in above line get oldest metadata for export
def highlight_code(slide): widget.value = code.focus_lines(range(slide.indexf + 1)).value
self.on_load(highlight_code)
for ws, cols in self.fsep.iter(zip([None, (2,3),None], [(0,1),(2,3),(4,5,6,7)])):
cols = [self.html('h1', f"{c}",style="background:var(--bg3-color);margin-block:0.05em !important;") for c in cols]
self.write(*cols, widths=ws)
IPySlides Documentation
self.write("## Adding content on frames incrementally yoffset`0`")
self.frozen(widget := (code := s.get_source()).as_widget()).display()
self.fsep(stack=True) # frozen in above line get oldest metadata for export
def highlight_code(slide): widget.value = code.focus_lines(range(slide.indexf + 1)).value
self.on_load(highlight_code)
for ws, cols in self.fsep.iter(zip([None, (2,3),None], [(0,1),(2,3),(4,5,6,7)])):
cols = [self.html('h1', f"{c}",style="background:var(--bg3-color);margin-block:0.05em !important;") for c in cols]
self.write(*cols, widths=ws)
IPySlides Documentation
self.write("## Adding content on frames incrementally yoffset`0`")
self.frozen(widget := (code := s.get_source()).as_widget()).display()
self.fsep(stack=True) # frozen in above line get oldest metadata for export
def highlight_code(slide): widget.value = code.focus_lines(range(slide.indexf + 1)).value
self.on_load(highlight_code)
for ws, cols in self.fsep.iter(zip([None, (2,3),None], [(0,1),(2,3),(4,5,6,7)])):
cols = [self.html('h1', f"{c}",style="background:var(--bg3-color);margin-block:0.05em !important;") for c in cols]
self.write(*cols, widths=ws)
IPySlides Documentation
self.write('## Adding User defined Objects/Markdown Extensions')
self.write(
self.hold(display, self.html('h3','I will be on main slides',css_class='warning'),
metadata = {'text/html': '<h3 class="warning">I will be on exported slides</h3>'}
), # Can also do 'Slides.serilaizer.get_metadata(obj)' if registered
s.get_source(), widths = [1,3]
)
self.write('If you need to serialize your own or third party objects not serialized by this module, you can use `@Slides.serializer.register` to serialize them to html.\n{.note .info}')
self.doc(self.serializer,'Slides.serializer', members = True, itself = False).display()
self.write('**You can also extend markdown syntax** using `markdown extensions`, ([See here](https://python-markdown.github.io/extensions/) and others to install, then use as below):')
self.doc(self.extender,'Slides.extender', members = True, itself = False).display()
If you need to serialize your own or third party objects not serialized by this module, you can use @Slides.serializer.register
to serialize them to html.
Get serializer function for a type. Returns None if not found.
Get html str of a registerd obj_type.
Get metadata for a type to use in display(obj, metadata)
for export purpose. This take precedence over object's own html representation. Returns {} if not found.
Decorator to register html serializer for an object type.
obj_type
and should return HTML string.Usage
class MyObject:
def __repr__(self):
return 'My object is awesome'
slides = ipyslides.Slides()
@slides.serializer.register(MyObject)
def parse_myobject(obj):
return f'<h1>{obj!r}</h1>'
my_object = MyObject()
slides.write(my_object) #This will write "My object is awesome" as main heading
parse_myobject(my_object) #This will return "<h1>My object is awesome</h1>"
#This is equivalent to above for custom objects(builtin objects can't be modified)
class MyObject:
def _repr_html_(self):
return '<h1>My object is awesome</h1>'
my_object = MyObject()
slides.write(my_object)
Note
_repr_html_
method which works as expected.Slides.alt(func, widget)
inside write
command for export purpose. Other commands such as Slides.[cols,rows,...]
will pick oldest value only.display
function automatically take care of serialized objects.Unregister all serializer handlers for a type.
Unregister all serializer handlers.
You can also extend markdown syntax using markdown extensions
, (See here and others to install, then use as below):
Clear all extensions and their configurations added by user.
Add configurations to the Markdown extensions. configs_dict is a dictionary like {'extension_name': config_dict}
Add list of extensions to the Markdown parser.
IPySlides Documentation
Z
key.zoom-self
, zoom-child
classes to an element. To prevent zooming under as zoom-child
class, use no-zoom
class.Z
key while mouse is over this part.IPySlides Documentation
Icons that apprear on buttons inslides (and their rotations) available to use in your slides as well besides standard ipywidgets icons.
import ipywidgets as ipw
btn = ipw.Button(description='Chevron-Down Icon',icon='chevrond')
self.write(btn)
Source code of this slide
with self.capture_content() as c:
with self.code.context():
import ipywidgets as ipw
btn = ipw.Button(description='Chevron-Down Icon',icon='chevrond')
self.write(btn)
self.write(['''
## SVG Icons
Icons that apprear on buttons inslides (and their rotations) available to use in your slides as well
besides standard ipywidgets icons.
''', *c.outputs, 'line`200`**Source code of this slide**',self.this.get_source()],
self.table([(f'`{k}`', self.icon(k,color='crimson').svg) for k in self.icon.available],headers=['Name','Icon']),
widths=[2,1])
Name
Icon
arrow
arrowb
arrowbd
arrowbl
arrowbr
arrowbu
arrowd
arrowl
arrowr
arrowu
bars
camera
chevron
chevrond
chevronl
chevronr
chevronu
circle
close
code
columns
compress
dots
edit
expand
info
laser
loading
pause
pencil
play
refresh
rows
search
settings
stop
win-maximize
win-restore
zoom-in
zoom-out
IPySlides Documentation
Use -1 as placeholder to update slide number automatically.
-1
.Slides.build_
instead of using -1
.IPySlides Documentation
def docs(self):
"Create presentation from docs of IPySlides."
self.close_view() # Close any previous view to speed up loading 10x faster on average
self.clear() # Clear previous content
self.create(range(24)) # Create slides faster
from ..core import Slides
self.set_citations({'A': 'Citation A', 'B': 'Citation B'}, mode = 'footnote')
self.settings.footer(text='IPySlides Documentation', date=None)
with self.build(0): # Title page
self.this.set_bg_image(self.get_logo(),0.25, filter='blur(10px)', contain=True)
self.write(f'## IPySlides {self.version} Documentation\n### Creating slides with IPySlides')
self.center(self.fmt('''
alert`Abdul Saboor`sup`1`
today``
{.text-small}
%{logo}
::: text-box
sup`1`My University is somewhere in the middle of nowhere
''', logo = self.get_logo("4em"))).display()
self.build(-1, self.fmt('''
section`Introduction`
```multicol .block-green
toc[True]`## Table of contents`
+++
### This is summary of current section
Oh we can use inline columns || Column A || Column B || here and what not!
%{btn}
```
```markdown
```multicol .block-green
toc[True]`## Table of contents`
+++
Extra content for current section which is on right
```
```''', btn = self.draw_button))
with self.build(-1):
self.write(['# Main App',self.doc(Slides), '### Jump between slides'])
self.doc(self.goto_button, 'Slides').display()
with self.build(-1):
self.write('## Adding Slides section`Adding Slides and Content`')
self.write('Besides function below, you can add slides with `%%slide number [-m]` magic as well.\n{.note .info}')
self.write([self.doc(self.build,'Slides'), self.doc(self.sync_with_file,'Slides')])
with self.build_():
self.write('''
## Important Methods on Slide
::: note-warning
Use slide handle or `Slides[number,]` to apply these methods becuase index can change on new builds.
''')
self.doc(self[0], members='yoffset set_animation set_bg_image update_display get_source show set_css'.split(), itself = False).display()
self.css_syntax.display()
with self.build(-1), self.code.context():
# self is in scope, auto picked, also fmt can be parsed on display
display(self.fmt('%{self.version!r} %{self.xmd_syntax}'))
with self.build(-1):
self.write('## Adding Content')
self.write('Besides functions below, you can add content to slides with `%%xmd`,`%xmd` as well.\n{.note .info}')
self.write([self.styled(self.doc(self.write,'Slides'),'block-green'), self.doc(self.parse,'Slides'),self.doc(self.clip,'Slides')])
with self.build(-1):
self.write('## Adding Speaker Notes')
(skipper := self.goto_button('Skip to Dynamic Content', icon='arrowr')).display()
self.write([rf'You can use alert`notes\`notes content\`` in markdown.\n{{.note .success}}\n',
'This is experimental feature, and may not work as expected.\n{.note-error .error}'])
self.doc(self.notes,'Slides.notes', members = True, itself = False).display()
with self.build(-1):
self.write('## Displaying Source Code')
self.doc(self.code,'Slides.code', members = True, itself = False).display()
self.build(-1, 'section`?Layout and color["yellow","black"]`Theme` Settings?` toc`### Contents`')
with self.build(-1) as s:
s.set_css({
'--bg1-color': 'linear-gradient(45deg, var(--bg3-color), var(--bg2-color), var(--bg3-color))',
'.highlight': {'background':'#8984'}
})
self.styled('## Layout and Theme Settings', 'info', border='1px solid red').display()
self.doc(self.settings,'Slides', members=True,itself = True).display()
with self.build(-1):
self.write('## Useful Functions for Rich Content section`?Useful Functions for alert`Rich Content`?`')
self.write("clip[caption='clipboard image']`test.png`", self.code.cast("clip[caption='clipboard image']`test.png`","markdown"))
self.doc(self.alt,'Slides')
self.doc(self.clip,'Slides').display()
members = sorted((
'AnimationSlider alert block bokeh2html bullets styled fmt color cols details doc '
'today error zoomable highlight html iframe image frozen notify plt2html '
'raw rows set_dir sig table textbox suppress_output suppress_stdout svg vspace'
).split())
self.doc(self, 'Slides', members = members, itself = False).display()
with self.build(-1):
self.write(r'''
## Citations and Sections
Use syntax alert`cite\`key\`` to add citations which should be already set by hl`Slides.set_citations(data, mode)` method.
Citations are written on suitable place according to given mode. Number of columns in citations are determined by
hl`Slides.settings.layout(..., ncol_refs = int)`. cite`A`
Add sections in slides to separate content by alert`section\`text\``. Corresponding table of contents
can be added with alert`toc\`title\``.
''')
self.doc(self, 'Slides', members = ['set_citations'], itself = False).display()
with self.build(-1):
skipper.set_target() # Set target for skip button
self.write('## Dynamic Content')
with self.capture_content() as cap, self.code.context():
import time
@self.ei.interact(auto_update=False, grid_css = dict({'.out-main': dict(height='2em')},background='var(--bg2-color)'), date = False) # self is Slides here
def update_time(date):
local_time = time.localtime()
objs = ['Time: {3}:{4}:{5}'.format(*local_time)] # Print time in HH:MM:SS format
if date:
objs.append('Date: {0}/{1}/{2}'.format(*local_time))
self.cols(*objs).display()
with self.code.context(returns=True) as c:
import datetime
@self.on_load # self is Slides here
def push_toast(slide):
t = datetime.datetime.now()
time = t.strftime('%H:%M:%S')
self.notify(f'Notification at {time} form slide {slide.index} and frame {slide.indexf}', timeout=5)
self.write(self.doc(self.ei.interact,'Slides.ei'), [*cap.outputs, c, self.doc(self.on_load,'Slides')])
with self.build(-1):
self.write('## Content Styling')
with self.code.context(returns = True) as c:
self.write(('You can **style**{.error} or **color["teal"]`colorize`** your *content*{: style="color:hotpink;"} and *color["hotpink","yellow"]`text`*. '
'Provide **CSS**{.info} for that using hl`Slides.html("style",...)` or use some of the available styles. '
'See these **styles**{.success} with `Slides.css_styles` property as below:'))
self.css_styles.display()
c.display()
s, *_ = self.build(-1, self.fmt('''
## Highlighting Code
[pygments](https://pygments.org/) is used for syntax highlighting cite`A`.
You can **highlight**{.error} code using `highlight` function cite`B` or within markdown using code blocks enclosed with three backticks:
```python
import ipyslides as isd
```
```javascript
import React, { Component } from "react";
```
**s is assigned variable to this slide**: %{s.source}
''', self=self))
with self.build(-1):
self.write('## Loading from File/Exporting to HTML section`Loading from File/Exporting to HTML`')
self.write('You can parse and view a markdown file. The output you can save by exporting notebook in other formats.\n{.note .info}')
self.write([self.doc(attr,'Slides') for attr in (self.sync_with_file,self.demo,self.docs,self.export_html)])
self.build(-1, 'section`Advanced Functionality` toc`### Contents`')
with self.build_() as s:
self.write("## Adding content on frames incrementally yoffset`0`")
self.frozen(widget := (code := s.get_source()).as_widget()).display()
self.fsep(stack=True) # frozen in above line get oldest metadata for export
def highlight_code(slide): widget.value = code.focus_lines(range(slide.indexf + 1)).value
self.on_load(highlight_code)
for ws, cols in self.fsep.iter(zip([None, (2,3),None], [(0,1),(2,3),(4,5,6,7)])):
cols = [self.html('h1', f"{c}",style="background:var(--bg3-color);margin-block:0.05em !important;") for c in cols]
self.write(*cols, widths=ws)
with self.build(-1) as s:
self.write('## Adding User defined Objects/Markdown Extensions')
self.write(
self.hold(display, self.html('h3','I will be on main slides',css_class='warning'),
metadata = {'text/html': '<h3 class="warning">I will be on exported slides</h3>'}
), # Can also do 'Slides.serilaizer.get_metadata(obj)' if registered
s.get_source(), widths = [1,3]
)
self.write('If you need to serialize your own or third party objects not serialized by this module, you can use `@Slides.serializer.register` to serialize them to html.\n{.note .info}')
self.doc(self.serializer,'Slides.serializer', members = True, itself = False).display()
self.write('**You can also extend markdown syntax** using `markdown extensions`, ([See here](https://python-markdown.github.io/extensions/) and others to install, then use as below):')
self.doc(self.extender,'Slides.extender', members = True, itself = False).display()
with self.build(-1):
self.write(r'''
## Focus on what matters
- There is a zoom button on top bar which enables zooming of certain elements. This can be toggled by `Z` key.
- Most of supported elements are zoomable by default like images, matplotlib, bokeh, PIL image, altair plotly, dataframe, etc.
- You can also enable zooming for an object/widget by wrapping it inside \`Slide.zoomable\` function conveniently.
- You can also enable by manully adding `zoom-self`, `zoom-child` classes to an element. To prevent zooming under as `zoom-child` class, use `no-zoom` class.
::: zoom-self block-red
### Focus on Me 😎
- If zoom button is enabled, you can hover here to zoom in this part!
- You can also zoom in this part by pressing `Z` key while mouse is over this part.
''')
with self.build(-1):
with self.capture_content() as c:
with self.code.context():
import ipywidgets as ipw
btn = ipw.Button(description='Chevron-Down Icon',icon='chevrond')
self.write(btn)
self.write(['''
## SVG Icons
Icons that apprear on buttons inslides (and their rotations) available to use in your slides as well
besides standard ipywidgets icons.
''', *c.outputs, 'line`200`**Source code of this slide**',self.this.get_source()],
self.table([(f'`{k}`', self.icon(k,color='crimson').svg) for k in self.icon.available],headers=['Name','Icon']),
widths=[2,1])
with self.build_():
self.write("""
# Auto Slide Numbering
Use alert`-1` as placeholder to update slide number automatically.
- In Jupyter notebook, this will be updated to current slide number.
- In python file, it stays same.
- You need to run cell twice if creating slides inside a for loop while using `-1`.
- Additionally, in python file, you can use `Slides.build_` instead of using `-1`.
""")
self.build(-1, lambda s: self.write(['## Presentation Code section`Presentation Code`',self.docs]))
self.navigate_to(0) # Go to title
return self
IPySlides Documentation