Have the LaTeX scanner also look for \includegraphics{} strings.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 20 Nov 2005 03:11:08 +0000 (03:11 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 20 Nov 2005 03:11:08 +0000 (03:11 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@1397 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Scanner/LaTeX.py
src/engine/SCons/Scanner/LaTeXTests.py

index 22a5e871cca2ce50f618ad4c59244878b2f93f0b..6451a58a593cfddf64b31a09f8e234c995cf3cdd 100644 (file)
@@ -1,6 +1,6 @@
 """SCons.Scanner.LaTeX
 
-This module implements the dependency scanner for LaTeX code. 
+This module implements the dependency scanner for LaTeX code.
 
 """
 
@@ -35,15 +35,32 @@ import SCons.Scanner
 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
index 3fc121c452f786eef261e42626d3f1359ce193e3..1f1861e8fb1f4485570d86785ca5a1dc14521a65 100644 (file)
@@ -40,16 +40,24 @@ test.write('test1.latex',"""
 \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
@@ -119,11 +127,21 @@ class LaTeXScannerTestCase2(unittest.TestCase):
          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__":
@@ -131,4 +149,3 @@ if __name__ == "__main__":
     result = runner.run(suite())
     if not result.wasSuccessful():
         sys.exit(1)
-