lua-resty-graphics-node

A version of MathJax adapted to TeX graphics

$ opm get sjnam/lua-resty-graphics-node

lua-resty-graphics-node

Just as MathJax makes it easier to use the tex math equations on a web page, lua-resty-graphics-node makes it easy to get the corresponding graphics with scripts such as metapost and graphviz on a web page.

Status

Experimental.

Installation

  • Prerequisites:

  • TeX Live, An easy way to get up and running with the TeX document production system

  • OpenResty, A full-fledged web platform that integrates the standard Nginx core, LuaJIT

  • lua-gumbo, A HTML5 parser and DOM library for Lua

  • sockexec, A small server for executing local processes

  • netstring.lua, An implementation of DJB's netstring encoding format for Lua/LuaJIT

  • lua-resty-exec, Run external programs in OpenResty without spawning a shell or blocking

  • Graphviz, Graph visualization is a way of representing structural information as diagrams of abstract graphs and networks.

  • 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
    $ sockexec /tmp/exec.sock &
    $ nginx -p `pwd`/ -c conf/nginx.conf
  • html/sample.html

        <html>
        <body>
        <mplibcode width="250">
        beginfig(1)
          pair A, B, C;
          A:=(0,0); B:=(1cm,0); C:=(0,1cm);
          draw A--B--C;
        endfig;
        </mplibcode>
        <hr>
        <graphviz cmd="dot" width="250">
        digraph G {
          main -> init;
          main -> cleanup;
        }
        </graphviz>
        </body>
        </html>
  • conf/nginx.conf

        worker_processes  1;
        error_log logs/error.log;
        events {
            worker_connections 1024;
        }
        http {
            server {
                listen 8080;
                include mime.types;
                location /sample {
                    default_type text/html;
                    content_by_lua_block {
                        require("resty.gxn"):render()
                    }
                }
            }
        }
  • 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

Authors

Soojin Nam

License

mit

Dependencies

Versions