summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/engine/SCons/Scanner/LaTeX.py29
-rw-r--r--src/engine/SCons/Scanner/LaTeXTests.py21
2 files changed, 42 insertions, 8 deletions
diff --git a/src/engine/SCons/Scanner/LaTeX.py b/src/engine/SCons/Scanner/LaTeX.py
index 22a5e87..6451a58 100644
--- a/src/engine/SCons/Scanner/LaTeX.py
+++ b/src/engine/SCons/Scanner/LaTeX.py
@@ -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
diff --git a/src/engine/SCons/Scanner/LaTeXTests.py b/src/engine/SCons/Scanner/LaTeXTests.py
index 3fc121c..1f1861e 100644
--- a/src/engine/SCons/Scanner/LaTeXTests.py
+++ b/src/engine/SCons/Scanner/LaTeXTests.py
@@ -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)
-