This section documents the LaTeX package sysquake.sty. This package permits to embed in LaTeX source files (.tex suffix) fragments of code written in LME, the programming language of Sysquake. All these fragments are evaluated successively in the same context: definitions and variables can be reused across multiple fragments.
The package is imported in the main LaTeX source file with \usepackage:
\usepackage{sysquake}
Several options can be specified in a comma-separated list in square brackets; for example
\usepackage[latexingraphics,noseparatelogfile]{sysquake}
Here is a list of all supported options.
Additional options with arguments can be set with special LaTeX commands:
Package sysquake.sty depends on other packages for some tasks. You should also import them with \usepackage if necessary.
The preamble of an article which needs all these packages could be as follows. There is no harm in importing superfluous packages.
\documentclass{article} \usepackage[latexingraphics,noseparatelogfile]{sysquake} \usepackage{graphicx} \usepackage{epstopdf} \usepackage{hyperref} \usepackage{listings} \begin{document} ... \end{document}
Any text output produced by code fragments is inserted in the LaTeX source code. It is subject to further evaluation by LaTeX.
\sqeval{code} evaluates code fragment code, which is processed as LaTeX code before being evaluated by Sysquake for LaTeX; hence characters aimed at Sysquake which have a meaning in LaTeX, such as \ and $, must be escaped.
Simple value:
The result is \sqeval{disp(1+2);}.
Passing a LaTeX counter:
\newcounter{n} \setcounter{n}{10} The square root of \arabic{n} is \sqeval{disp(sqrt(\arabic{n}));}.
\sqexpr{expr} evaluates expression expr, formats it for LaTeX and inserts it in the result. The expression should not be terminated by a semicolon or comma.
Currently, the following types are supported: real or complex double, scalar or 2-dim arrays, and strings. Options set by format are used; scientific notation is displayed with the mathematical notation (a multiplication by 10 to some integer power) instead of the classic computer notation.
\sqexpr can be used in text as well as in math mode. It is a fragile command; to use it in a moving argument, such as the argument of \caption, put \protect right before it.
Scalar value in an equation:
Some small number: $\frac{\pi}{e^{10}} = \sqexpr{pi/exp(10)}$.
Magic square of size 5:
\[ M_5 = \sqexpr{magic(5)} \]
Fragile command:
\caption{Simulation with $\alpha=\protect\sqexpr{2*3.9}$}
Text in the sysquake environment is interpreted verbatim as LME code. All LaTeX constructs are ignored, except for the terminating string \end{sysquake}. Standard output produced by functions like disp and fprintf is inserted in the output, where it is processed by LaTeX.
Remark: the sysquake environment uses the verbatim package. In the beamer class, the [fragile] option should be added to frames where it is used. See below for an example.
In the fragment below, the eigenvalues of a magic square are computed and displayed in a loop. Function fprintf is used to display symbols with and sqlxvalue to format the numbers.
$R$'s eigenvalues $\lambda_i$ are \begin{sysquake} R = magic(3); lambda = eig(R); for i = 1:length(lambda) fprintf('\\[ \\lambda_%d = %s \\]\n', i, sqlxvalue(lambda(i))); end \end{sysquake}
\begin{sysquake}(w,h) starts an environment where sysquake code is evaluated, like \begin{sysquake}. In addition, an EPS file with width w and height h is created with all the output produced by graphical commands the code fragment contains. This EPS is inserted in the LaTeX document in a picture environment with the \includegraphics command of package graphicx.
The fragment below defines a floating figure with the step response of the transfer function 1/(s^3+2s^2+3s+4). We assume the latexingraphics option of the sysquake package, so that text is processed by LaTeX (see above).
\begin{figure} \begin{center} \begin{sysquake}(300,200) step(1, [1,2,3,4]); label('$t$','$\\psi$'); legend('$\\psi(t)=\\int_0^\\infty g(\\tau)s(t-\\tau){\\rm d}\\tau$'); \end{sysquake} \caption{Step response} \end{center} \end{figure}
Here is an example of a plot in a document with class beamer. Note the use of the option [fragile] required by the frame environment.
\documentclass{beamer} \usepackage[latexingraphics]{sysquake} \usepackage{graphicx} \usepackage{epstopdf} \begin{document} \begin{frame}[fragile] \frametitle{Graphics} \begin{sysquake}(280,200) fplot(@(x) (x+0.3)^2+7.2*exp(-3*x^2), [-2,3], 'r'); \end{sysquake} \end{frame} \end{document}