The blog of a juvenile Geekus biologicus

Math

How to render LaTeX formula in Pelican

Rendering $\LaTeX$ formulas in Pelican is easy.

Firstly import the pelican plugin in the proper python environment:

pip install pelican-render-math

Add render_math to PLUGINS list in your pelicanconf.py file:

PLUGINS = ['render_math']

Then type formula in your blog post markdown documents:

$$
\frac{1}{2}
$$
$$ \frac{1}{2} $$

And that’s it !

Draw a Plot in C with GNU plotutils

Install plotutils

Debian

$ sudo apt-get install plotutils-dev

Fedora

$ sudo dnf install plotutils-devel

Use PlotUtils to plot a graph

Let us draw the $sin(x)$ function using math library.

#include <stdio.h>
#include <math.h>

#define RANGE 100

// Export data to stdout
void plot(double *x, double *y, size_t len)
{
    for (unsigned int i = 0; i < len; i++)
        printf("%lf %lf\n", x[i], y[i]);
}

int main(void)
{
    int i;
    double x[RANGE], y[RANGE];
    // Compute sin(x)
    for (i = 0; i < RANGE; i++)
    {
        x[i] = i * 0.1;
        y[i] = sin(x[i]);
    }

    plot(x, y, 100);

    return 0;
}
$ gcc -o plot plot.c -lm
$ ./plot # Show data on screen

Use graph utility to plot the data

$ ./plot | graph -T X -T PNG -L "sin(x)" > output.png