PageRenderTime 53ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/scons/scons-local-1.2.0/SCons/Tool/tex.py

http://github.com/zpao/spidernode
Python | 661 lines | 649 code | 1 blank | 11 comment | 8 complexity | 266bd8eb88bbea79a70a348cc7fb2d8b MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, JSON, BSD-2-Clause, BSD-3-Clause
  1. """SCons.Tool.tex
  2. Tool-specific initialization for TeX.
  3. There normally shouldn't be any need to import this module directly.
  4. It will usually be imported through the generic SCons.Tool.Tool()
  5. selection method.
  6. """
  7. #
  8. # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundation
  9. #
  10. # Permission is hereby granted, free of charge, to any person obtaining
  11. # a copy of this software and associated documentation files (the
  12. # "Software"), to deal in the Software without restriction, including
  13. # without limitation the rights to use, copy, modify, merge, publish,
  14. # distribute, sublicense, and/or sell copies of the Software, and to
  15. # permit persons to whom the Software is furnished to do so, subject to
  16. # the following conditions:
  17. #
  18. # The above copyright notice and this permission notice shall be included
  19. # in all copies or substantial portions of the Software.
  20. #
  21. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  22. # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  23. # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. #
  29. __revision__ = "src/engine/SCons/Tool/tex.py 3842 2008/12/20 22:59:52 scons"
  30. import os.path
  31. import re
  32. import string
  33. import shutil
  34. import SCons.Action
  35. import SCons.Node
  36. import SCons.Node.FS
  37. import SCons.Util
  38. import SCons.Scanner.LaTeX
  39. Verbose = False
  40. must_rerun_latex = True
  41. # these are files that just need to be checked for changes and then rerun latex
  42. check_suffixes = ['.toc', '.lof', '.lot', '.out', '.nav', '.snm']
  43. # these are files that require bibtex or makeindex to be run when they change
  44. all_suffixes = check_suffixes + ['.bbl', '.idx', '.nlo', '.glo']
  45. #
  46. # regular expressions used to search for Latex features
  47. # or outputs that require rerunning latex
  48. #
  49. # search for all .aux files opened by latex (recorded in the .log file)
  50. openout_aux_re = re.compile(r"\\openout.*`(.*\.aux)'")
  51. #printindex_re = re.compile(r"^[^%]*\\printindex", re.MULTILINE)
  52. #printnomenclature_re = re.compile(r"^[^%]*\\printnomenclature", re.MULTILINE)
  53. #printglossary_re = re.compile(r"^[^%]*\\printglossary", re.MULTILINE)
  54. # search to find rerun warnings
  55. warning_rerun_str = '(^LaTeX Warning:.*Rerun)|(^Package \w+ Warning:.*Rerun)'
  56. warning_rerun_re = re.compile(warning_rerun_str, re.MULTILINE)
  57. # search to find citation rerun warnings
  58. rerun_citations_str = "^LaTeX Warning:.*\n.*Rerun to get citations correct"
  59. rerun_citations_re = re.compile(rerun_citations_str, re.MULTILINE)
  60. # search to find undefined references or citations warnings
  61. undefined_references_str = '(^LaTeX Warning:.*undefined references)|(^Package \w+ Warning:.*undefined citations)'
  62. undefined_references_re = re.compile(undefined_references_str, re.MULTILINE)
  63. # used by the emitter
  64. auxfile_re = re.compile(r".", re.MULTILINE)
  65. tableofcontents_re = re.compile(r"^[^%\n]*\\tableofcontents", re.MULTILINE)
  66. makeindex_re = re.compile(r"^[^%\n]*\\makeindex", re.MULTILINE)
  67. bibliography_re = re.compile(r"^[^%\n]*\\bibliography", re.MULTILINE)
  68. listoffigures_re = re.compile(r"^[^%\n]*\\listoffigures", re.MULTILINE)
  69. listoftables_re = re.compile(r"^[^%\n]*\\listoftables", re.MULTILINE)
  70. hyperref_re = re.compile(r"^[^%\n]*\\usepackage.*\{hyperref\}", re.MULTILINE)
  71. makenomenclature_re = re.compile(r"^[^%\n]*\\makenomenclature", re.MULTILINE)
  72. makeglossary_re = re.compile(r"^[^%\n]*\\makeglossary", re.MULTILINE)
  73. beamer_re = re.compile(r"^[^%\n]*\\documentclass\{beamer\}", re.MULTILINE)
  74. # search to find all files included by Latex
  75. include_re = re.compile(r'^[^%\n]*\\(?:include|input){([^}]*)}', re.MULTILINE)
  76. # search to find all graphics files included by Latex
  77. includegraphics_re = re.compile(r'^[^%\n]*\\(?:includegraphics(?:\[[^\]]+\])?){([^}]*)}', re.MULTILINE)
  78. # search to find all files opened by Latex (recorded in .log file)
  79. openout_re = re.compile(r"\\openout.*`(.*)'")
  80. # list of graphics file extensions for TeX and LaTeX
  81. TexGraphics = SCons.Scanner.LaTeX.TexGraphics
  82. LatexGraphics = SCons.Scanner.LaTeX.LatexGraphics
  83. # An Action sufficient to build any generic tex file.
  84. TeXAction = None
  85. # An action to build a latex file. This action might be needed more
  86. # than once if we are dealing with labels and bibtex.
  87. LaTeXAction = None
  88. # An action to run BibTeX on a file.
  89. BibTeXAction = None
  90. # An action to run MakeIndex on a file.
  91. MakeIndexAction = None
  92. # An action to run MakeIndex (for nomencl) on a file.
  93. MakeNclAction = None
  94. # An action to run MakeIndex (for glossary) on a file.
  95. MakeGlossaryAction = None
  96. # Used as a return value of modify_env_var if the variable is not set.
  97. _null = SCons.Scanner.LaTeX._null
  98. modify_env_var = SCons.Scanner.LaTeX.modify_env_var
  99. def FindFile(name,suffixes,paths,env,requireExt=False):
  100. if requireExt:
  101. name = SCons.Util.splitext(name)[0]
  102. if Verbose:
  103. print " searching for '%s' with extensions: " % name,suffixes
  104. for path in paths:
  105. testName = os.path.join(path,name)
  106. if Verbose:
  107. print " look for '%s'" % testName
  108. if os.path.exists(testName):
  109. if Verbose:
  110. print " found '%s'" % testName
  111. return env.fs.File(testName)
  112. else:
  113. name_ext = SCons.Util.splitext(testName)[1]
  114. if name_ext:
  115. continue
  116. # if no suffix try adding those passed in
  117. for suffix in suffixes:
  118. testNameExt = testName + suffix
  119. if Verbose:
  120. print " look for '%s'" % testNameExt
  121. if os.path.exists(testNameExt):
  122. if Verbose:
  123. print " found '%s'" % testNameExt
  124. return env.fs.File(testNameExt)
  125. if Verbose:
  126. print " did not find '%s'" % name
  127. return None
  128. def InternalLaTeXAuxAction(XXXLaTeXAction, target = None, source= None, env=None):
  129. """A builder for LaTeX files that checks the output in the aux file
  130. and decides how many times to use LaTeXAction, and BibTeXAction."""
  131. global must_rerun_latex
  132. # This routine is called with two actions. In this file for DVI builds
  133. # with LaTeXAction and from the pdflatex.py with PDFLaTeXAction
  134. # set this up now for the case where the user requests a different extension
  135. # for the target filename
  136. if (XXXLaTeXAction == LaTeXAction):
  137. callerSuffix = ".dvi"
  138. else:
  139. callerSuffix = env['PDFSUFFIX']
  140. basename = SCons.Util.splitext(str(source[0]))[0]
  141. basedir = os.path.split(str(source[0]))[0]
  142. basefile = os.path.split(str(basename))[1]
  143. abspath = os.path.abspath(basedir)
  144. targetext = os.path.splitext(str(target[0]))[1]
  145. targetdir = os.path.split(str(target[0]))[0]
  146. saved_env = {}
  147. for var in SCons.Scanner.LaTeX.LaTeX.env_variables:
  148. saved_env[var] = modify_env_var(env, var, abspath)
  149. # Create base file names with the target directory since the auxiliary files
  150. # will be made there. That's because the *COM variables have the cd
  151. # command in the prolog. We check
  152. # for the existence of files before opening them--even ones like the
  153. # aux file that TeX always creates--to make it possible to write tests
  154. # with stubs that don't necessarily generate all of the same files.
  155. targetbase = os.path.join(targetdir, basefile)
  156. # if there is a \makeindex there will be a .idx and thus
  157. # we have to run makeindex at least once to keep the build
  158. # happy even if there is no index.
  159. # Same for glossaries and nomenclature
  160. src_content = source[0].get_contents()
  161. run_makeindex = makeindex_re.search(src_content) and not os.path.exists(targetbase + '.idx')
  162. run_nomenclature = makenomenclature_re.search(src_content) and not os.path.exists(targetbase + '.nlo')
  163. run_glossary = makeglossary_re.search(src_content) and not os.path.exists(targetbase + '.glo')
  164. saved_hashes = {}
  165. suffix_nodes = {}
  166. for suffix in all_suffixes:
  167. theNode = env.fs.File(targetbase + suffix)
  168. suffix_nodes[suffix] = theNode
  169. saved_hashes[suffix] = theNode.get_csig()
  170. if Verbose:
  171. print "hashes: ",saved_hashes
  172. must_rerun_latex = True
  173. #
  174. # routine to update MD5 hash and compare
  175. #
  176. # TODO(1.5): nested scopes
  177. def check_MD5(filenode, suffix, saved_hashes=saved_hashes, targetbase=targetbase):
  178. global must_rerun_latex
  179. # two calls to clear old csig
  180. filenode.clear_memoized_values()
  181. filenode.ninfo = filenode.new_ninfo()
  182. new_md5 = filenode.get_csig()
  183. if saved_hashes[suffix] == new_md5:
  184. if Verbose:
  185. print "file %s not changed" % (targetbase+suffix)
  186. return False # unchanged
  187. saved_hashes[suffix] = new_md5
  188. must_rerun_latex = True
  189. if Verbose:
  190. print "file %s changed, rerunning Latex, new hash = " % (targetbase+suffix), new_md5
  191. return True # changed
  192. # generate the file name that latex will generate
  193. resultfilename = targetbase + callerSuffix
  194. count = 0
  195. while (must_rerun_latex and count < int(env.subst('$LATEXRETRIES'))) :
  196. result = XXXLaTeXAction(target, source, env)
  197. if result != 0:
  198. return result
  199. count = count + 1
  200. must_rerun_latex = False
  201. # Decide if various things need to be run, or run again.
  202. # Read the log file to find all .aux files
  203. logfilename = targetbase + '.log'
  204. logContent = ''
  205. auxfiles = []
  206. if os.path.exists(logfilename):
  207. logContent = open(logfilename, "rb").read()
  208. auxfiles = openout_aux_re.findall(logContent)
  209. # Now decide if bibtex will need to be run.
  210. # The information that bibtex reads from the .aux file is
  211. # pass-independent. If we find (below) that the .bbl file is unchanged,
  212. # then the last latex saw a correct bibliography.
  213. # Therefore only do this on the first pass
  214. if count == 1:
  215. for auxfilename in auxfiles:
  216. target_aux = os.path.join(targetdir, auxfilename)
  217. if os.path.exists(target_aux):
  218. content = open(target_aux, "rb").read()
  219. if string.find(content, "bibdata") != -1:
  220. if Verbose:
  221. print "Need to run bibtex"
  222. bibfile = env.fs.File(targetbase)
  223. result = BibTeXAction(bibfile, bibfile, env)
  224. if result != 0:
  225. return result
  226. must_rerun_latex = check_MD5(suffix_nodes['.bbl'],'.bbl')
  227. break
  228. # Now decide if latex will need to be run again due to index.
  229. if check_MD5(suffix_nodes['.idx'],'.idx') or (count == 1 and run_makeindex):
  230. # We must run makeindex
  231. if Verbose:
  232. print "Need to run makeindex"
  233. idxfile = suffix_nodes['.idx']
  234. result = MakeIndexAction(idxfile, idxfile, env)
  235. if result != 0:
  236. return result
  237. # TO-DO: need to add a way for the user to extend this list for whatever
  238. # auxiliary files they create in other (or their own) packages
  239. # Harder is case is where an action needs to be called -- that should be rare (I hope?)
  240. for index in check_suffixes:
  241. check_MD5(suffix_nodes[index],index)
  242. # Now decide if latex will need to be run again due to nomenclature.
  243. if check_MD5(suffix_nodes['.nlo'],'.nlo') or (count == 1 and run_nomenclature):
  244. # We must run makeindex
  245. if Verbose:
  246. print "Need to run makeindex for nomenclature"
  247. nclfile = suffix_nodes['.nlo']
  248. result = MakeNclAction(nclfile, nclfile, env)
  249. if result != 0:
  250. return result
  251. # Now decide if latex will need to be run again due to glossary.
  252. if check_MD5(suffix_nodes['.glo'],'.glo') or (count == 1 and run_glossary):
  253. # We must run makeindex
  254. if Verbose:
  255. print "Need to run makeindex for glossary"
  256. glofile = suffix_nodes['.glo']
  257. result = MakeGlossaryAction(glofile, glofile, env)
  258. if result != 0:
  259. return result
  260. # Now decide if latex needs to be run yet again to resolve warnings.
  261. if warning_rerun_re.search(logContent):
  262. must_rerun_latex = True
  263. if Verbose:
  264. print "rerun Latex due to latex or package rerun warning"
  265. if rerun_citations_re.search(logContent):
  266. must_rerun_latex = True
  267. if Verbose:
  268. print "rerun Latex due to 'Rerun to get citations correct' warning"
  269. if undefined_references_re.search(logContent):
  270. must_rerun_latex = True
  271. if Verbose:
  272. print "rerun Latex due to undefined references or citations"
  273. if (count >= int(env.subst('$LATEXRETRIES')) and must_rerun_latex):
  274. print "reached max number of retries on Latex ,",int(env.subst('$LATEXRETRIES'))
  275. # end of while loop
  276. # rename Latex's output to what the target name is
  277. if not (str(target[0]) == resultfilename and os.path.exists(resultfilename)):
  278. if os.path.exists(resultfilename):
  279. print "move %s to %s" % (resultfilename, str(target[0]), )
  280. shutil.move(resultfilename,str(target[0]))
  281. # Original comment (when TEXPICTS was not restored):
  282. # The TEXPICTS enviroment variable is needed by a dvi -> pdf step
  283. # later on Mac OSX so leave it
  284. #
  285. # It is also used when searching for pictures (implicit dependencies).
  286. # Why not set the variable again in the respective builder instead
  287. # of leaving local modifications in the environment? What if multiple
  288. # latex builds in different directories need different TEXPICTS?
  289. for var in SCons.Scanner.LaTeX.LaTeX.env_variables:
  290. if var == 'TEXPICTS':
  291. continue
  292. if saved_env[var] is _null:
  293. try:
  294. del env['ENV'][var]
  295. except KeyError:
  296. pass # was never set
  297. else:
  298. env['ENV'][var] = saved_env[var]
  299. return result
  300. def LaTeXAuxAction(target = None, source= None, env=None):
  301. result = InternalLaTeXAuxAction( LaTeXAction, target, source, env )
  302. return result
  303. LaTeX_re = re.compile("\\\\document(style|class)")
  304. def is_LaTeX(flist):
  305. # Scan a file list to decide if it's TeX- or LaTeX-flavored.
  306. for f in flist:
  307. content = f.get_contents()
  308. if LaTeX_re.search(content):
  309. return 1
  310. return 0
  311. def TeXLaTeXFunction(target = None, source= None, env=None):
  312. """A builder for TeX and LaTeX that scans the source file to
  313. decide the "flavor" of the source and then executes the appropriate
  314. program."""
  315. if is_LaTeX(source):
  316. result = LaTeXAuxAction(target,source,env)
  317. else:
  318. result = TeXAction(target,source,env)
  319. return result
  320. def TeXLaTeXStrFunction(target = None, source= None, env=None):
  321. """A strfunction for TeX and LaTeX that scans the source file to
  322. decide the "flavor" of the source and then returns the appropriate
  323. command string."""
  324. if env.GetOption("no_exec"):
  325. if is_LaTeX(source):
  326. result = env.subst('$LATEXCOM',0,target,source)+" ..."
  327. else:
  328. result = env.subst("$TEXCOM",0,target,source)+" ..."
  329. else:
  330. result = ''
  331. return result
  332. def tex_eps_emitter(target, source, env):
  333. """An emitter for TeX and LaTeX sources when
  334. executing tex or latex. It will accept .ps and .eps
  335. graphics files
  336. """
  337. (target, source) = tex_emitter_core(target, source, env, TexGraphics)
  338. return (target, source)
  339. def tex_pdf_emitter(target, source, env):
  340. """An emitter for TeX and LaTeX sources when
  341. executing pdftex or pdflatex. It will accept graphics
  342. files of types .pdf, .jpg, .png, .gif, and .tif
  343. """
  344. (target, source) = tex_emitter_core(target, source, env, LatexGraphics)
  345. return (target, source)
  346. def ScanFiles(theFile, target, paths, file_tests, file_tests_search, env, graphics_extensions, targetdir):
  347. # for theFile (a Node) update any file_tests and search for graphics files
  348. # then find all included files and call ScanFiles for each of them
  349. content = theFile.get_contents()
  350. if Verbose:
  351. print " scanning ",str(theFile)
  352. for i in range(len(file_tests_search)):
  353. if file_tests[i][0] == None:
  354. file_tests[i][0] = file_tests_search[i].search(content)
  355. # For each file see if any graphics files are included
  356. # and set up target to create ,pdf graphic
  357. # is this is in pdflatex toolchain
  358. graphic_files = includegraphics_re.findall(content)
  359. if Verbose:
  360. print "graphics files in '%s': "%str(theFile),graphic_files
  361. for graphFile in graphic_files:
  362. graphicNode = FindFile(graphFile,graphics_extensions,paths,env,requireExt=True)
  363. # if building with pdflatex see if we need to build the .pdf version of the graphic file
  364. # I should probably come up with a better way to tell which builder we are using.
  365. if graphics_extensions == LatexGraphics:
  366. # see if we can build this graphics file by epstopdf
  367. graphicSrc = FindFile(graphFile,TexGraphics,paths,env,requireExt=True)
  368. # it seems that FindFile checks with no extension added
  369. # so if the extension is included in the name then both searches find it
  370. # we don't want to try to build a .pdf from a .pdf so make sure src!=file wanted
  371. if (graphicSrc != None) and (graphicSrc != graphicNode):
  372. if Verbose:
  373. if graphicNode == None:
  374. print "need to build '%s' by epstopdf %s -o %s" % (graphFile,graphicSrc,graphFile)
  375. else:
  376. print "no need to build '%s', but source file %s exists" % (graphicNode,graphicSrc)
  377. graphicNode = env.PDF(graphicSrc)
  378. env.Depends(target[0],graphicNode)
  379. # recursively call this on each of the included files
  380. inc_files = [ ]
  381. inc_files.extend( include_re.findall(content) )
  382. if Verbose:
  383. print "files included by '%s': "%str(theFile),inc_files
  384. # inc_files is list of file names as given. need to find them
  385. # using TEXINPUTS paths.
  386. for src in inc_files:
  387. srcNode = srcNode = FindFile(src,['.tex','.ltx','.latex'],paths,env,requireExt=False)
  388. if srcNode != None:
  389. file_test = ScanFiles(srcNode, target, paths, file_tests, file_tests_search, env, graphics_extensions, targetdir)
  390. if Verbose:
  391. print " done scanning ",str(theFile)
  392. return file_tests
  393. def tex_emitter_core(target, source, env, graphics_extensions):
  394. """An emitter for TeX and LaTeX sources.
  395. For LaTeX sources we try and find the common created files that
  396. are needed on subsequent runs of latex to finish tables of contents,
  397. bibliographies, indices, lists of figures, and hyperlink references.
  398. """
  399. targetbase = SCons.Util.splitext(str(target[0]))[0]
  400. basename = SCons.Util.splitext(str(source[0]))[0]
  401. basefile = os.path.split(str(basename))[1]
  402. basedir = os.path.split(str(source[0]))[0]
  403. targetdir = os.path.split(str(target[0]))[0]
  404. abspath = os.path.abspath(basedir)
  405. target[0].attributes.path = abspath
  406. #
  407. # file names we will make use of in searching the sources and log file
  408. #
  409. emit_suffixes = ['.aux', '.log', '.ilg', '.blg', '.nls', '.nlg', '.gls', '.glg'] + all_suffixes
  410. auxfilename = targetbase + '.aux'
  411. logfilename = targetbase + '.log'
  412. env.SideEffect(auxfilename,target[0])
  413. env.SideEffect(logfilename,target[0])
  414. env.Clean(target[0],auxfilename)
  415. env.Clean(target[0],logfilename)
  416. content = source[0].get_contents()
  417. idx_exists = os.path.exists(targetbase + '.idx')
  418. nlo_exists = os.path.exists(targetbase + '.nlo')
  419. glo_exists = os.path.exists(targetbase + '.glo')
  420. # set up list with the regular expressions
  421. # we use to find features used
  422. file_tests_search = [auxfile_re,
  423. makeindex_re,
  424. bibliography_re,
  425. tableofcontents_re,
  426. listoffigures_re,
  427. listoftables_re,
  428. hyperref_re,
  429. makenomenclature_re,
  430. makeglossary_re,
  431. beamer_re ]
  432. # set up list with the file suffixes that need emitting
  433. # when a feature is found
  434. file_tests_suff = [['.aux'],
  435. ['.idx', '.ind', '.ilg'],
  436. ['.bbl', '.blg'],
  437. ['.toc'],
  438. ['.lof'],
  439. ['.lot'],
  440. ['.out'],
  441. ['.nlo', '.nls', '.nlg'],
  442. ['.glo', '.gls', '.glg'],
  443. ['.nav', '.snm', '.out', '.toc'] ]
  444. # build the list of lists
  445. file_tests = []
  446. for i in range(len(file_tests_search)):
  447. file_tests.append( [None, file_tests_suff[i]] )
  448. # TO-DO: need to add a way for the user to extend this list for whatever
  449. # auxiliary files they create in other (or their own) packages
  450. # get path list from both env['TEXINPUTS'] and env['ENV']['TEXINPUTS']
  451. savedpath = modify_env_var(env, 'TEXINPUTS', abspath)
  452. paths = env['ENV']['TEXINPUTS']
  453. if SCons.Util.is_List(paths):
  454. pass
  455. else:
  456. # Split at os.pathsep to convert into absolute path
  457. # TODO(1.5)
  458. #paths = paths.split(os.pathsep)
  459. paths = string.split(paths, os.pathsep)
  460. # now that we have the path list restore the env
  461. if savedpath is _null:
  462. try:
  463. del env['ENV']['TEXINPUTS']
  464. except KeyError:
  465. pass # was never set
  466. else:
  467. env['ENV']['TEXINPUTS'] = savedpath
  468. if Verbose:
  469. print "search path ",paths
  470. file_tests = ScanFiles(source[0], target, paths, file_tests, file_tests_search, env, graphics_extensions, targetdir)
  471. for (theSearch,suffix_list) in file_tests:
  472. if theSearch:
  473. for suffix in suffix_list:
  474. env.SideEffect(targetbase + suffix,target[0])
  475. env.Clean(target[0],targetbase + suffix)
  476. # read log file to get all other files that latex creates and will read on the next pass
  477. if os.path.exists(logfilename):
  478. content = open(logfilename, "rb").read()
  479. out_files = openout_re.findall(content)
  480. env.SideEffect(out_files,target[0])
  481. env.Clean(target[0],out_files)
  482. return (target, source)
  483. TeXLaTeXAction = None
  484. def generate(env):
  485. """Add Builders and construction variables for TeX to an Environment."""
  486. # A generic tex file Action, sufficient for all tex files.
  487. global TeXAction
  488. if TeXAction is None:
  489. TeXAction = SCons.Action.Action("$TEXCOM", "$TEXCOMSTR")
  490. # An Action to build a latex file. This might be needed more
  491. # than once if we are dealing with labels and bibtex.
  492. global LaTeXAction
  493. if LaTeXAction is None:
  494. LaTeXAction = SCons.Action.Action("$LATEXCOM", "$LATEXCOMSTR")
  495. # Define an action to run BibTeX on a file.
  496. global BibTeXAction
  497. if BibTeXAction is None:
  498. BibTeXAction = SCons.Action.Action("$BIBTEXCOM", "$BIBTEXCOMSTR")
  499. # Define an action to run MakeIndex on a file.
  500. global MakeIndexAction
  501. if MakeIndexAction is None:
  502. MakeIndexAction = SCons.Action.Action("$MAKEINDEXCOM", "$MAKEINDEXCOMSTR")
  503. # Define an action to run MakeIndex on a file for nomenclatures.
  504. global MakeNclAction
  505. if MakeNclAction is None:
  506. MakeNclAction = SCons.Action.Action("$MAKENCLCOM", "$MAKENCLCOMSTR")
  507. # Define an action to run MakeIndex on a file for glossaries.
  508. global MakeGlossaryAction
  509. if MakeGlossaryAction is None:
  510. MakeGlossaryAction = SCons.Action.Action("$MAKEGLOSSARYCOM", "$MAKEGLOSSARYCOMSTR")
  511. global TeXLaTeXAction
  512. if TeXLaTeXAction is None:
  513. TeXLaTeXAction = SCons.Action.Action(TeXLaTeXFunction,
  514. strfunction=TeXLaTeXStrFunction)
  515. import dvi
  516. dvi.generate(env)
  517. bld = env['BUILDERS']['DVI']
  518. bld.add_action('.tex', TeXLaTeXAction)
  519. bld.add_emitter('.tex', tex_eps_emitter)
  520. env['TEX'] = 'tex'
  521. env['TEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode')
  522. env['TEXCOM'] = 'cd ${TARGET.dir} && $TEX $TEXFLAGS ${SOURCE.file}'
  523. # Duplicate from latex.py. If latex.py goes away, then this is still OK.
  524. env['LATEX'] = 'latex'
  525. env['LATEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode')
  526. env['LATEXCOM'] = 'cd ${TARGET.dir} && $LATEX $LATEXFLAGS ${SOURCE.file}'
  527. env['LATEXRETRIES'] = 3
  528. env['BIBTEX'] = 'bibtex'
  529. env['BIBTEXFLAGS'] = SCons.Util.CLVar('')
  530. env['BIBTEXCOM'] = 'cd ${TARGET.dir} && $BIBTEX $BIBTEXFLAGS ${SOURCE.filebase}'
  531. env['MAKEINDEX'] = 'makeindex'
  532. env['MAKEINDEXFLAGS'] = SCons.Util.CLVar('')
  533. env['MAKEINDEXCOM'] = 'cd ${TARGET.dir} && $MAKEINDEX $MAKEINDEXFLAGS ${SOURCE.file}'
  534. env['MAKEGLOSSARY'] = 'makeindex'
  535. env['MAKEGLOSSARYSTYLE'] = '${SOURCE.filebase}.ist'
  536. env['MAKEGLOSSARYFLAGS'] = SCons.Util.CLVar('-s ${MAKEGLOSSARYSTYLE} -t ${SOURCE.filebase}.glg')
  537. env['MAKEGLOSSARYCOM'] = 'cd ${TARGET.dir} && $MAKEGLOSSARY ${SOURCE.filebase}.glo $MAKEGLOSSARYFLAGS -o ${SOURCE.filebase}.gls'
  538. env['MAKENCL'] = 'makeindex'
  539. env['MAKENCLSTYLE'] = '$nomencl.ist'
  540. env['MAKENCLFLAGS'] = '-s ${MAKENCLSTYLE} -t ${SOURCE.filebase}.nlg'
  541. env['MAKENCLCOM'] = 'cd ${TARGET.dir} && $MAKENCL ${SOURCE.filebase}.nlo $MAKENCLFLAGS -o ${SOURCE.filebase}.nls'
  542. # Duplicate from pdflatex.py. If latex.py goes away, then this is still OK.
  543. env['PDFLATEX'] = 'pdflatex'
  544. env['PDFLATEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode')
  545. env['PDFLATEXCOM'] = 'cd ${TARGET.dir} && $PDFLATEX $PDFLATEXFLAGS ${SOURCE.file}'
  546. def exists(env):
  547. return env.Detect('tex')