test -f /bin/ksh && test -z "$RUNNING_KSH" \
&& { UNAMES=`uname -s`; test "x$UNAMES" = xULTRIX; } 2>/dev/null \
&& { RUNNING_KSH=true; export RUNNING_KSH; exec /bin/ksh $0 ${1+"$@"}; }
unset RUNNING_KSH
set -e
: ${SED=sed}
program=`echo $0 | $SED -e 's!.*/!!'`
build_mode=${TEXI2DVI_BUILD_MODE:-local}
build_dir=${TEXI2DVI_BUILD_DIRECTORY:-.}
orig_pwd=`pwd`
action=compile
debug=false
escape="\\"
expand=false includes=
line_error=true max_iters=7 oname= out_lang=dvi
quiet=false set_language=
src_specials=
shell_escape=
latex2html=hevea textra= txiprereq=19990129 verb=false translate_file=
space=' '
tab=' '
newline='
'
IFS="$space$tab$newline"
: ${EGREP=egrep}
if test -n "$COMSPEC$ComSpec" \
&& MSYSTEM=$OSTYPE uname | $EGREP -iv 'cygwin|msys' >/dev/null; then
path_sep=";"
else
path_sep=":"
fi
CDPATH=${ZSH_VERSION+.}$path_sep
usage ()
{
cat <<EOF
Usage: $program [OPTION]... FILE...
or: texi2pdf [OPTION]... FILE...
or: pdftexi2dvi [OPTION]... FILE...
Run each Texinfo or (La)TeX FILE through TeX in turn until all
cross-references are resolved, building all indices. The directory
containing each FILE is searched for included files. The suffix of FILE
is used to determine its language ((La)TeX or Texinfo). To process
(e)plain TeX files, set the environment variable LATEX=tex.
When invoked as \`texi2pdf' or given the option --pdf generate PDF output.
Otherwise, generate DVI.
General options:
-D, --debug turn on shell debugging (set -x)
-h, --help display this help and exit successfully
-o, --output=OFILE leave output in OFILE; only one input FILE is allowed
-q, --quiet no output unless errors
-v, --version display version information and exit successfully
-V, --verbose report on what is done
--max-iterations=N don't process files more than N times [$max_iters]
--mostly-clean remove auxiliary files or directories from
previous runs (but not the output)
Output format:
--dvi output a DVI file [default]
--dvipdf output a PDF file via DVI (using a dvi-to-pdf program)
--html output an HTML file from LaTeX, using HeVeA
--info output an Info file from LaTeX, using HeVeA
-p, --pdf use pdftex or pdflatex for processing
--ps output a PostScript file via DVI (using dvips)
--text output a plain text file from LaTeX, using HeVeA
TeX tuning:
-E, --expand macro expansion using makeinfo
-I DIR search DIR for Texinfo files
-l, --language=LANG specify LANG for FILE, either latex or texinfo
--no-line-error do not pass --file-line-error to TeX
--shell-escape pass --shell-escape to TeX
--src-specials pass --src-specials to TeX
--translate-file=FILE use given charset translation file for TeX
-t, --command=CMD insert CMD in copy of input file
Build modes:
--build=MODE specify the treatment of auxiliary files [$build_mode]
--tidy same as --build=tidy
-c, --clean same as --build=clean
--build-dir=DIR specify where the tidy compilation is performed;
implies --tidy;
defaults to TEXI2DVI_BUILD_DIRECTORY [$build_dir]
The MODE specifies where the TeX compilation takes place, and, as a
consequence, how auxiliary files are treated. The build mode can also
be set using the environment variable TEXI2DVI_BUILD_MODE.
Valid values of MODE are:
\`local' compile in the current directory, leaving all the auxiliary
files around. This is the traditional TeX use.
\`tidy' compile in a local *.t2d directory, where the auxiliary files
are left. Output files are copied back to the original file.
\`clean' same as \`tidy', but remove the auxiliary directory afterwards.
Every compilation therefore requires the full cycle.
The values of these environment variables are used to run the
corresponding commands, if they are set:
BIBER BIBTEX DVIPDF DVIPS EGREP HEVEA LATEX MAKEINDEX MAKEINFO
PDFLATEX PDFTEX SED T4HT TEX TEX4HT TEXINDEX TEXINDY THUMBPDF_CMD
Regarding --dvipdf, if DVIPDF is not set in the environment, the
following programs are looked for (in this order): dvipdfmx dvipdfm
dvipdf dvi2pdf dvitopdf.
If Texinfo is installed on your site, then the command
info texi2dvi
should give you access to more documentation.
Report bugs to bug-texinfo@gnu.org,
general questions and discussion to help-texinfo@gnu.org.
GNU Texinfo home page: <http://www.gnu.org/software/texinfo/>
General help using GNU software: <http://www.gnu.org/gethelp/>
EOF
exit 0
}
version ()
{
cat <<EOF
texi2dvi (GNU Texinfo 6.7)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
EOF
exit 0
}
rel=
cd_dir ()
{
cd "$1"
use_absolute=false
case $1 in
[\\/]* | ?:[\\/]*) use_absolute=true ;;
esac
case $in_input in
[\\/]* | ?:[\\/]*)
use_absolute=true ;;
esac
if $use_absolute ; then
for cdd_dir in work_build workdir t2ddir work_bak in_input in_dir; do
eval "$cdd_dir=\`absolute \$$cdd_dir\`"
done
return
fi
rel=`echo "$1" | \$SED -e 's/[^/\\][^/\\]*/../g' -e 's/[/\\]*$/\//'`
}
cd_orig ()
{
cd /
cd "$orig_pwd" || exit 1
rel=
}
func_dirname ()
{
dirname "$1" 2>/dev/null \
|| { echo "$1" | $SED 's!/[^/]*$!!;s!^$!.!'; }
}
noext ()
{
echo "$1" | $SED -e 's/\.[^/.][^/.]*$//'
}
absolute ()
{
case $1 in
[\\/]* | ?:[\\/]*)
echo "$1"
;;
*) absolute_slashes=`echo "$1" | $SED -n 's,.*[^/]\(/*\)$,\1,p'`
absolute_rel=$orig_pwd/`func_dirname "$1"`
if test -d "$absolute_rel"; then
(cd "$absolute_rel" 2>/dev/null \
&& absolute_name=`pwd`/`basename "$1"`"$absolute_slashes"
echo "$absolute_name")
else
error 1 "not a directory: $absolute_rel"
fi
;;
esac
}
ensure_dir ()
{
for dir
do
test -d "$dir" \
|| mkdir "$dir" \
|| test -d "$dir" \
|| error 1 "cannot create directory: $dir"
done
}
error ()
{
error_status="$1"
shift
report "$@"
if test "$error_status" != 0; then
exit $error_status
fi
}
findprog ()
{
saveIFS="$IFS"
IFS=$path_sep for dir in $PATH; do
IFS=$saveIFS
if { test -f "$dir/$1" && test -x "$dir/$1"; } \
|| { test -f "$dir/$1.exe" && test -x "$dir/$1.exe"; }; then
return 0
fi
done
return 1
}
report ()
{
for i in "$@"
do
echo >&2 "$0: $i"
done
}
run ()
{
verbose "Running $@"
"$@" 2>&5 1>&2 \
|| error 1 "$1 failed"
}
verbose ()
{
if $verb; then
echo >&2 "$0: $@"
fi
}
list_append ()
{
list_name="$1"
shift
eval set X \$$list_name "$@"
shift
eval $list_name=\""$@"\"
}
list_concat_dirs ()
{
lcd_list="$1"
lcd_replace_EMPTY="-e 's/^$path_sep/EMPTY$path_sep/g' \
-e 's/$path_sep\$/${path_sep}EMPTY/g' \
-e 's/$path_sep$path_sep/${path_sep}EMPTY${path_sep}/g'"
save_IFS=$IFS
IFS=$path_sep
set x `echo "$2" | eval $SED $lcd_replace_EMPTY`; shift
IFS=$save_IFS
for lcd_dir
do
case $lcd_dir in
EMPTY)
list_append $lcd_list ""
;;
*)
if test -d $lcd_dir; then
dir=`absolute "$lcd_dir"`
list_append $lcd_list "$lcd_dir"
fi
;;
esac
done
}
list_prefix ()
{
lp_separator="$2"
eval set X \$$1
shift
lp_result=''
for i
do
lp_result="$lp_result \"$lp_separator\" \"$i\""
done
echo "$lp_result"
}
list_infix ()
{
eval set X \$$1
shift
save_IFS="$IFS"
IFS=$path_sep
echo "$*"
IFS=$save_IFS
}
list_dir_to_abs ()
{
ldta_list="$1"
eval set X \$$ldta_list
shift
ldta_result=''
for dir
do
dir=`absolute "$dir"`
test -d "$dir" || continue
ldta_result="$ldata_result \"$dir\""
done
set X $ldta_result; shift
eval $ldta_list=\"$@\"
}
out_lang_set ()
{
case $1 in
dvi|dvipdf|html|info|pdf|ps|text) out_lang=$1;;
*) error 1 "invalid output format: $1";;
esac
}
out_lang_tex ()
{
case $out_lang in
dvi | ps | dvipdf ) echo dvi;;
pdf ) echo $out_lang;;
html | info | text ) echo $out_lang;;
*) error 1 "invalid out_lang: $1";;
esac
}
out_lang_ext ()
{
case $out_lang in
dvipdf ) echo pdf;;
dvi | html | info | pdf | ps | text ) echo $out_lang;;
*) error 1 "invalid out_lang: $1";;
esac
}
absolute_filenames ()
{
af_replace_empty="-e 's/^$path_sep/EMPTY$path_sep/g' \
-e 's/$path_sep\$/${path_sep}EMPTY/g' \
-e 's/$path_sep$path_sep/${path_sep}EMPTY${path_sep}/g'"
af_result=`echo "$1" | eval $SED $af_replace_empty`
save_IFS=$IFS
IFS=$path_sep
set x $af_result; shift
af_result=
af_path_sep=
for dir
do
case $dir in
EMPTY)
af_result=$af_result$af_path_sep
;;
*)
if test -d "$dir"; then
af_result=$af_result$af_path_sep`absolute "$dir"`
else
af_result=$af_result$af_path_sep$dir
fi
;;
esac
af_path_sep=$path_sep
done
echo "$af_result"
}
output_base_name ()
{
case $oname in
'') echo "$1";;
*) obn_out_noext=`noext "$oname"`
obn_file_ext=`echo "$1" | $SED 's/^.*\.//'`
echo "$obn_out_noext.$obn_file_ext"
;;
esac
}
destdir ()
{
case $oname in
'') echo "$orig_pwd";;
*) dirname "$oname";;
esac
}
move_to_dest ()
{
case $tidy:$oname in
false:) return;;
esac
for file
do
test -f "$file" \
|| error 1 "no such file or directory: $file"
case $tidy:$oname in
true:) mtd_destdir=$orig_pwd
mtd_destfile=$mtd_destdir/$file;;
true:*) mtd_destfile=`output_base_name "$file"`
mtd_destdir=`dirname "$mtd_destfile"`;;
false:*) mtd_destfile=$oname
mtd_destdir=`dirname "$mtd_destfile"`;;
esac
mtd_destdir=`cd "$mtd_destdir" && pwd`
mtd_destbase=`basename "$mtd_destfile"`
mtd_sourcedir=`dirname "$file"`
mtd_sourcedir=`cd "$mtd_sourcedir" && pwd`
mtd_sourcebase=`basename "$file"`
if test "$mtd_sourcedir/$mtd_sourcebase" != "$mtd_destdir/$mtd_destbase"
then
verbose "Moving $file to $mtd_destfile"
rm -f "$mtd_destfile"
mv "$file" "$mtd_destfile"
fi
done
}
aux_file_p ()
{
test -f "$1" || return 0
case $1 in
*.aux) echo "$1";;
*) return 0;;
esac
}
bibaux_file_p ()
{
test -s "$1" || return 0
if (grep '^\\bibstyle[{]' "$1" \
&& grep '^\\bibdata[{]' "$1" \
) >&6 2>&1;
then
echo "$1"
fi
return 0
}
index_file_p ()
{
test -f "$1" || return 0
case $in_lang:$latex2html:`out_lang_tex`:`$SED '1q' "$1"` in
latex:tex4ht:html:"\\beforeentry {"*) echo $1;;
latex:*:*:"\\indexentry{"*|latex:*:*:"\\indexentry {"*) echo $1;;
texinfo:*:*:"\\entry{"*) echo $1;;
texinfo:*:*:"@entry{"*) echo $1;;
esac
return 0
}
xref_file_p ()
{
test -f "$1" || return 1
case `$SED '1q' "$1"` in
"\\input texinfo"*) return 1;;
[\\''@]*) return 0;;
*) return 1;;
esac
}
generated_files_get_from_log ()
{
if test -f "$1.log"; then
grep '^\\openout[0-9]' "$1.log" \
| $SED -e "s/\\\\openout[^=]*= *[\`']*//" \
-e "s/'\.$//"
fi
}
generated_files_get_from_fls ()
{
if test -f "$1.fls"; then
grep '^OUTPUT ' "$1.fls" | cut -b 8- \
| grep -v '\.dvi$' | grep -v '\.log$' | grep -v '\.pdf$' || true
fi
}
generated_files_get ()
{
$generated_files_get_method "$in_noext"
if test $generated_files_get_method = generated_files_get_from_fls; then
if test -r "$in_noext.fl"; then
report 'WARNING!! The fl index may typeset as garbage!' report 'Try upgrading your version of texinfo.tex, or else try setting'
report 'the environment variable TEXI2DVI_USE_RECORDER to '\''no'\''.'
report 'Once you'\''ve done that, delete the file with an '\''fl'\'' extension.'
fi
fi
}
xref_files_save ()
{
xref_files_orig=$xref_files_new
if test -n "$xref_files_orig"; then
verbose "Backing up xref files: $xref_files_orig"
TAR_OPTIONS=; export TAR_OPTIONS
tar cf - $xref_files_orig | (cd "$rel$work_bak" && tar xf -)
fi
if $tidy ; then
secondary_xref_files=`sorted_index_files`
for f in $xref_files_new $secondary_xref_files ; do
if test -f "$rel$in_dir/$f" ; then
remove $rel$in_dir/$f
fi
done
fi
}
xref_files_changed ()
{
if grep "Rerun to get" "$in_noext.log" >&6 2>&1; then
return 0
fi
if grep "biblatex.*(re)run" "$in_noext.log" >&6 2>&1; then
return 0
fi
xref_files_new=`generated_files_get`
verbose "Original xref files = $xref_files_orig"
verbose "New xref files = $xref_files_new"
if test "x$xref_files_orig" != "x$xref_files_new"; then
return 0
fi
for this_file in $xref_files_new; do
verbose "Comparing xref file `echo $this_file | $SED 's|\./||g'` ..."
if cmp -s "$this_file" "$rel$work_bak/$this_file"; then :; else
verbose "xref file `echo $this_file | $SED 's|\./||g'` differed ..."
if $debug; then
diff -u "$rel$work_bak/$this_file" "$this_file"
fi
return 0
fi
done
secondary_xref_files=`sorted_index_files`
verbose "Secondary xref files = $secondary_xref_files"
for this_file in $secondary_xref_files; do
if test -f $this_file; then :; else
verbose "$this_file missing ..."
return 0
fi
done
return 1
}
make_tex_cmd ()
{
case $in_lang:$latex2html:`out_lang_tex` in
latex:*:dvi|latex:tex4ht:html)
tex=${LATEX:-latex};;
latex:*:pdf)
tex=${PDFLATEX:-pdflatex};;
texinfo:*:dvi)
case $TEX in
*latex) tex=tex;; *) tex=$TEX
esac;;
texinfo:*:pdf) tex=$PDFTEX;;
*) error 1 "$out_lang not supported for $in_lang";;
esac
case $in_lang:$tidy in
latex:true)
$SED -n 's|^[ ]*\\include{\(.*\)/.*}.*|\1|p' "$in_input" |
sort -u |
while read d
do
ensure_dir "$work_build/$d"
done
;;
esac
tex_cmd="$tex"
if $line_error; then
if test "${tex_help:+set}" != set; then
tex_help_dir=$t2ddir/tex_help
ensure_dir "$tex_help_dir"
tex_help=`cd "$tex_help_dir" >&6 && $tex --help </dev/null 2>&1 || true`
fi
case $tex_help in
*file-line-error*) tex_cmd="$tex_cmd --file-line-error";;
esac
fi
tex_cmd="$tex_cmd$recorder_option_maybe"
test -n "$translate_file" \
&& tex_cmd="$tex_cmd --translate-file=$translate_file"
test -n "$src_specials" && tex_cmd="$tex_cmd $src_specials"
test -n "$shell_escape" && tex_cmd="$tex_cmd $shell_escape"
tex_cmd="$tex_cmd </dev/null '${escape}nonstopmode'"
}
run_tex ()
{
in_input_funnies=`echo "$in_input" \
| $SED -e 's![^}#$%&^_{~]!!g' -e 's!\(.\)!\1\''
!g' | uniq`
if test -n "$in_input_funnies" ; then
tex_cmd="$tex_cmd '${escape}bgroup${escape}catcode62=2${escape}relax'"
for w in $in_input_funnies ; do
tex_cmd="$tex_cmd '${escape}catcode\`${escape}$w=12${escape}relax'"
done
tex_cmd="$tex_cmd '${escape}toks0${escape}bgroup${escape}input' '$rel$in_input' '${escape}relax>"
tex_cmd="$tex_cmd${escape}expandafter${escape}egroup"
tex_cmd="$tex_cmd${escape}the${escape}toks0${escape}relax'"
else
tex_cmd="$tex_cmd '${escape}input' '$rel$in_input'"
fi
verbose "$0: Running $tex_cmd ..."
if (eval "$tex_cmd" >&5); then
case $out_lang in
dvi | pdf ) move_to_dest "$in_noext.$out_lang";;
esac
else
tex_failed=true
fi
}
run_bibtex ()
{
case $in_lang in
latex) bibtex=${BIBTEX:-bibtex};;
texinfo) return;;
esac
if test -r "$in_noext.aux" \
&& test -r "$in_noext.log" \
&& ( (grep 'Warning:.*Citation.*undefined' "$in_noext.log" \
|| grep '.*Undefined citation' "$in_noext.log" \
|| grep 'No file .*\.bbl\.' "$in_noext.log") \
|| (grep 'No \.aux file' "$in_noext.log" \
&& grep '^\\bibdata' "$in_noext.aux") ) \
>&6 2>&1; \
then
bibtex_aux=`filter_files bibaux_file_p`
for f in $bibtex_aux; do
run $bibtex "$f"
done
fi
if test -r "$in_noext.bcf" \
&& grep '</bcf:controlfile>' "$in_noext.bcf" >/dev/null; then
run ${BIBER:-biber} "$in_noext"
fi
}
filter_files ()
{
test -n "$xref_files_new" || return 0
echo "$xref_files_new" |
while read file; do
$1 "$file"
done |
sort |
uniq
}
run_index ()
{
index_files=`filter_files index_file_p`
test -n "$index_files" \
|| return 0
: ${MAKEINDEX:=makeindex}
: ${TEXINDEX:=texindex}
: ${TEXINDY:=texindy}
case $in_lang:$latex2html:`out_lang_tex` in
latex:tex4ht:html)
for index_file in $index_files
do
index_noext=`noext "$index_file"`
run tex \
'\def\filename{{'"$index_noext"'}{idx}{4dx}{ind}}
\input idxmake.4ht'
run $MAKEINDEX -o $index_noext.ind $index_noext.4dx
done
;;
latex:*)
if $TEXINDY --version >&6 2>&1; then
run $TEXINDY $index_files
else
run $MAKEINDEX $index_files
fi
;;
texinfo:*)
run $TEXINDEX $index_files
;;
esac
}
run_tex4ht ()
{
case $in_lang:$latex2html:`out_lang_tex` in
latex:tex4ht:html)
: ${TEX4HT:=tex4ht} ${T4HT:=t4ht}
run "$TEX4HT" "-f/$in_noext"
run "$T4HT" "-d`destdir`/" "-f/$in_noext"
;;
esac
}
run_thumbpdf ()
{
if test `out_lang_tex` = pdf \
&& test -r "$in_noext.log" \
&& grep 'thumbpdf\.sty' "$in_noext.log" >&6 2>&1; \
then
thumbpdf=${THUMBPDF_CMD:-thumbpdf}
thumbcmd="$thumbpdf $in_dir/$in_noext"
verbose "Running $thumbcmd ..."
if $thumbcmd >&5; then
run_tex
else
report "$thumbpdf exited with bad status." \
"Ignoring its output."
fi
fi
}
run_dvipdf ()
{
if test -n "$DVIPDF"; then
dvipdf=$DVIPDF
elif test -z "$dvipdf"; then
for i in dvipdfmx dvipdfm dvipdf dvi2pdf dvitopdf; do
if findprog $i; then
dvipdf=$i
fi
done
fi
run $dvipdf "$1"
if test ! -f `echo "$1" | $SED -e 's/\.dvi$/.pdf/'`; then
error 1 "cannot find output file"
fi
}
run_tex_suite ()
{
make_tex_cmd
if $tidy; then
verbose "cd $work_build"
cd_dir "$work_build" || exit 1
fi
suite_cycle=0
xref_files_new=`generated_files_get`
xref_files_save
while :; do
if test $suite_cycle -eq "$max_iters"; then
error 0 "Maximum of $max_iters cycles exceeded"
break
fi
suite_cycle=`expr $suite_cycle + 1`
verbose "Cycle $suite_cycle for $command_line_filename"
tex_failed=false
run_core_conversion
xref_files_changed || break
xref_files_save
run_bibtex
run_index
done
if $tex_failed ; then
error 1 "$tex exited with bad status, quitting."
fi
run_thumbpdf
run_tex4ht
case $latex2html:$out_lang in
*:dvipdf)
run_dvipdf "$in_noext.`out_lang_tex`"
move_to_dest "$in_noext.`out_lang_ext`"
;;
*:ps)
: ${DVIPS:=dvips}
run $DVIPS -o "$in_noext.`out_lang_ext`" "$in_noext.`out_lang_tex`"
move_to_dest "$in_noext.`out_lang_ext`"
;;
esac
cd_orig
}
run_makeinfo ()
{
test $in_lang = texinfo \
|| return 0
if $expand; then
makeinfo=${MAKEINFO:-makeinfo}
else
version_test_dir=$t2ddir/version_test
ensure_dir "$version_test_dir"
if (
cd "$version_test_dir"
echo '\input texinfo.tex @bye' >txiversion.tex
$TEX txiversion.tex </dev/null >txiversion.out 2>txiversion.err
); then :; else
report "texinfo.tex appears to be broken.
This may be due to the environment variable TEX set to something
other than (plain) tex, a corrupt texinfo.tex file, or
to tex itself simply not working."
cat "$version_test_dir/txiversion.out"
cat "$version_test_dir/txiversion.err" >&2
error 1 "quitting."
fi
eval `$SED -n 's/^.*\[\(.*\)version \(....\)-\(..\)-\(..\).*$/txiformat=\1 txiversion="\2\3\4"/p' "$version_test_dir/txiversion.out"`
verbose "texinfo.tex preloaded as \`$txiformat', version is \`$txiversion' ..."
if test "$txiprereq" -le "$txiversion" >&6 2>&1; then
makeinfo=
else
makeinfo=${MAKEINFO:-makeinfo}
fi
if test "$txiformat" = Texinfo; then
escape=@
fi
fi
if test -n "$makeinfo"; then
work_src=$workdir/src
ensure_dir "$work_src"
in_src=$work_src/$in_base
run_mi_includes=`list_prefix includes -I`
verbose "Macro-expanding $command_line_filename to $in_src ..."
$SED "$comment_iftex" "$command_line_filename" \
| eval $makeinfo --footnote-style=end -I "$in_dir" $run_mi_includes \
-o /dev/null --macro-expand=- \
| $SED "$uncomment_iftex" >"$in_src"
if test $? -ne 0 \
|| test ! -r "$in_src"; then
verbose "Expansion failed, ignored...";
else
in_input=$in_src
fi
fi
}
comment_iftex=\
'/^@tex/,/^@end tex/{
s/^/@c _texi2dvi/
}
/^@iftex/,/^@end iftex/{
s/^/@c _texi2dvi/
/^@c _texi2dvi@macro/,/^@c _texi2dvi@end macro/{
s/^@c _texi2dvi//
}
}
/^@ifnottex/,/^@end ifnottex/{
s/^/@c (_texi2dvi)/
/^@c (_texi2dvi)@node Top/,/^@c (_texi2dvi)@end ifnottex/ {
/^@c (_texi2dvi)@end ifnottex/b
s/^@c (_texi2dvi)//
}
}
/^@ifinfo/,/^@end ifinfo/{
/^@node/p
/^@menu/,/^@end menu/p
t
s/^/@c (_texi2dvi)/
}
s/^@ifnotinfo/@c _texi2dvi@ifnotinfo/
s/^@end ifnotinfo/@c _texi2dvi@end ifnotinfo/'
uncomment_iftex=\
's/^@c _texi2dvi\(@c _texi2dvi\)*//
/^@c (_texi2dvi)@ifnottex/,/^@c (_texi2dvi)@end ifnottex/{
s/^/@c (_texi2dvi)/
}'
insert_commands ()
{
if test -n "$textra"; then
work_xtr=$workdir/xtr
in_xtr=$work_xtr/$in_base
ensure_dir "$work_xtr"
verbose "Inserting extra commands: $textra"
case $in_lang in
latex) textra_cmd=1i;;
texinfo)
textra_cmd='/^\\input texinfo/a'
if head -n 10 $in_input | grep '^@setfilename' ; then
textra_cmd='/^@setfilename/a'
fi
;;
*) error 1 "internal error, unknown language: $in_lang";;
esac
$SED "$textra_cmd\\
$textra" "$in_input" >"$in_xtr"
in_input=$in_xtr
fi
case $in_lang:$latex2html:`out_lang_tex` in
latex:tex4ht:html)
work_tex4ht=$workdir/tex4ht
in_tex4ht=$work_tex4ht/$in_base
ensure_dir "$work_tex4ht"
verbose "Inserting \\usepackage{tex4ht}"
perl -pe 's<\\documentclass(?:\[.*\])?{.*}>
<$&\\usepackage[xhtml]{tex4ht}>' \
"$in_input" >"$in_tex4ht"
in_input=$in_tex4ht
;;
esac
}
compute_language ()
{
if test -n "$set_language"; then
echo $set_language
elif $SED 1q "$1" | grep 'input texinfo' >&6; then
echo texinfo
else
case $1 in
*.ltx | *.tex | *.drv | *.dtx) echo latex;;
*) echo texinfo;;
esac
fi
}
run_hevea ()
{
run_hevea_name="${HEVEA:-hevea}"
run_hevea_cmd="$run_hevea_name"
case $1 in
html) ;;
text|info) run_hevea_cmd="$run_hevea_cmd -$1";;
*) error 1 "run_hevea_cmd: invalid argument: $1";;
esac
run_hevea_cmd="$run_hevea_cmd -fix -O -o '$out_base'"
run_hevea_cmd="$run_hevea_cmd `list_prefix includes -I` -I '$orig_pwd' "
run_hevea_cmd="$run_hevea_cmd '$rel$in_input'"
if $debug; then
run_hevea_cmd="$run_hevea_cmd -v -v"
fi
verbose "running $run_hevea_cmd"
if eval "$run_hevea_cmd" >&5; then
case $1 in text|info)
perl -pi -e 's/[ \t]+$//g' "$out_base"*;;
esac
case $1 in
html|text) move_to_dest "$out_base";;
info) move_to_dest "$out_base"*;;
esac
else
error 1 "$run_hevea_name exited with bad status, quitting."
fi
}
run_core_conversion ()
{
case $in_lang:$latex2html:`out_lang_tex` in
*:dvi|*:pdf|latex:tex4ht:html)
run_tex;;
latex:*:html|latex:*:text|latex:*:info)
run_hevea $out_lang;;
*)
error 1 "invalid input/output combination: $in_lang/$out_lang";;
esac
}
compile ()
{
common="$orig_pwd$path_sep$in_dir$path_sep"
txincludes=`list_infix includes $path_sep`
test -n "$txincludes" && common="$common$txincludes$path_sep"
for var in $tex_envvars; do
eval val="\$common\$${var}_orig"
val=`absolute_filenames "$val"`
eval $var="\"$val\""
export $var
eval verbose \"$var=\'\$${var}\'\"
done
run_makeinfo
insert_commands
run_tex_suite
}
make_openout_test ()
{
recorder_option_maybe="$1"
make_tex_cmd
ensure_dir "$workdir"/check_recorder
cd_dir "$workdir"/check_recorder
cat > openout.tex <<EOF
\newwrite\ourwrite
\immediate\openout\ourwrite dum.dum
\bye
EOF
tex_cmd="$tex_cmd '${escape}input' ./openout.tex"
verbose "$0: running $tex_cmd ..."
rm -fr "openout.$2"
(eval "$tex_cmd" >/dev/null 2>&1)
}
check_recorder_support ()
{
verbose "Checking TeX recorder support..."
make_openout_test " -recorder" fls
if test -f openout.fls && grep '^OUTPUT dum.dum$' openout.fls > /dev/null
then
cd_orig
verbose "Checking TeX recorder support... yes"
return 0
else
cd_orig
verbose "Checking TeX recorder support... no"
return 1
fi
}
check_openout_in_log_support ()
{
verbose "Checking TeX \openout in log support..."
make_openout_test "" log
if test -f openout.log \
&& grep '^\\openout..\? *= *`\?dum\.dum'\''\?' openout.log >/dev/null
then
cd_orig
verbose "Checking TeX \openout in log support... yes"
return 0
else
cd_orig
verbose "Checking TeX \openout in log support... no"
return 1
fi
}
set_aux_files_from_fls ()
{
recorder_option_maybe=" -recorder"
generated_files_get_method=generated_files_get_from_fls
}
set_aux_files_from_log ()
{
recorder_option_maybe=''
generated_files_get_method=generated_files_get_from_log
}
decide_aux_files_method ()
{
test -n "$TEXI2DVI_USE_RECORDER" || TEXI2DVI_USE_RECORDER=nomaybe
case $TEXI2DVI_USE_RECORDER in
yes) set_aux_files_from_fls;;
no) set_aux_files_from_log;;
yesmaybe)
if check_recorder_support; then
set_aux_files_from_fls
elif check_openout_in_log_support; then
set_aux_files_from_log
else
error 1 "TeX neither supports -recorder nor outputs \\openout lines in its log file"
fi
;;
nomaybe)
if check_openout_in_log_support; then
set_aux_files_from_log
elif check_recorder_support; then
set_aux_files_from_fls
else
error 1 "TeX neither supports -recorder nor outputs \\openout lines in its log file"
fi
;;
*) error 1 "Invalid value of TEXI2DVI_USE_RECORDER environment variable : $TEXI2DVI_USE_RECORDER.";;
esac
}
remove ()
{
verbose "Removing" "$@"
rm -rf "$@"
}
all_files ()
{
echo $in_noext.log
echo $in_noext.fls
echo $xref_files_new
echo `sorted_index_files`
}
sorted_index_files ()
{
filter_files sorted_index_filter
}
sorted_index_filter ()
{
case $in_lang in
texinfo)
if test -n "`index_file_p $1`" ; then
echo $1s
fi
;;
esac
}
bibtex_secondary_files ()
{
case $in_lang in
latex)
if test -n "`aux_file_p $1`"; then
echo $1 | $SED 's/^\(.*\)\.aux$/\1.bbl/'
echo $1 | $SED 's/^\(.*\)\.aux$/\1.blg/'
fi
;;
esac
}
mostly_clean ()
{
cd_orig
set X "$t2ddir"
shift
$tidy || {
set X ${1+"$@"} `all_files`
shift
}
remove ${1+"$@"}
}
cleanup ()
{
case $clean:$tidy in
true:true) mostly_clean ;; false:false) cd_orig; remove "$t2ddir";; esac
}
input_file_name_decode ()
{
case $command_line_filename in
*\\input{*}*)
line_error=false
command_line_filename=`\
expr X"$command_line_filename" : X'.*input{\([^}]*\)}'`
;;
esac
echo "$command_line_filename" | LC_ALL=C $EGREP '^(/|[A-Za-z]:/)' >&6 \
|| command_line_filename="./$command_line_filename"
test -r "$command_line_filename" \
|| error 1 "cannot read $command_line_filename, skipping."
in_dir=`func_dirname "$command_line_filename"`
in_base=`basename "$command_line_filename"`
in_noext=`noext "$in_base"`
in_input=$in_dir/$in_base
if test x"$oname" != x; then
out_name=$oname
else
out_name=$in_noext.`out_lang_ext`
fi
out_dir=`func_dirname "$out_name"`
out_dir_abs=`absolute "$out_dir"`
out_base=`basename "$out_name"`
out_noext=`noext "$out_base"`
}
tex_envvars="BIBINPUTS BSTINPUTS DVIPSHEADERS INDEXSTYLE MFINPUTS MPINPUTS \
TEXINPUTS TFMFONTS"
for var in $tex_envvars; do
eval ${var}_orig=\$$var
export $var
done
arg_sep="$$--$$"
set dummy ${1+"$@"} "$arg_sep"; shift
while test x"$1" != x"$arg_sep"; do
case "$1" in
--*=*)
opt=`echo "$1" | $SED -e 's/=.*//'`
val=`echo "$1" | $SED -e 's/[^=]*=//'`
shift
set dummy "$opt" "$val" ${1+"$@"}; shift
;;
esac
case "$1" in
-@ ) escape=@;;
-~ ) verbose "Option -~ is obsolete: texi2dvi ignores it.";;
-b | --batch) ;; --build) shift; build_mode=$1;;
--build-dir) shift; build_dir=$1; build_mode=tidy;;
-c | --clean) build_mode=clean;;
-D | --debug) debug=true;;
-e | -E | --expand) expand=true;;
-h | --help) usage;;
-I) shift; list_concat_dirs includes "$1";;
-l | --lang | --language) shift; set_language=$1;;
--mostly-clean) action=mostly-clean;;
--no-line-error) line_error=false;;
--max-iterations) shift; max_iters=$1;;
-o | --out | --output)
shift
oname=`absolute "$1"`;;
-O|--output-format) shift; out_lang_set "$1";;
--dvi|--dvipdf|--html|--info|--pdf|--ps|--text)
out_lang_set `echo "x$1" | $SED 's/^x--//'`;;
-p) out_lang_set pdf;;
-q | -s | --quiet | --silent) quiet=true;;
--src-specials) src_specials=--src-specials;;
--shell-escape) shell_escape=--shell-escape;;
--tex4ht) latex2html=tex4ht;;
-t | --texinfo | --command ) shift; textra="$textra\\
"`echo "$1" | $SED 's/\\\\/\\\\\\\\/g'`;;
--translate-file ) shift; translate_file="$1";;
--tidy) build_mode=tidy;;
-v | --vers*) version;;
-V | --verb*) verb=true;;
--) shift
while test x"$1" != x"$arg_sep"; do
set dummy ${1+"$@"} "$1"; shift
shift
done
break;;
-*)
error 1 "Unknown or ambiguous option \`$1'." \
"Try \`--help' for more information."
;;
*) set dummy ${1+"$@"} "$1"; shift;;
esac
shift
done
shift
case $build_mode in
local) clean=false; tidy=false;;
tidy) clean=false; tidy=true;;
clean) clean=true; tidy=true;;
*) error 1 "invalid build mode: $build_mode";;
esac
case $# in
0)
error 2 "Missing file arguments." "Try \`--help' for more information."
;;
1) ;;
*)
if test -n "$oname"; then
error 2 "Can't use option \`--output' with more than one argument."
fi
;;
esac
test -n "$TEX" && test -d "$TEX" && unset TEX
if test -z "$TEX"; then
if findprog tex; then :; else cat <<EOM >&2
You don't have a working TeX binary (tex) installed anywhere in
your PATH, and texi2dvi cannot proceed without one. If you want to use
this script, you'll need to install TeX (if you don't have it) or change
your PATH or TEX environment variable (if you do). See the --help
output for more details.
For information about obtaining TeX, please see http://tug.org/texlive,
or do a web search for TeX and your operating system or distro.
EOM
exit 1
fi
if findprog etex; then TEX=etex; else TEX=tex; fi
fi
if test -z "$PDFTEX"; then
if findprog pdfetex; then PDFTEX=pdfetex; else PDFTEX=pdftex; fi
fi
if $quiet; then
exec 5>/dev/null
else
exec 5>&1
fi
if $debug; then
exec 6>&1
set -vx
else
exec 6>/dev/null
fi
for command_line_filename
do
verbose "Processing $command_line_filename ..."
input_file_name_decode
in_lang=`compute_language "$command_line_filename"`
case $build_dir in
'' | . ) t2ddir=$out_noext.t2d ;;
*) t2ddir=$build_dir/`echo "$out_dir_abs/$out_noext.t2d" |
$SED "s,^$orig_pwd/,,;s,^\./,,;s,/,!,g"`
esac
trap "cleanup" 0 1 2 15
ensure_dir "$build_dir" "$t2ddir"
workdir=$t2ddir/`out_lang_tex`
ensure_dir "$workdir"
if $tidy; then
work_build=$workdir/build
else
work_build=.
fi
work_bak=$workdir/bak
ensure_dir "$work_build" "$work_bak"
decide_aux_files_method
case $action in
compile)
compile
cleanup
;;
mostly-clean)
xref_files_new=`generated_files_get`
mostly_clean
;;
esac
done
verbose "done."
exit 0