summaryrefslogtreecommitdiffstats
path: root/src/engine
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2003-09-21 15:58:08 (GMT)
committerSteven Knight <knight@baldmt.com>2003-09-21 15:58:08 (GMT)
commit7d5aa5669b5208be12b1a75e7a2b2d290493508e (patch)
tree6fc95ab7e3b6b239cc16097bd02424bc92afa4c7 /src/engine
parent9598e63d01421fa10f8dad43378ad0420f7b87ec (diff)
downloadSCons-7d5aa5669b5208be12b1a75e7a2b2d290493508e.zip
SCons-7d5aa5669b5208be12b1a75e7a2b2d290493508e.tar.gz
SCons-7d5aa5669b5208be12b1a75e7a2b2d290493508e.tar.bz2
New tex.py.
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/SCons/Tool/tex.py66
1 files changed, 65 insertions, 1 deletions
diff --git a/src/engine/SCons/Tool/tex.py b/src/engine/SCons/Tool/tex.py
index c3d38f1..b9a8dea 100644
--- a/src/engine/SCons/Tool/tex.py
+++ b/src/engine/SCons/Tool/tex.py
@@ -33,7 +33,61 @@ selection method.
__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."""
@@ -43,11 +97,21 @@ def generate(env):
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')