bug-texinfo
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

texi2dvi: A more pleasant way to compile


From: Akim Demaille
Subject: texi2dvi: A more pleasant way to compile
Date: Wed, 25 May 2005 18:42:24 +0200
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

The following patch transforms TeX into the program I would have liked
it to be :)  This patch considerably improves my life by easing the
edition cycle.  I hope the ChangeLog and the code are clear enough to
see the point.

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        Let all the compilations happen in a local directory.  This is
        similar to using --clean, but the files are preserved.  The
        benefits are:
        - the output is updated when each tex compilation is completed:
        - to allow interactive viewing
        - to preserve the previous output is the compilation fails
        - if the compilation fails, the previous state is preserved.
        - a fix set of files to clean in this end (this directory)
        - a perfect independence between DVI and PDF compilations.

        * util/texi2dvi (ensure_dir, workdir): New.
        (clean): Now a true/false Boolean.
        Adjust dependencies.
        (tmpdir_src, tmpdir_xtr, tmpdir_rcd, tmpdir_bak): Replace with...
        (work_src, work_xtr, work_rcd, work_bak): these.
        Adjust dependencies.
        (filename_src, filename_xtr, filename_rcd, filename_bak): these.
        (run_tex): Update the output.
        Remove this task from the core of the loop.

Index: util/texi2dvi
===================================================================
RCS file: /cvsroot/texinfo/texinfo/util/texi2dvi,v
retrieving revision 1.52
diff -u -u -r1.52 texi2dvi
--- util/texi2dvi 25 May 2005 09:13:24 -0000 1.52
+++ util/texi2dvi 25 May 2005 16:40:11 -0000
@@ -87,7 +87,7 @@
 # Don't use `unset' since old bourne shells don't have this command.
 # Instead, assign them an empty value.
 batch=false     # eval for batch mode
-clean=
+clean=false
 debug=
 escape='\'
 expand=         # t for expansion via makeinfo
@@ -173,6 +173,18 @@
   exit $s
 }
 
+# ensure_dir $DIRECTORY...
+# Make sure the directory exists.
+ensure_dir ()
+{
+  for dir
+  do
+    test -d "$dir" \
+      || mkdir "$dir" \
+      || fatal 1 "cannot create directory: $dir"
+  done
+}
+
 # Save TEXINPUTS so we can construct a new TEXINPUTS path for each file.
 # Likewise for bibtex and makeindex.
 tex_envvars="BIBINPUTS BSTINPUTS INDEXSTYLE TEXINPUTS"
@@ -211,7 +223,7 @@
     -@ ) escape=@;;
     # Silently and without documentation accept -b and --b[atch] as synonyms.
     -b | --b*) batch=true;;
-    -c | --c*) clean=t;;
+    -c | --c*) clean=true;;
     -D | --d*) debug=t;;
     -e | -E | --e*) expand=t;;
     -h | --h*) echo "$usage"; exit 0;;
@@ -442,9 +454,16 @@
   cmd="$cmd '$filename_input'"
 
   verbose "Running $cmd ..."
-  if eval "$cmd" >&5; then :; else
-    test "$clean" = t \
-        && cp "$filename_noext.log" "$orig_pwd"
+  if eval "$cmd" >&5; then
+    # Update the actual output.
+    case $oname in
+      '') dest=$orig_pwd;;
+       *) dest=$oname;;
+    esac
+    verbose "Copying $oformat file from `pwd` to $dest"
+    cp -p "./$filename_noext.$oformat" "$dest"
+  else
+    cp "$filename_noext.log" "$orig_pwd"
     fatal 1 "$tex exited with bad status, quitting." \
             "see $filename_noext.log for errors."
   fi
@@ -515,26 +534,38 @@
   filename_noext=`echo "$filename_ext" | sed 's/\.[^.]*$//'`
   ext=`echo "$filename_ext" | sed 's/^.*\.//'`
 
+  # An auxiliary directory used to compile this document.  If --clean,
+  # then leave it in the global temporary directory.
+  workdir=`$clean && echo "$tmpdir/"`$filename_noext.t2d
+  ensure_dir "$workdir"
+  # We will change directory, better work with an absolute path...
+  workdir=`cd "$workdir" && pwd`
+  # Sometimes there are incompatibilities between auxiliary files for
+  # DVI and PDF.  The contents can also change whether we work on PDF
+  # and/or DVI.  So keep separate spaces for each.
+  workdir=$workdir/$oformat
+  ensure_dir "$workdir"
+
   # _src.  Use same basename since we want to generate aux files with
   # the same basename as the manual.  If --expand, then output the
   # macro-expanded file to here, else copy the original file.
-  tmpdir_src=$tmpdir/src
-  filename_src=$tmpdir_src/$filename_noext.$ext
+  work_src=$workdir/src
+  filename_src=$work_src/$filename_noext.$ext
 
   # _xtr.  The file with the user's extra commands.
-  tmpdir_xtr=$tmpdir/xtr
-  filename_xtr=$tmpdir_xtr/$filename_noext.$ext
+  work_xtr=$workdir/xtr
+  filename_xtr=$work_xtr/$filename_noext.$ext
 
   # _rcd.  The Texinfo file recoded in 7bit.
-  tmpdir_rcd=$tmpdir/rcd
-  filename_rcd=$tmpdir_rcd/$filename_noext.$ext
+  work_rcd=$workdir/rcd
+  filename_rcd=$work_rcd/$filename_noext.$ext
 
   # _bak.  Copies of the previous xref files (another round is run if
   # they differ from the new one).
-  tmpdir_bak=$tmpdir/bak
+  work_bak=$workdir/bak
 
   # Make all those directories and give up if we can't succeed.
-  mkdir $tmpdir_src $tmpdir_xtr $tmpdir_rcd $tmpdir_bak || exit 1
+  ensure_dir $work_src $work_xtr $work_rcd $work_bak
 
   # Source file might include additional sources.
   # We want `.:$orig_pwd' before anything else.  (We'll add `.:' later
@@ -689,11 +720,9 @@
     fi
   fi
 
-  # If clean mode was specified, then move to the temporary directory.
-  if test "$clean" = t; then
-    verbose "cd $tmpdir_src"
-    cd "$tmpdir_src" || exit 1
-  fi
+  # Move to the working directory.
+  verbose "cd $work_src"
+  cd "$work_src" || exit 1
 
   while :; do # will break out of loop below
     orig_xref_files=`get_xref_files "$filename_noext"`
@@ -701,7 +730,7 @@
     # Save copies of originals for later comparison.
     if test -n "$orig_xref_files"; then
       verbose "Backing up xref files: `echo $orig_xref_files | sed 's|\./||g'`"
-      cp $orig_xref_files $tmpdir_bak
+      cp $orig_xref_files $work_bak
     fi
 
     # Run bibtex on current file.
@@ -796,13 +825,13 @@
       for this_file in $new_xref_files; do
         verbose "Comparing xref file `echo $this_file | sed 's|\./||g'` ..."
         # cmp -s returns nonzero exit status if files differ.
-        if cmp -s "$this_file" "$tmpdir_bak/$this_file"; then :; else
+        if cmp -s "$this_file" "$work_bak/$this_file"; then :; else
           # We only need to keep comparing until we find one that
           # differs, because we'll have to run texindex & tex again no
           # matter how many more there might be.
           finished=
           verbose "xref file `echo $this_file | sed 's|\./||g'` differed ..."
-          test "$debug" = t && diff -c "$tmpdir_bak/$this_file" "$this_file"
+          test "$debug" = t && diff -c "$work_bak/$this_file" "$this_file"
           break
         fi
       done
@@ -827,23 +856,6 @@
     fi
   fi
 
-  # Honor the actual output destination.
-  case $clean:$oname in
-    :) dest=;;
-
-    t:)  # If we were in clean mode, compilation was in a tmp
-        # directory.  Copy the DVI (or PDF) file into the directory
-        # where the compilation has been done.  (The temp dir is
-        # about to get removed anyway.)
-        dest=$orig_pwd;;
-
-    *:*) dest=$oname;;
-  esac
-  if test -n "$dest"; then
-    verbose "Copying $oformat file from `pwd` to $dest"
-    cp -p "./$filename_noext.$oformat" "$dest"
-  fi
-
   # Return to the original directory so that
   # - the next file is processed in correct conditions
   # - the temporary file can be removed





reply via email to

[Prev in Thread] Current Thread [Next in Thread]