This notebook has examples of using magics.

If the first line of a cell starts with %% or #%, the kernel treats it as a "magic". javascript will just send the contents as javascript to the browser. In this context, you can use element to manipulate the output area.

In [1]:
%% javascript
element.append('foo')
In [2]:
#% javascript
for (var i=0;i<4;i++) {
  element.append(i)
}

To generate output of type latex, use the #% latex magic.

In [3]:
#% latex
my $x = '\begin{equation*} \frac{1}{2} \end{equation*}';
$x
Out[3]:
\begin{equation*} \frac{1}{2} \end{equation*}
In [4]:
%% latex(equation)
'\frac{1}{2}'
Out[4]:
\begin{equation} \frac{1}{2} \end{equation}
In [5]:
#% latex(equation) > html
say '&frac12;';
'\frac{1}{2}';
½
Out[5]:
\begin{equation} \frac{1}{2} \end{equation}
In [6]:
Rat.^find_method($_)
    .wrap( sub ($x) {
        '\frac{' ~ $x.numerator ~ '}{' ~ $x.denominator ~ '}'
    } ) for <gist Str>;
Out[6]:
(Routine::WrapHandle.new Routine::WrapHandle.new)
In [7]:
%% latex(equation)
"{0.2} + {0.9} - {0.1}"
Out[7]:
\begin{equation} \frac{1}{5} + \frac{9}{10} - \frac{1}{10} \end{equation}
In [8]:
%% latex(equation)
my $x = 2/3;
my $y = 1/8;
"$x + $y == { $x + $y }"
Out[8]:
\begin{equation} \frac{2}{3} + \frac{1}{8} == \frac{19}{24} \end{equation}