"""SCons.Scanner.LaTeX
-This module implements the dependency scanner for LaTeX code.
+This module implements the dependency scanner for LaTeX code.
"""
def LaTeXScanner(fs = SCons.Node.FS.default_fs):
"""Return a prototype Scanner instance for scanning LaTeX source files"""
ds = LaTeX(name = "LaTeXScanner",
- suffixes = '$LATEXSUFFIXES',
- path_variable = 'TEXINPUTS',
- regex = '\\\\(?:include|input){([^}]*)}',
- recursive = 0)
+ suffixes = '$LATEXSUFFIXES',
+ path_variable = 'TEXINPUTS',
+ regex = '\\\\(include|includegraphics(?:\[[^\]]+\])?|input){([^}]*)}',
+ recursive = 0)
return ds
class LaTeX(SCons.Scanner.Classic):
+ """Class for scanning LaTeX files for included files.
+
+ Unlike most scanners, which use regular expressions that just
+ return the included file name, this returns a tuple consisting
+ of the keyword for the inclusion ("include", "includegraphics" or
+ "input"), and then the file name itself. Base on a quick look at
+ LaTeX documentation, it seems that we need a should append .tex
+ suffix for "include" and "input" keywords, but leave the file name
+ untouched for "includegraphics."
+ """
+ def latex_name(self, include):
+ filename = include[1]
+ if include[0][:15] != 'includegraphics':
+ filename = filename + '.tex'
+ return filename
+ def sort_key(self, include):
+ return SCons.Node.FS._my_normcase(self.latex_name(include))
def find_include(self, include, source_dir, path):
if callable(path): path=path()
- i = SCons.Node.FS.find_file(include + '.tex',
+ i = SCons.Node.FS.find_file(self.latex_name(include),
(source_dir,) + path)
return i, include
\include{inc1}
\input{inc2}
""")
+
test.write('test2.latex',"""
\include{inc1}
\include{inc3}
""")
+test.write('test3.latex',"""
+\includegraphics{inc4.eps}
+\includegraphics[width=60mm]{inc5.xyz}
+""")
+
test.subdir('subdir')
test.write('inc1.tex',"\n")
test.write('inc2.tex',"\n")
-test.write([ 'subdir', 'inc3.tex'], "\n")
+test.write(['subdir', 'inc3.tex'], "\n")
+test.write(['subdir', 'inc4.eps'], "\n")
+test.write('inc5.xyz', "\n")
# define some helpers:
# copied from CTest.py
headers = ['inc1.tex', 'subdir/inc3.tex']
deps_match(self, deps, headers)
+class LaTeXScannerTestCase3(unittest.TestCase):
+ def runTest(self):
+ env = DummyEnvironment(TEXINPUTS=[test.workpath("subdir")])
+ s = SCons.Scanner.LaTeX.LaTeXScanner()
+ path = s.path(env)
+ deps = s(env.File('test3.latex'), env, path)
+ files = ['subdir/inc4.eps', 'inc5.xyz']
+ deps_match(self, deps, files)
+
def suite():
suite = unittest.TestSuite()
suite.addTest(LaTeXScannerTestCase1())
suite.addTest(LaTeXScannerTestCase2())
+ suite.addTest(LaTeXScannerTestCase3())
return suite
if __name__ == "__main__":
result = runner.run(suite())
if not result.wasSuccessful():
sys.exit(1)
-