#!/bin/sh
SRC=T$2
TMP=$SRC.lout
TARGET=`basename $2 .lout`.eps

cat >$TMP <<EOF
@SysInclude{fontdefs}
@SysInclude{langdefs}
@SysInclude{fig}
@SysInclude{eq}
@SysInclude{graph}
@SysInclude{dl}
extend @DocumentLayout
export @TextPlace @Text
def @PlainLayout
@Begin
def @TextPlace { @Galley }
def @Text into { @TextPlace&&preceding } right x 
{
 @InitialFont @Font @InitialBreak @Break @InitialColour @Colour
 @InitialLanguage @Language x
}
@End @PlainLayout
@Use{ @DocumentLayout }
@Use{ @PlainLayout }
@TextPlace
//
@Text @Begin

EOF

cat $1 >>$TMP

cat >>$TMP <<EOF

@End @Text

EOF

cat >/tmp/mk$$ <<EOF
$TARGET: $1
	lout -EPS $TMP -o \$@
EOF
make -f /tmp/mk$$ 1>&2
rm -f /tmp/mk$$ $TMP $SRC.ld lout.li

echo \\includegraphics{$TARGET}
