Beautiful graphics in all browsers
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib/resty
README.md
dist.ini

README.md

GraphicsNode

Just as MathJax makes it easier to use the tex math equations on a web page, GraphicsNode makes it easy to get the corresponding graphics with scripts such as metapost, graphviz on tikz on a web page.

Status

Experimental.

Installation

  • Prerequisites:

    • TeX Live, An easy way to get up and running with the TeX document production system
    • Graphviz, Graph visualization is a way of representing structural information as diagrams of abstract graphs and networks.
    • OpenResty, A full-fledged web platform that integrates the standard Nginx core, LuaJIT
    • lua-gumbo, A HTML5 parser and DOM library for Lua
    • lua-resty-requests, Yet Another HTTP library for OpenResty
  • Place lib/resty to your lua library path.

Getting Started

$ export PATH=/usr/local/openresty/nginx/sbin:$PATH
$ mkdir ~/www
$ cd ~/www
$ mkdir -p conf logs util html/images
$ nginx -p `pwd`/ -c conf/nginx.conf
  • html/sample.html
<html>
<body>

<hr>
<mplibcode>
beginfig(1)
  pair A, B, C;
  A:=(0,0); B:=(1cm,0); C:=(0,1cm);
  draw A--B--C;
endfig;
</mplibcode>

<hr>
<mplibcode src="/source/triangle.mp" width="300"></mplibcode>

<hr>
<mplibcode src="http://www.cs.ucc.ie/~dongen/mpost/mp/Escher87.mp"></mplibcode>

</body>
</html>
  • conf/nginx.conf
worker_processes 1;
error_log logs/error.log;
events {
    worker_connections 1024;
}
http {
    lua_shared_dict gxn_cache 10m;
    
    server {
        listen 8080;
        
        resolver 8.8.8.8;
        include mime.types;
        
        location /sample {
            default_type text/html;
            content_by_lua_block {
                require("resty.gxn")()
            }
        }
    }
}
  • util/gxn.sh
#!/bin/bash

cd $1

ERROR=0

case $2 in
    mplibcode)
        $5 $3
        ERROR=$?
        ;;
    graphviz)
        $5 -Tsvg $3.gv -o $3.$4
        ERROR=$?
        ;;
    *)
        echo 'NOT SUPPORTED'
esac

rm -rf *.mp *.mpx *.gv

exit $ERROR

Copyright (C) 2018-2019 Soojin Nam