def LaTeXAuxFunction(target = None, source= None, env=None):
result = SCons.Tool.tex.InternalLaTeXAuxAction( LaTeXAction, target, source, env )
+ if result != 0:
+ print env['LATEX']," returned an error, check the log file"
return result
LaTeXAuxAction = SCons.Action.Action(LaTeXAuxFunction,
bld.add_emitter('.latex', SCons.Tool.tex.tex_eps_emitter)
env['LATEX'] = 'latex'
- env['LATEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode')
+ env['LATEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode -recorder')
env['LATEXCOM'] = 'cd ${TARGET.dir} && $LATEX $LATEXFLAGS ${SOURCE.file}'
env['LATEXRETRIES'] = 3
def PDFLaTeXAuxFunction(target = None, source= None, env=None):
result = SCons.Tool.tex.InternalLaTeXAuxAction( PDFLaTeXAction, target, source, env )
+ if result != 0:
+ print env['PDFLATEX']," returned an error, check the log file"
return result
PDFLaTeXAuxAction = None
bld.add_emitter('.latex', SCons.Tool.tex.tex_pdf_emitter)
env['PDFLATEX'] = 'pdflatex'
- env['PDFLATEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode')
+ env['PDFLATEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode -recorder')
env['PDFLATEXCOM'] = 'cd ${TARGET.dir} && $PDFLATEX $PDFLATEXFLAGS ${SOURCE.file}'
env['LATEXRETRIES'] = 3
program."""
if SCons.Tool.tex.is_LaTeX(source):
result = PDFLaTeXAuxAction(target,source,env)
+ if result != 0:
+ print env['PDFLATEX']," returned an error, check the log file"
else:
result = PDFTeXAction(target,source,env)
+ if result != 0:
+ print env['PDFTEX']," returned an error, check the log file"
return result
PDFTeXLaTeXAction = None
pdf.generate2(env)
env['PDFTEX'] = 'pdftex'
- env['PDFTEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode')
+ env['PDFTEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode -recorder')
env['PDFTEXCOM'] = 'cd ${TARGET.dir} && $PDFTEX $PDFTEXFLAGS ${SOURCE.file}'
# Duplicate from latex.py. If latex.py goes away, then this is still OK.
env['PDFLATEX'] = 'pdflatex'
- env['PDFLATEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode')
+ env['PDFLATEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode -recorder')
env['PDFLATEXCOM'] = 'cd ${TARGET.dir} && $PDFLATEX $PDFLATEXFLAGS ${SOURCE.file}'
env['LATEXRETRIES'] = 3
# regular expressions used to search for Latex features
# or outputs that require rerunning latex
#
-# search for all .aux files opened by latex (recorded in the .log file)
-openout_aux_re = re.compile(r"\\openout.*`(.*\.aux)'")
+# search for all .aux files opened by latex (recorded in the .fls file)
+openout_aux_re = re.compile(r"INPUT *(.*\.aux)")
#printindex_re = re.compile(r"^[^%]*\\printindex", re.MULTILINE)
#printnomenclature_re = re.compile(r"^[^%]*\\printnomenclature", re.MULTILINE)
includegraphics_re = re.compile(r'^[^%\n]*\\(?:includegraphics(?:\[[^\]]+\])?){([^}]*)}', re.MULTILINE)
# search to find all files opened by Latex (recorded in .log file)
-openout_re = re.compile(r"\\openout.*`(.*)'")
+openout_re = re.compile(r"OUTPUT *(.*)")
# list of graphics file extensions for TeX and LaTeX
TexGraphics = SCons.Scanner.LaTeX.TexGraphics
must_rerun_latex = False
# Decide if various things need to be run, or run again.
- # Read the log file to find all .aux files
+ # Read the log file to find warnings/errors
logfilename = targetbase + '.log'
logContent = ''
- auxfiles = []
if os.path.exists(logfilename):
logContent = open(logfilename, "rb").read()
- auxfiles = openout_aux_re.findall(logContent)
+
+
+ # Read the fls file to find all .aux files
+ flsfilename = targetbase + '.fls'
+ flsContent = ''
+ auxfiles = []
+ if os.path.exists(flsfilename):
+ flsContent = open(flsfilename, "rb").read()
+ auxfiles = openout_aux_re.findall(flsContent)
+ if Verbose:
+ print "auxfiles ",auxfiles
# Now decide if bibtex will need to be run.
# The information that bibtex reads from the .aux file is
bibfile = env.fs.File(targetbase)
result = BibTeXAction(bibfile, bibfile, env)
if result != 0:
+ print env['BIBTEX']," returned an error, check the blg file"
return result
must_rerun_latex = check_MD5(suffix_nodes['.bbl'],'.bbl')
break
idxfile = suffix_nodes['.idx']
result = MakeIndexAction(idxfile, idxfile, env)
if result != 0:
+ print env['MAKEINDEX']," returned an error, check the ilg file"
return result
# TO-DO: need to add a way for the user to extend this list for whatever
nclfile = suffix_nodes['.nlo']
result = MakeNclAction(nclfile, nclfile, env)
if result != 0:
+ print env['MAKENCL']," (nomenclature) returned an error, check the nlg file"
return result
# Now decide if latex will need to be run again due to glossary.
glofile = suffix_nodes['.glo']
result = MakeGlossaryAction(glofile, glofile, env)
if result != 0:
+ print env['MAKEGLOSSARY']," (glossary) returned an error, check the glg file"
return result
# Now decide if latex needs to be run yet again to resolve warnings.
program."""
if is_LaTeX(source):
result = LaTeXAuxAction(target,source,env)
+ if result != 0:
+ print env['LATEX']," returned an error, check the log file"
else:
result = TeXAction(target,source,env)
+ if result != 0:
+ print env['TEX']," returned an error, check the log file"
return result
def TeXLaTeXStrFunction(target = None, source= None, env=None):
are needed on subsequent runs of latex to finish tables of contents,
bibliographies, indices, lists of figures, and hyperlink references.
"""
- targetbase = SCons.Util.splitext(str(target[0]))[0]
+ targetbase, targetext = SCons.Util.splitext(str(target[0]))
basename = SCons.Util.splitext(str(source[0]))[0]
basefile = os.path.split(str(basename))[1]
emit_suffixes = ['.aux', '.log', '.ilg', '.blg', '.nls', '.nlg', '.gls', '.glg'] + all_suffixes
auxfilename = targetbase + '.aux'
logfilename = targetbase + '.log'
+ flsfilename = targetbase + '.fls'
env.SideEffect(auxfilename,target[0])
env.SideEffect(logfilename,target[0])
+ env.SideEffect(flsfilename,target[0])
env.Clean(target[0],auxfilename)
env.Clean(target[0],logfilename)
+ env.Clean(target[0],flsfilename)
content = source[0].get_text_contents()
env.SideEffect(targetbase + suffix,target[0])
env.Clean(target[0],targetbase + suffix)
- # read log file to get all other files that latex creates and will read on the next pass
- if os.path.exists(logfilename):
- content = open(logfilename, "rb").read()
+ # read fls file to get all other files that latex creates and will read on the next pass
+ if os.path.exists(flsfilename):
+ content = open(flsfilename, "rb").read()
out_files = openout_re.findall(content)
+ mysuffixes = ['.log' , '.fls' , targetext]
+ for filename in out_files:
+ base,ext = SCons.Util.splitext(filename)
+ if ext in mysuffixes:
+ out_files.remove(filename)
env.SideEffect(out_files,target[0])
env.Clean(target[0],out_files)
bld.add_emitter('.tex', tex_eps_emitter)
env['TEX'] = 'tex'
- env['TEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode')
+ env['TEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode -recorder')
env['TEXCOM'] = 'cd ${TARGET.dir} && $TEX $TEXFLAGS ${SOURCE.file}'
# Duplicate from latex.py. If latex.py goes away, then this is still OK.
env['LATEX'] = 'latex'
- env['LATEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode')
+ env['LATEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode -recorder')
env['LATEXCOM'] = 'cd ${TARGET.dir} && $LATEX $LATEXFLAGS ${SOURCE.file}'
env['LATEXRETRIES'] = 3
# Duplicate from pdflatex.py. If latex.py goes away, then this is still OK.
env['PDFLATEX'] = 'pdflatex'
- env['PDFLATEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode')
+ env['PDFLATEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode -recorder')
env['PDFLATEXCOM'] = 'cd ${TARGET.dir} && $PDFLATEX $PDFLATEXFLAGS ${SOURCE.file}'
def exists(env):
import os
import sys
import getopt
-cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', [])
+cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:r:', [])
base_name = os.path.splitext(arg[0])[0]
infile = open(arg[0], 'rb')
out_file = open(base_name+'.dvi', 'wb')
import os
import sys
import getopt
-cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', [])
+cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:r:', [])
base_name = os.path.splitext(arg[0])[0]
infile = open(arg[0], 'rb')
out_file = open(base_name+'.dvi', 'wb')
import os
import sys
import getopt
-cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', [])
+cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:r:', [])
infile = open(arg[0], 'rb')
out_file = open(arg[1], 'wb')
for l in infile.readlines():
import os
import sys
import getopt
-cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', [])
+cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:r:', [])
base_name = os.path.splitext(arg[0])[0]
infile = open(arg[0], 'rb')
out_file = open(base_name+'.dvi', 'wb')
import os
import sys
import getopt
-cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', [])
+cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:r:', [])
base_name = os.path.splitext(arg[0])[0]
infile = open(arg[0], 'rb')
out_file = open(base_name+'.dvi', 'wb')
import os
import sys
import getopt
-cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', [])
+cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:r:', [])
base_name = os.path.splitext(arg[0])[0]
infile = open(arg[0], 'rb')
out_file = open(base_name+'.dvi', 'wb')
import os
import sys
import getopt
-cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', [])
+cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:r:', [])
base_name = os.path.splitext(arg[0])[0]
infile = open(arg[0], 'rb')
out_file = open(base_name+'.dvi', 'wb')
import os
import sys
import getopt
-cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', [])
+cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:r:', [])
base_name = os.path.splitext(arg[0])[0]
infile = open(arg[0], 'rb')
out_file = open(base_name+'.dvi', 'wb')
import os
import sys
import getopt
-cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', [])
+cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:r:', [])
base_name = os.path.splitext(arg[0])[0]
infile = open(arg[0], 'rb')
out_file = open(base_name+'.dvi', 'wb')
import sys
import os
import getopt
-cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', [])
+cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:r:', [])
base_name = os.path.splitext(arg[0])[0]
infile = open(arg[0], 'rb')
dvi_file = open(base_name+'.dvi', 'wb')
import sys
import os
import getopt
-cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', [])
+cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:r:', [])
base_name = os.path.splitext(arg[0])[0]
infile = open(arg[0], 'rb')
pdf_file = open(base_name+'.pdf', 'wb')
import sys
import os
import getopt
-cmd_opts, arg = getopt.getopt(sys.argv[2:], 'i:', [])
+cmd_opts, arg = getopt.getopt(sys.argv[2:], 'i:r:', [])
base_name = os.path.splitext(arg[0])[0]
infile = open(arg[0], 'rb')
pdf_file = open(base_name+'.pdf', 'wb')
import sys
import os
import getopt
-cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', [])
+cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:r:', [])
base_name = os.path.splitext(arg[0])[0]
infile = open(arg[0], 'rb')
dvi_file = open(base_name+'.dvi', 'wb')
test.run(stderr = None)
output_lines = string.split(test.stdout(), '\n')
- reruns = filter(lambda x: string.find(x, 'latex -interaction=nonstopmode rerun.tex') != -1, output_lines)
+ reruns = filter(lambda x: string.find(x, 'latex -interaction=nonstopmode -recorder rerun.tex') != -1, output_lines)
if len(reruns) != 2:
print "Expected 2 latex calls, got %s:" % len(reruns)
print string.join(reruns, '\n')
""")
test.run(arguments = '--dry-run', stdout = test.wrap_stdout("""\
-cd . && latex -interaction=nonstopmode foo.ltx ...
+cd . && latex -interaction=nonstopmode -recorder foo.ltx ...
"""), stderr = None)
--- /dev/null
+#!/usr/bin/env python
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+"""
+Test creation of a Tex document with nested includes in a
+subdir that needs to create a fig.pdf.
+Test creation with pdflatex
+
+Test courtesy Rob Managan.
+"""
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+latex = test.where_is('latex')
+epstopdf = test.where_is('epstopdf')
+if not latex:
+ test.skip_test("Could not find 'latex'; skipping test.\n")
+
+if not epstopdf:
+ test.skip_test("Could not find 'epstopdf'; skipping test.\n")
+
+test.subdir(['docs'])
+
+
+test.write(['SConstruct'], """\
+import os
+
+env = Environment(ENV = { 'PATH' : os.environ['PATH'] })
+
+env.PDF('docs/Fig1.eps')
+test = env.PDF(source='docs/test.tex')
+""")
+
+
+test.write(['docs','Fig1.eps'], """\
+%!PS-Adobe-2.0 EPSF-2.0
+%%Title: Fig1.fig
+%%Creator: fig2dev Version 3.2 Patchlevel 4
+%%CreationDate: Tue Apr 25 09:56:11 2006
+%%For: managan@mangrove.llnl.gov (Rob Managan)
+%%BoundingBox: 0 0 98 98
+%%Magnification: 1.0000
+%%EndComments
+/$F2psDict 200 dict def
+$F2psDict begin
+$F2psDict /mtrx matrix put
+/col-1 {0 setgray} bind def
+/col0 {0.000 0.000 0.000 srgb} bind def
+
+end
+save
+newpath 0 98 moveto 0 0 lineto 98 0 lineto 98 98 lineto closepath clip newpath
+-24.9 108.2 translate
+1 -1 scale
+
+/cp {closepath} bind def
+/ef {eofill} bind def
+/gr {grestore} bind def
+/gs {gsave} bind defThe Oxygen Isotopic Composition of Captured Solar Wind: First Results\rfrom the GENESIS Mission
+/rs {restore} bind def
+/l {lineto} bind def
+/m {moveto} bind def
+/rm {rmoveto} bind def
+/n {newpath} bind def
+/s {stroke} bind def
+/slc {setlinecap} bind def
+/slj {setlinejoin} bind def
+/slw {setlinewidth} bind def
+/srgb {setrgbcolor} bind def
+/sc {scale} bind def
+/sf {setfont} bind def
+/scf {scalefont} bind def
+/tr {translate} bind def
+ /DrawEllipse {
+ /endangle exch def
+ /startangle exch def
+ /yrad exch def
+ /xrad exch def
+ /y exch def
+ /x exch def
+ /savematrix mtrx currentmatrix def
+ x y tr xrad yrad sc 0 0 1 startangle endangle arc
+ closepath
+ savematrix setmatrix
+ } def
+
+/$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def
+/$F2psEnd {$F2psEnteredState restore end} def
+
+$F2psBegin
+10 setmiterlimit
+ 0.06299 0.06299 sc
+%
+% Fig objects follow
+%
+7.500 slw
+% Ellipse
+n 1170 945 766 766 0 360 DrawEllipse gs col0 s gr
+
+$F2psEnd
+rs
+""")
+
+
+
+test.write(['docs','test.tex'],
+r"""\documentclass{report}
+
+\usepackage{graphicx}
+\usepackage{epsfig,color} % for .tex version of figures if we go that way
+
+\begin{document}
+
+\title{Report Title}
+
+\author{A. N. Author}
+
+\maketitle
+
+\begin{abstract}
+there is no abstract
+\end{abstract}
+
+\chapter{Introduction}
+
+The introduction is short.
+
+\section{Acknowledgements}
+
+The Acknowledgements are shown as well.
+
+To get a hard copy of this report call me.
+
+\begin{figure}[htbp]
+\begin{center}
+\includegraphics{Fig1}
+\caption{Zone and Node indexing}
+\label{fig1}
+\end{center}
+\end{figure}
+
+All done now.
+
+\end{document}
+""")
+
+# makeindex will write status messages to stderr (grrr...), so ignore it.
+test.run(arguments = '.', stderr=None)
+
+
+# All (?) the files we expect will get created in the docs directory
+files = [
+ 'docs/test.aux',
+ 'docs/test.log',
+ 'docs/test.pdf',
+]
+
+for f in files:
+ test.must_exist([ f])
+
+#test.must_not_exist(['docs/Fig1.pdf',])
+
+test.pass_test()