There are some dependencies needed:
ruby (2.*.*)
imagemagik (6.*.*.*)
latex
-packagefile (5.*)
All you need to do is to run the following command (use curl
or wget
or your preferred network downloader):
sudo curl "https://gist.githubusercontent.com/MatteoRagni/c788528aa26feba6f9db/raw/415f09dc102a7dc053040f16ba14e507dbb536e0/EquationCreator.rb" > /usr/local/bin/EquationCreator.rb"
Now you are able to run the script from command line.
This script generates a series of image equations (gif
) starting from a yaml file that contains a simple template (standalone
).
Also resizes image canvas if needed (to display all images at the same size), that means image border are enlarged, but image content is not rescaled.
This is done to keep as simple as possible the use of final image on Github .
show this help
input YAML file is required. File must contains:
- template used to create latex final image (object $eq)
- configuration (definitions to be inserted in preamble)
- list of equations, that must contains:
- name for equation
- options (to be used in template, such as inline)
- data (contained equation)
directory in which image files will be saved (if directory does not exists, will be created).
size of the final image (width). The height will be collected automagically :) If "max", will use the maximum value of the images in output directory
This is an example of yaml
file:
---
configuration: |-
\usepackage{varwidth}
\usepackage{amsmath}
\def \xx {\mathbf{x}}
\def \activeset {\mathcal{A}}
\def \real {\mathbb{R}}
template: |-
\documentclass{standalone}
<%= $eq["configuration"] %>
\begin{document}
\begin{varwidth}{\linewidth}
<% if $eq["options"] =~ /nolabel/ %>$$<%= $eq["data"] %>$$<% else %>$$<%= $eq["data"] %>\hspace{3cm}(<%= $eq["label"] %>)$$<% end %>
\end{varwidth}
\end{document}
equations:
- name: eq_problem
options:
data: |-
\arraycolsep=1.4pt\def\arraystretch{2}
\begin{array}{rcl}
\xx & = & \mathrm{arg}~\underset{\xx}{\mathrm{min}} ~ \dfrac{1}{2} \xx^{T} M \xx + \mathbf{g}^{T}\xx + c \\
\mathrm{subject~to} & & \mathbf{a}^{T}_{j} \xx + b_j = 0 \qquad j \in \left\{1 \dots m\right\} \\
& & \mathbf{a}^{T}_{j} \xx + b_j \geq 0 \qquad j \in \left\{m+1 \dots r\right\} \quad m > r \\
\end{array}
- name: eq_activeset
options:
data: |-
\activeset(\mathbf{z}) = \left\{ 1 \dots m \right\} \cup \left\{ j \in \left\{ m+1 \dots r \right\} ~|~ \mathbf{a}^{T}_{j} \mathbf{z} + b_j = 0 \right\}
Generates with the options:
EquationCreator.rb -i example.yaml -o . -r max
The two images:
eq_problem.gif
eq_activeset.gif