From 29890ac3a5608ad86d99b3361350a9dc3e69ac2f Mon Sep 17 00:00:00 2001 From: Werner LEMBERG Date: Sun, 7 Jul 2002 22:14:56 +0000 Subject: [PATCH] import from Eric's sources --- contrib/eqn2graph/.cvsignore | 2 + contrib/eqn2graph/Makefile.sub | 19 +++++++++ contrib/eqn2graph/eqn2graph.man | 87 +++++++++++++++++++++++++++++++++++++++++ contrib/eqn2graph/eqn2graph.sh | 63 +++++++++++++++++++++++++++++ 4 files changed, 171 insertions(+) create mode 100644 contrib/eqn2graph/.cvsignore create mode 100644 contrib/eqn2graph/Makefile.sub create mode 100644 contrib/eqn2graph/eqn2graph.man create mode 100644 contrib/eqn2graph/eqn2graph.sh diff --git a/contrib/eqn2graph/.cvsignore b/contrib/eqn2graph/.cvsignore new file mode 100644 index 00000000..4ec677a1 --- /dev/null +++ b/contrib/eqn2graph/.cvsignore @@ -0,0 +1,2 @@ +eqn2graph +eqn2graph.n diff --git a/contrib/eqn2graph/Makefile.sub b/contrib/eqn2graph/Makefile.sub new file mode 100644 index 00000000..6ccdd982 --- /dev/null +++ b/contrib/eqn2graph/Makefile.sub @@ -0,0 +1,19 @@ +MAN1=eqn2graph.n +CLEANADD=eqn2graph + +all: eqn2graph + +eqn2graph: eqn2graph.sh + rm -f $@; \ + sed -e "s|@g@|$(g)|g" \ + -e "s|@VERSION@|$(version)$(revision)|" \ + -e $(SH_SCRIPT_SED_CMD) $(srcdir)/eqn2graph.sh >$@; \ + chmod +x $@ + +install_data: eqn2graph + -test -d $(bindir) || $(mkinstalldirs) $(bindir) + -rm -f $(bindir)/eqn2graph + $(INSTALL_SCRIPT) eqn2graph $(bindir)/eqn2graph + +uninstall_sub: + -rm -f $(bindir)/eqn2graph diff --git a/contrib/eqn2graph/eqn2graph.man b/contrib/eqn2graph/eqn2graph.man new file mode 100644 index 00000000..9a4f5ce9 --- /dev/null +++ b/contrib/eqn2graph/eqn2graph.man @@ -0,0 +1,87 @@ +.\" $Id$ +.\" This documentation is released to the public domain. +.TH EQN2GRAPH @MAN1EXT@ "@MDATE@" "Groff Version @VERSION@" +.IX eqn2graph +.SH NAME +eqn2graph \- convert an EQN equation into a cropped image +. +. +.SH SYNOPSIS +.B eqn2graph +[ +.B \-unsafe +] +[ +.BI \-format\ fmt +] +. +. +.SH DESCRIPTION +Reads an EQN equation (one line) as input; produces an image +file (by default in Portable Network Graphics format) suitable for the +Web as output. +.P +Your input EQN code should \fInot\fR have the .EQ/.EN preamble that +that normally precedes it within +.BR groff (@MAN1EXT@) +macros; nor do you need to have dollar-sign or other delimiters +around the equation. +.P +The output image will be a black-on-white graphic clipped to the +smallest possible bounding box that contains all the black pixels. +By specifying command-line options to be passed to +.BR convert (1) +you can give it a border, set the background transparent, set the +image's pixel density, or perform other useful transformations. +.P +This program uses +.BR @g@eqn (@MAN1EXT@), +.BR groff (@MAN1EXT@), +and the ImageMagick +.BR convert (1) +program. +These programs must be installed on your system and accessible on your +$PATH for \fBeqn2graph\fR to work. +. +. +.SH OPTIONS +.TP +.B \-unsafe +Run +.BR groff (@MAN1EXT@) +in the `unsafe' mode enabling the PIC macro +.B sh +to execute arbitrary commands. +The default is to forbid this. +.TP +.BI \-format\ fmt +Specify an output format; the default is PNG (Portable Network Graphics). +Any format that +.BR convert (1) +can emit is supported. +.PP +Command-line switches and arguments not listed above are passed to +.BR convert (1). +. +. +.SH FILES +.Tp \w'\fB@MACRODIR@/eqnrc'u+2n +.B @MACRODIR@/eqnrc +The +.BR @g@eqn (@MAN1EXT@) +initialization file. +. +. +.SH "SEE ALSO" +.BR @g@eqn (@MAN1EXT@), +.BR groff (@MAN1EXT@), +.BR gs (1), +.BR convert (1). +. +. +.SH AUTHOR +Eric S. Raymond . +. +.\" Local Variables: +.\" mode: nroff +.\" End: diff --git a/contrib/eqn2graph/eqn2graph.sh b/contrib/eqn2graph/eqn2graph.sh new file mode 100644 index 00000000..312f0bc0 --- /dev/null +++ b/contrib/eqn2graph/eqn2graph.sh @@ -0,0 +1,63 @@ +#!/bin/sh +# +# eqn2graph -- compile EQN equation descriptions to bitmap images +# +# by Eric S. Raymond , July 2002 +# +# In Unixland, the magic is in knowing what to string together... +# +# Take an eqn equation on stdin, emit cropped bitmap on stdout. +# The pic markup should *not* be wrapped in .EQ/.EN, this script will do that. +# A -U option on the command line enables gpic/groff "unsafe" mode. +# All other options are passed to convert (or whichever back end is selected +# by the format option). The default format is PNG. +# +# This is separate from pic2graph because pic processing has some weird +# clipping effect on the output, mangling equations that are very wide +# or deep. Besides, this rool can supply its own delimiters. +# + +# Requires the groff suite and the ImageMagick tools. Both are open source. +# This code is released to the public domain. +# +# Here are the assumptions behind the option processing: +# +# 1. None of the options of eqn(1) are relevant. +# +# 2. Only the -U option of groff(1) is relevant. +# +# 3. Many options of convert(1) are potentially relevant, (especially +# -density, -interlace, -transparency, -border, and -comment). +# +# Thus, we pass -U to groff(1), and everything else to convert(1). +# +# $Id$ +# +groff_opts="" +convert_opts="" +format="png" + +while [ "$1" ] +do + case $1 in + -unsafe) groff_opts="-U";; + -format) format=$2; shift;; + *) convert_opts="$convert_opts $1" ;; + esac + shift; +done + +# Here goes: +# 1. Add .EQ/.EN. +# 2. Process through eqn(1) to emit troff markup. +# 3. Process through groff(1) to emit Postscript. +# 4. Use convert(1) to crop the Postscript and turn it into a bitmap. +tmp=/usr/tmp/eqn2graph-$$ +trap "rm ${tmp}.*" 0 2 15 +read equation +(echo ".EQ"; echo 'delim $$'; echo ".EN"; echo '$'"${equation}"'$') | \ + groff -e $groff_opts -Tps >${tmp}.ps \ + && convert -crop 0x0 $convert_opts ${tmp}.ps ${tmp}.${format} \ + && cat ${tmp}.${format} + +# End -- 2.11.4.GIT