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.
%% javascript
element.append('foo')
#% javascript
for (var i=0;i<4;i++) {
element.append(i)
}
To generate output of type latex, use the #% latex
magic.
#% latex
my $x = '\begin{equation*} \frac{1}{2} \end{equation*}';
$x
%% latex(equation)
'\frac{1}{2}'
#% latex(equation) > html
say '½';
'\frac{1}{2}';
Rat.^find_method($_)
.wrap( sub ($x) {
'\frac{' ~ $x.numerator ~ '}{' ~ $x.denominator ~ '}'
} ) for <gist Str>;
(Routine::WrapHandle.new Routine::WrapHandle.new)
%% latex(equation)
"{0.2} + {0.9} - {0.1}"
%% latex(equation)
my $x = 2/3;
my $y = 1/8;
"$x + $y == { $x + $y }"