#! /bin/sh

# A. Flatau  9-Jul-1993; modified by M. Kaufmann many times thereafter.

# This file was originally part of create-acl2-texinfo, which created
# both Emacs Info files and a .ps file.  Now, create-acl2-texinfo
# creates Emacs Info files and create-acl2-tex creates a .ps file.
# Keep the two files in sync.

# This script should be run by executing
#   make DOC
# or
#   make TEX
# from the main ACL2 directory.  The environment variable ACL2 is used
# in this script; it is typically set in ../GNUmakefile.

rm -f doc/workxxx.tex

rm -rf doc/TEX
mkdir doc/TEX
chmod 775 doc/TEX

# Some ACL2 images start up inside LP; some don't.  (Value :q) always gets us
# out of the loop, and should also be harmless when executed in raw Lisp.
# However, note that Lispworks requires that the two forms not all be on the
# same line.

echo '(value :q)' > doc/workxxx.tex
echo '(lp)' >> doc/workxxx.tex
echo '(include-book "doc/write-acl2-texinfo")' >> doc/workxxx.tex
# Note that we do not support ACL2_DOC_UNDOCUMENTED_FILE=t here.  We
# looked into it a bit (January 2011) and it seemed awkward to provide
# that support, unlike the case of HTML.
echo '(write-tex-file :dir-string "doc/TEX/" :file "acl2-book")' >> doc/workxxx.tex
echo ':q' >> doc/workxxx.tex

${ACL2} < doc/workxxx.tex

cd doc/TEX

# Note: At UT CS we typically use an old version of texinfo.tex stored
# at /projects/acl2/devel-misc/doc/texinfo.tex in order to build the
# documentation, which seems to result in more pages with an arguably
# more attractive result.  But anyone can build it using the default
# texinfo.tex.
if [ -e ../texinfo.tex ] ; then \
    cp ../texinfo.tex . ;\
fi

texi2dvi acl2-book.tex

# We do it again because otherwise some index entries are wrong.

texi2dvi acl2-book.tex

dvips acl2-book.dvi -o acl2-book.ps

gzip acl2-book.dvi
gzip acl2-book.ps

# Make all files world-readable after changing back to doc/.

cd ..

rm -f workxxx.tex

chmod a+r TEX/*

# See notes at the bottom of create-acl2-texinfo for how to debug bad documentation.
