~yoctocell/gralc

Groff preprocessor for doing arithmetic in python
README: Update installation instructions
README: Update installation with flakes
Fix formatting

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~yoctocell/gralc
read/write
git@git.sr.ht:~yoctocell/gralc

You can also use your local clone with git send-email.

#Gralc

A preprocessor for Groff/Troff that lets you do arithmetic in Python.

#Installation

Download the src/gralc.py file and put it in your $PATH.

#Nix-build

Change directory to the root of the project and run nix-build to install gralc in ./result/bin/gralc.py.

#Nix Flakes

If you have nix flakes enabled, you can run nix shell git+https://git.sr.ht/~yoctocell/nixrc#gralc.

#Usage

To perform arithmetic, write your expression between `\P`` and ``` (variables aren't supported tho).

three plus three is \P`3+3`.

You can define a base value in roff like this.

.nr base 400

Then use the base value to compute something.

Sugar \P`base*0.4` ml

Very useful for writing recipes.

Compile the document by calling gralc <filename>.

$ gralc demo.me | groff -me -Tpdf > demo.pdf

Or pipe the output of another command into gralc.py.

$ eqn demo.me | gralc.py | ...

See test/demo.mm for a simple demo.

#Configuration

Because gralc is written in Python, it can read a configuration file where you can write your own Python code.

It will read your $XDG_CONFIG_HOME/gralc/config.py file, or ~/.config/gralc/config.py as a fallback.

In you config file:

from math import *
from random import *

Then in your groff file:

Extra cool random spicy number \P`random() * sin(pi)`