Sharedsupport / 2015-12-12-151702-latex-partitions.sagewsOpen in CoCalc
Examples for support purposes...
{\def\lr#1{\multicolumn{1}{|@{\hspace{.6ex}}[email protected]{\hspace{.6ex}}|}{\raisebox{-.3ex}{$#1$}}} \raisebox{-.6ex}{$\begin{array}[b]{*{2}c}\cline{1-2} \lr{\phantom{x}}&\lr{\phantom{x}}\\\cline{1-2} \lr{\phantom{x}}&\lr{\phantom{x}}\\\cline{1-2} \lr{\phantom{x}}\\\cline{1-1} \end{array}$} }
'\\raisebox' in str(latex(Partition([2,2,1])))
   File: /projects/sage/sage-6.9/local/lib/python2.7/site-packages/smc_sagews/
   def show(*objs, **kwds):
    Show a 2d or 3d graphics object (or objects), animation, or matplotlib figure, or show an
    expression typeset nicely using LaTeX.

       - display: (default: True); if True, use display math for expression (big and centered).

       - svg: (default: True); if True, show 2d plots using svg (otherwise use png)

       - d3: (default: True); if True, show graphs (vertices and edges) using an interactive D3 viewer
           for the many options for this viewer, type 'import graphics; graphics.graph_to_d3_jsonable?'
         If false, graphs are converted to plots and displayed as usual.

       - renderer: (default: 'webgl'); for 3d graphics
           - 'webgl' (fastest) using hardware accelerated 3d;
           - 'canvas' (slower) using a 2d canvas, but may work better with transparency;
           - 'tachyon' -- a ray traced static image.

       - spin: (default: False); spins 3d plot, with number determining speed (requires mouse over plot)

       - events: if given, {'click':foo, 'mousemove':bar}; each time the user clicks,
         the function foo is called with a 2-tuple (x,y) where they clicked.  Similarly
         for mousemove.  This works for Sage 2d graphics and matplotlib figures.


       - animations are by default encoded and displayed using an efficiently web-friendly
         format (currently webm, which is **not supported** by Safari or IE).

            - ``delay`` - integer (default: 20); delay in hundredths of a
              second between frames.

            - gif=False -- if you set gif=True, instead use an animated gif,
              which is much less efficient, but works on all browsers.

         You can also use options directly to the animate command, e.g., the figsize option below:

              a = animate([plot(sin(x + a), (x, 0, 2*pi)) for a in [0, pi/4, .., 2*pi]], figsize=6)
              show(a, delay=30)


    Some examples:

        show([1, 4/5, pi^2 + e], 1+pi)
        show(x^2, display=False)
        show(e, plot(sin))

    Here's an example that illustrates creating a clickable image with events::

        def f0(fun=x*sin(x^2), mousemove='', click='(0,0)'):
            click = sage_eval(click)
            g = plot(fun, (x,0,5), zorder=0) + point(click, color='red', pointsize=100, zorder=10)
            ymax = g.ymax(); ymin = g.ymin()
            m = fun.derivative(x)(x=click[0])
            b =  fun(x=click[0]) - m*click[0]
            g += plot(m*x + b, (click[0]-1,click[0]+1), color='red', zorder=10)
            def h(p):
                f0.mousemove = p
            def c(p):
            show(g, events={'click':c, 'mousemove':h}, svg=True, gridlines='major', ymin=ymin, ymax=ymax)
    # svg=True, d3=True,
    svg = kwds.get('svg',True)
    d3 = kwds.get('d3',True)
    display = kwds.get('display', True)
    for t in ['svg', 'd3', 'display']:
        if t in kwds:
            del kwds[t]
    import graphics
    def show0(obj, combine_all=False):
        # Either show the object and return None or
        # return a string of html to represent obj.
        if isinstance(obj, (Graphics, GraphicsArray, matplotlib.figure.Figure, matplotlib.axes.Axes, matplotlib.image.AxesImage)):
            show_2d_plot_using_matplotlib(obj, svg=svg, **kwds)
        elif isinstance(obj, Animation):
            show_animation(obj, **kwds)
        elif isinstance(obj, Graphics3d):
            if kwds.get('viewer') == 'tachyon':
                show_3d_plot_using_tachyon(obj, **kwds)
                salvus.threed(obj, **kwds)
                # graphics.show_3d_plot_using_threejs(obj, **kwds)
        elif isinstance(obj, (sage.graphs.graph.Graph, sage.graphs.digraph.DiGraph)):
            if d3:
                show_graph_using_d3(obj, **kwds)
                show(obj.plot(), **kwds)
        elif isinstance(obj, str):
            return obj
        elif isinstance(obj, (list, tuple)):
            v = []
            for a in obj:
                b = show0(a)
                if b is not None:
            if combine_all:
                return ' '.join(v)
            s = ', '.join(v)
            if isinstance(obj, list):
                return '[%s]'%s
                return '(%s)'%s
            s = str(sage.misc.latex.latex(obj))
            if '\\begin{tikzpicture}' in s:
                # special case -- mathjax has no support for tikz so we just immediately display it (as a png); this is
                # better than nothing.
                return ''
            elif display:
                return "$\\displaystyle %s$"%s
                return "$%s$"%s
    s = show0(objs, combine_all=True)
    if s is not None:
        if display:
            salvus.html("<div align='center'>%s</div>"%cgi.escape(s))