# Beampy API¶

Warning

## Core¶

Beampy main file

class beampy.document(quiet=False, latex_packages=None, source_filename=None, **kwargs)

Main function to define the document style etc…

dict_deep_update(original, update)

Recursively update a dict. Subdict’s won’t be overwritten but also updated. from http://stackoverflow.com/questions/38987/how-can-i-merge-two-python-dictionaries-in-a-single-expression/44512#44512

classmethod print_variables()

Print information on the document class and the content of its private data and methods.

class beampy.beampy_module(**kargs)

Base class for creating a module

Each module need a render method and need to return a register

above(other_element)

Set the current module to appears above the other_element_id.

add_border(svg_style={‘stroke’: ‘red’, ’stroke-width’: 0.5, ’fill’: ‘none’})

function to add a border to the given element

add_layers(layerslist)

Function to add this elements to given layers :param layerslist: list of layers where the module should be printed :return:

add_svgdef(svgdef, svgdefsargs=None)

Function to add svg clipPath or filter.

svgdef: string,
The svg syntax to add to <defs> environnement. This svg syntax could include arguments as python string format replacement (like ‘{width}’) that will be replaced by their value (store as instance of the class, like self.width for ‘{width}’) when render is executed.
svgdefargs: list of string optional
The list of arguments as string to format in the svgdef.
below(other_element)

Set the current module to appears beow the othe_element

check_args_from_theme(arg_values_dict, parent=None)

Function to check input function keyword args.

Functions args are defined in the default_theme.py or if a theme is added the new value is taken rather than the default one

Parameters: arg_values_dict (dictionary,) – The key-value dictionary containing function arguments. parent (string optional) – The name of the parent beampy_module to also load args
export_svg()

function to export rendered svg in a group positionned in the slide

export_svg_def()

function to export rendered svg in a group positionned in the slide

first()

Set the current object in the background

last()

Set the current object in the foreground

load_args(kwargs_dict)

Function to transform input kwargs dict into attribute of the module

load_extra_args(theme_key)

Function to load default args from the theme for the given theme_key and add them to the module

load_special_kwargs()

Load all attributes contained in self.sepcial_kwargs dictionnary as attributes of the beampy_module with the setattr function.

pre_render()

A method that is called at the begining of the slide.newrender method

process_with()

Function called by the __exit__ function

Need to be redefined by each module to adjust the behaviours of “with :”

render_svgdefs()

Function to render the svgdefs

run_render()

Run the function self.render if the module is not in cache

update_size(width, height)

Update the size (width, height) of the current module

class beampy.positionner(x, y, width, height, elem_id, slideid)
compute_anchors()

Compute the anchors for the element self.left self.right self.top and self.bottom

guess_size_for_group()

Function to guess parent group final position to place elements relatively to this group.

place(available_size, ytop=0)

Method to place the given element. This method is used by renders.py in the place_content function

available_size: (width, heith) is the page or group width and height

ytop[default 0]: is the y offset (used to center verticaly taking into
account the title)
update_size(width, height)

Update width and height to computed ones by the element render.

If width is less than 1px, use it as a percentage of the width

update_x(x)

Update the x position and run the converter

update_y(y)

Update the y position and run the converter

class beampy.group(elements_to_group=None, x=’center’, y=’auto’, width=None, height=None, background=None, parentid=None, parent_slide_id=None, opengroup=True)

Group Beampy modules together and manipulate them as a group

Parameters: elements_to_group (None or list of beampy.base_module, optional) – List of Beampy module to put inside the group (the default is None). This argument allows to group Beampy modules, when group is not used with the python with expression. x (int or float or {'center', 'auto'} or str, optional) – Horizontal position for the group (the default is ‘center’). See positioning system of Beampy. y (int or float or {'center', 'auto'} or str, optional) – Vertical position for the group (the default is ‘auto’). See positioning system of Beampy. width (int or float or None, optional) – Width of the group (the default is None, which implies that the width is computed to fit the group contents width). height (int or float or None, optional) – Height of the group (the default is None). When height is None the height is computed to fit the group contents height. background (str or None, optional) – Svg color name of the background color for the group (the default is None). perentid (str or None, optional) – Beampy id of the parent group (the default is None). This parentid is given automatically by Beampy render.

Note

When the position of a group (x, y) are relative to a parent group and that the parent group has width=None or height=None and positions x or y equal to ‘auto’ or ‘center’, the render will use the slide.curwidth as width and the document._height as height. This will produce unexpected positioning of child group.

compute_group_size()

Function to compute the size of a given group

Update the size with self.update_size(width, height) at the end

export_svg_content_layer(layer)

Function to export group content for a given layer to svg :param layer: :return:

propagate_layers()

Function to recusivly propagate the layers to group elements :return:

remove_element_in_group(elementid)

Function to remove element from the group key stores

Parameters: elementid – The id of the module to remove
render()

group render

reset_outputs()

Rewrite the reset_outputs function of beampy_module to add content_layer.

## Beampy Modules¶

class beampy.figure(content, ext=None, **kwargs)

Include a figure to the current slide. Figure formats could be (svg, pdf, png, jpeg, gif, matplotib figure, and bokeh figure)

Parameters: content (str or matplotlib.figure or bokeh.figure) – Figure input source. To load file, content is the path to the file. For matplotlib and bokeh, content is the python object figure of either matplotlib or bokeh. ext ({'svg','jpeg','png','pdf', 'gif', 'bokeh','matplotlib'} or None, optional) – Image format defined as string (the default value is None, which implies that the image format is guessed from file or python object name. x (int or float or {'center', 'auto'} or str, optional) – Horizontal position for the figure (the default is ‘center’). y (int or float or {'center', 'auto'} or str, optional) – Vertical position for the figure (the default is ‘auto’, which implies equal blank width between ‘auto’ positioned elements) width (int or float or None, optional) – Width of the figure (the default is None, which implies that the width is width of the image).
render()

function to render figures

class beampy.text(textin=None, **kwargs)

Add text to the current slide. Input text is by default processed using Latex and could use Latex syntax.

Parameters: textin (str, optional) – Text to add. Could contain latex syntax with protected slash either by using double slash or by using the python r before string. >>> text(r’\sqrt{x}’)  x (int or float or {'center', 'auto'} or str, optional) – Horizontal position for the text container (the default is ‘center’). See positioning system of Beampy. y (int or float or {'center', 'auto'} or str, optional) – Vertical position for the text container (the default is ‘auto’). See positioning system of Beampy. width (int or float or None, optional) – Width of the text container (the default is None, which implies that the width is the parent group with). size (int, optional) – The font size (the default theme sets this value to 20). font (str, optional) – The Tex font (the default theme sets this value to ‘CMR’). THIS IS NOT YET IMPLEMENTED! color (str, optional) – The text color (the default theme set this value to ‘#000000’). Color could be html hex values or SVG-COLOR-NAMES. usetex (bool, optional) – Use latex to render text (the default value is true). Latex render could be turned off using usetex=False, then the text is rendered as svg. va ({'','baseline'}, optional) – Vertical text alignment (the default value is ‘’, which implies that the alignment reference is the top-left corner of text). When va=’baseline’, the base-line of the first text row is computed and used as alignment reference (baseline-left). extra_packages (list of string, optional) – Add latex packages to render the text, like [r’usepackage{name1}’, r’usepackage{name2}’]

Example

>>> text('this is my text', x='20', y='20')

local_render()

Function to render only on text of this module.

It’s slower than writing all texts to one latex file and then render it to dvi then svg.

parse_dvisvgm_svg(soup_data)

Function to transform the svg produced by dvisvgm. Make a global glyph store to use them as defs in svg to reduce the size off the global presentation.

soup_data: BeautifulSoup parsed svg

return: soup_data (without the defs part)

pre_render()

Prepare the latex render of the text

process_with()

Process the text inside the width

render()

Text is rendered using latex if self.usetex = True if not use simple svg

class beampy.video(videofile, **kwargs)

Include a figure to the current slide. Figure formats could be (svg, pdf, png, jpeg, matplotib figure, and bokeh figure)

Parameters: content (str or matplotlib.figure or bokeh.figure) – Figure input source. To load file, content is the path to the file. For matplotlib and bokeh, content is the python object figure of either matplotlib or bokeh. ext ({'svg','jpeg','png','pdf','bokeh','matplotlib'} or None, optional) – Image format defined as string (the default value is None, which implies that the image format is guessed from file or python object name. x (int or float or {'center', 'auto'} or str, optional) – Horizontal position for the figure (the default is ‘center’). y (int or float or {'center', 'auto'} or str, optional) – Vertical position for the figure (the default is ‘auto’, which implies equal blank width between ‘auto’ positioned elements) width (int or float or None, optional) – Width of the figure (the default is None, which implies that the width is width of the image).
render()

Render video (webm) encoded in base64 in svg command

Render Need to produce an html and an svg

video_image()

Function used to get the first image of a video

It use FFMPEG to extract one image

class beampy.tikz(tikzcmd, **kwargs)

Add Tikz/pgf graphic to the slide.

Parameters: tikzcmd (string) – String containing the main Tikz commands contained between begin{tikzpicture} and end{}tikzpicture}. x (int or float or {'center', 'auto'} or str, optional) – Horizontal position for the Tikz graphic (the default theme set this to 0). See positioning system of Beampy. y (int or float or {'center', 'auto'} or str, optional) – Vertical position for the Tikz graphic (the default theme sets this to 0). See positioning system of Beampy. tikz_header (str or None, optional) – Add extra Tiks/pgf libraries and style (Tiks commands usetikzlibrary and tickstyle), everything that is included before begin{document} (the default theme sets this to None). tex_packages (list of string or None, optional) – Add extra Tex packages that are included using the usepackages (the default theme sets this to None). The list should only contains the name of tex packages as strings. >>> tex_packages = [‘xolors’,’tikz-3dplot’]  latex_pre_tikzpicture (str or None, optional) – Add extra latex commands that will be added between begin{document} and begin{tikzpicture} (the default theme sets this to None) >>> latex_pre_tikzpicture = r’\newcounter{mycounter}\setcounter{mycounter}{10}’  figure_options (string or None,) – Tikz options added just after: begin{tikzpicture}[options] (the default theme sets this to None). figure_anchor ({'top_left' or 'top_right' or 'bottom_left' or 'bottom_right' }, optional) – Anchor of the svg produced by Tikz.
render()

Latex -> dvi -> svg for tikz image

class beampy.svg(svg_content, **kwargs)

Insert svg content.

Parameters: svg_content (string) – Svg elements to add written in svg syntax without svg document tag “
render()

The render of an svg part