tex

TeX/LaTeX/PDFLaTeX/XeLaTeX support

Example:

def configure(conf):
        conf.load('tex')
        if not conf.env.LATEX:
                conf.fatal('The program LaTex is required')

def build(bld):
        bld(
                features = 'tex',
                type     = 'latex', # pdflatex or xelatex
                source   = 'document.ltx', # mandatory, the source
                outs     = 'ps', # 'pdf' or 'ps pdf'
                deps     = 'crossreferencing.lst', # to give dependencies directly
                prompt   = 1, # 0 for the batch mode
                )

To configure with a special program use:

$ PDFLATEX=luatex waf configure
waflib.Tools.tex.bibunitscan(self)[source]

Parse the inputs and try to find the bibunit dependencies

Returns:list of bibunit files
Return type:list of waflib.Node.Node
waflib.Tools.tex.exts_deps_tex = ['', '.ltx', '.tex', '.bib', '.pdf', '.png', '.eps', '.ps']

List of typical file extensions included in latex files

waflib.Tools.tex.exts_tex = ['.ltx', '.tex']

List of typical file extensions that contain latex

waflib.Tools.tex.re_tex = <_sre.SRE_Pattern object at 0xa17f588>

Regexp for expressions that may include latex files

waflib.Tools.tex.g_bibtex_re = <_sre.SRE_Pattern object at 0xa0339e0>

Regexp for bibtex files

class waflib.Tools.tex.tex(*k, **kw)[source]

Bases: waflib.Task.Task

Compile a tex/latex file.

Inheritance diagram of waflib.Tools.tex.latex, waflib.Tools.tex.xelatex, waflib.Tools.tex.pdflatex

exec_command(cmd, **kw)[source]

Override waflib.Task.Task.exec_command() to execute the command without buffering (latex may prompt for inputs)

Returns:the return code
Return type:int
scan_aux(node)[source]

A recursive regex-based scanner that finds included auxiliary files.

scan()[source]

A recursive regex-based scanner that finds latex dependencies. It uses waflib.Tools.tex.re_tex

Depending on your needs you might want:

  • to change re_tex:

    from waflib.Tools import tex
    tex.re_tex = myregex
    
  • or to change the method scan from the latex tasks:

    from waflib.Task import classes
    classes['latex'].scan = myscanfunction
    
check_status(msg, retcode)[source]

Check an exit status and raise an error with a particular message

Parameters:
  • msg (string) – message to display if the code is non-zero
  • retcode (boolean) – condition
bibfile()[source]

Parse the .aux files to find bibfiles to process. If yes, execute waflib.Tools.tex.tex.bibtex_fun()

bibunits()[source]

Parse the .aux file to find bibunit files. If there are bibunit files, execute waflib.Tools.tex.tex.bibtex_fun().

makeindex()[source]

Look on the filesystem if there is a .idx file to process. If yes, execute waflib.Tools.tex.tex.makeindex_fun()

bibtopic()[source]

Additional .aux files from the bibtopic package

_ = ['MAKEINDEX', 'MAKEINDEXFLAGS', 'SRCFILE']
__doc__ = '\n\tCompile a tex/latex file.\n\n\t.. inheritance-diagram:: waflib.Tools.tex.latex waflib.Tools.tex.xelatex waflib.Tools.tex.pdflatex\n\t'
__module__ = 'waflib.Tools.tex'
bibtex_fun(tsk)

Execute the program bibtex

hcode = '\tdef run(self):\n\t\t"""\n\t\tRuns the TeX build process.\n\n\t\tIt may require multiple passes, depending on the usage of cross-references,\n\t\tbibliographies, content susceptible of needing such passes.\n\t\tThe appropriate TeX compiler is called until the *.aux* files stop changing.\n\n\t\tMakeindex and bibtex are called if necessary.\n\t\t"""\n\t\tenv = self.env\n\n\t\tif not env[\'PROMPT_LATEX\']:\n\t\t\tenv.append_value(\'LATEXFLAGS\', \'-interaction=batchmode\')\n\t\t\tenv.append_value(\'PDFLATEXFLAGS\', \'-interaction=batchmode\')\n\t\t\tenv.append_value(\'XELATEXFLAGS\', \'-interaction=batchmode\')\n\n\t\tfun = self.texfun\n\n\t\tnode = self.inputs[0]\n\t\tsrcfile = node.abspath()\n\n\t\ttexinputs = self.env.TEXINPUTS or \'\'\n\t\tself.TEXINPUTS = node.parent.get_bld().abspath() + os.pathsep + node.parent.get_src().abspath() + os.pathsep + texinputs + os.pathsep\n\n\t\t# important, set the cwd for everybody\n\t\tself.cwd = self.inputs[0].parent.get_bld().abspath()\n\n\t\tLogs.warn(\'first pass on %s\' % self.__class__.__name__)\n\n\t\tself.env.env = {}\n\t\tself.env.env.update(os.environ)\n\t\tself.env.env.update({\'TEXINPUTS\': self.TEXINPUTS})\n\t\tself.env.SRCFILE = srcfile\n\t\tself.check_status(\'error when calling latex\', fun())\n\n\t\tself.aux_nodes = self.scan_aux(node.change_ext(\'.aux\'))\n\t\tself.idx_node = node.change_ext(\'.idx\')\n\n\t\tself.bibtopic()\n\t\tself.bibfile()\n\t\tself.bibunits()\n\t\tself.makeindex()\n\n\t\thash = \'\'\n\t\tfor i in range(10):\n\t\t\t# prevent against infinite loops - one never knows\n\n\t\t\t# watch the contents of file.aux and stop if file.aux does not change anymore\n\t\t\tprev_hash = hash\n\t\t\ttry:\n\t\t\t\thashes = [Utils.h_file(x.abspath()) for x in self.aux_nodes]\n\t\t\t\thash = Utils.h_list(hashes)\n\t\t\texcept (OSError, IOError):\n\t\t\t\tLogs.error(\'could not read aux.h\')\n\t\t\t\tpass\n\t\t\tif hash and hash == prev_hash:\n\t\t\t\tbreak\n\n\t\t\t# run the command\n\t\t\tLogs.warn(\'calling %s\' % self.__class__.__name__)\n\n\t\t\tself.env.env = {}\n\t\t\tself.env.env.update(os.environ)\n\t\t\tself.env.env.update({\'TEXINPUTS\': self.TEXINPUTS})\n\t\t\tself.env.SRCFILE = srcfile\n\t\t\tself.check_status(\'error when calling %s\' % self.__class__.__name__, fun())\n'
makeindex_fun(tsk)

Execute the program makeindex

waflib.Tools.tex.feature(*k)

Decorator: register a task generator method that will be executed when the object attribute ‘feature’ contains the corresponding key(s):

from waflib.Task import feature
@feature('myfeature')
def myfunction(self):
        print('that is my feature!')
def build(bld):
        bld(features='myfeature')
Parameters:k (list of string) – feature names
waflib.Tools.tex.before_method(*k)

Decorator: register a task generator method which will be executed before the functions of given name(s):

from waflib.TaskGen import feature, before
@feature('myfeature')
@before_method('fun2')
def fun1(self):
        print('feature 1!')
@feature('myfeature')
def fun2(self):
        print('feature 2!')
def build(bld):
        bld(features='myfeature')
Parameters:k (list of string) – method names
waflib.Tools.tex.apply_tex(self)[source]

Task generator method

Create waflib.Tools.tex.tex objects, and dvips/dvipdf/pdf2ps tasks if necessary (outs=’ps’, etc).

Feature :tex
waflib.Tools.tex.configure(self)[source]

Try to find the programs tex, latex and others. Do not raise any error if they are not found.

Features defined in this module:

Previous topic

waf_unit_test

Next topic

javaw

This Page