.IP DVI
Builds a .dvi file from a .tex, .ltx or .latex input file.
+If the source file suffix is .tex,
+.B scons
+will examine the contents of the file;
+if the string
+.B \\documentclass
+or
+.B \\documentstyle
+is found, the file is assumed to be a LaTeX file and
+the target is built by invoking the $LATEXCOM command line;
+otherwise, the $TEXCOM command line is used.
+If the file is a LaTeX file,
+the
+.B DVI
+builder will also examine the contents
+of the
+.B .aux file
+and invoke the $BIBTEX command line
+if the string
+.B bibdata
+is found,
+and will examine the contents
+.B .log
+file and re-run the $LATEXCOM command
+if the log file says it is necessary.
+
The suffix .dvi
(hard-coded within TeX itself)
is automatically added to the target
-if it is not already present. Example:
+if it is not already present. Examples:
.ES
# builds from aaa.tex
Any options specified in the $ASFLAGS and $CPPFLAGS construction variables
are included on this command line.
+.IP BIBTEX
+The bibliography generator for the TeX formatter and typesetter and the
+LaTeX structured formatter and typesetter.
+
+.IP BIBTEXCOM
+The command line used to call the bibliography generator for the
+TeX formatter and typesetter and the LaTeX structured formatter and
+typesetter.
+
+.IP BIBTEXFLAGS
+General options passed to the bibliography generator for the TeX formatter
+and typesetter and the LaTeX structured formatter and typesetter.
+
.IP BITKEEPER
The BitKeeper executable.
subclass of Environment.Base and setting a new Environment.Environment
variable as the calling entry point.
+ From Clark McGrew:
+
+ - Generalize the action for .tex files so that it will decide whether
+ a file is TeX or LaTeX, check the .aux output to decide if it should
+ run bibtex, and check the .log output to re-run LaTeX if needed.
+
From Bram Moolenaar:
- Split the non-SCons-specific functionality from SConf.py to a new,
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import os.path
+import re
+import string
+
+import SCons.Action
import SCons.Defaults
+import SCons.Node
+import SCons.Node.FS
+import SCons.Util
+
+# Define an action to build a generic tex file. This is sufficient for all
+# tex files.
+TeXAction = SCons.Action.CommandAction("$TEXCOM")
+
+# Define an action to build a latex file. This action might be needed more
+# than once if we are dealing with labels and bibtex
+LaTeXAction = SCons.Action.CommandAction("$LATEXCOM")
+
+# Define an action to run BibTeX on a file.
+BibTeXAction = SCons.Action.CommandAction("$BIBTEXCOM")
+
+def LaTeXAuxAction(target = None, source= None, env=None):
+ """A builder for LaTeX files that checks the output in the aux file
+ and decides how many times to use LaTeXAction, and BibTeXAction."""
+ # Get the base name of the target
+ basename, ext = os.path.splitext(str(target[0]))
+ # Run LaTeX once to generate a new aux file.
+ LaTeXAction(target,source,env)
+ # Now if bibtex will need to be run.
+ content = open(basename + ".aux","rb").read()
+ if string.find(content, "bibdata") != -1:
+ bibfile = self.fs.File(basename)
+ BibTeXAction(None,bibfile,env)
+ # Now check if latex needs to be run yet again.
+ for trial in range(3):
+ content = open(basename + ".log","rb").read()
+ if not re.search("^LaTeX Warning:.*Rerun",content,re.MULTILINE):
+ break
+ LaTeXAction(target,source,env)
+ return 0
+
+def TeXLaTeXAction(target = None, source= None, env=None):
+ """A builder for TeX and LaTeX that scans the source file to
+ decide the "flavor" of the source and then executes the appropriate
+ program."""
+ LaTeXFile = False
+ for src in source:
+ content = src.get_contents()
+ if re.search("\\\\document(style|class)",content):
+ LaTeXFile = True
+ if LaTeXFile:
+ LaTeXAuxAction(target,source,env)
+ else:
+ TeXAction(target,source,env)
+ return 0
def generate(env):
"""Add Builders and construction variables for TeX to an Environment."""
bld = SCons.Defaults.DVI()
env['BUILDERS']['DVI'] = bld
- bld.add_action('.tex', '$TEXCOM')
+ bld.add_action('.tex', TeXLaTeXAction)
env['TEX'] = 'tex'
env['TEXFLAGS'] = ''
env['TEXCOM'] = '$TEX $TEXFLAGS $SOURCES'
+ # Duplicate from latex.py. If latex.py goes away, then this is still OK.
+ env['LATEX'] = 'latex'
+ env['LATEXFLAGS'] = ''
+ env['LATEXCOM'] = '$LATEX $LATEXFLAGS $SOURCES'
+
+ env['BIBTEX'] = 'bibtex'
+ env['BIBTEXFLAGS'] = ''
+ env['BIBTEXCOM'] = '$BIBTEX $BIBTEXFLAGS $SOURCES'
+
+
def exists(env):
return env.Detect('tex')
tex = foo.Dictionary('TEX')
bar = Environment(ENV = ENV, TEX = r'%s wrapper.py ' + tex)
foo.DVI(target = 'foo.dvi', source = 'foo.tex')
+foo.DVI(target = 'foo-latex.dvi', source = 'foo-latex.tex')
bar.DVI(target = 'bar', source = 'bar.tex')
+bar.DVI(target = 'bar-latex', source = 'bar-latex.tex')
""" % python)
tex = r"""
\end
"""
- test.write('foo.tex', tex % 'foo.tex')
+ latex = r"""
+\document%s{letter}
+\begin{document}
+This is the %s LaTeX file.
+\end{document}
+"""
+ test.write('foo.tex', tex % 'foo.tex')
test.write('bar.tex', tex % 'bar.tex')
+ test.write('foo-latex.tex', latex % ('style', 'foo-latex.tex'))
+ test.write('bar-latex.tex', latex % ('class', 'bar-latex.tex'))
- test.run(arguments = 'foo.dvi', stderr = None)
-
+ test.run(arguments = 'foo.dvi foo-latex.dvi', stderr = None)
test.fail_test(os.path.exists(test.workpath('wrapper.out')))
-
test.fail_test(not os.path.exists(test.workpath('foo.dvi')))
+ test.fail_test(not os.path.exists(test.workpath('foo-latex.dvi')))
- test.run(arguments = 'bar.dvi', stderr = None)
-
+ test.run(arguments = 'bar.dvi bar-latex.dvi', stderr = None)
test.fail_test(not os.path.exists(test.workpath('wrapper.out')))
-
test.fail_test(not os.path.exists(test.workpath('bar.dvi')))
+ test.fail_test(not os.path.exists(test.workpath('bar-latex.dvi')))
test.pass_test()