From e980f0196884fc57563967f57f5845f4c7274df4 Mon Sep 17 00:00:00 2001 From: Robert Managan Date: Thu, 14 Jun 2012 10:20:17 -0700 Subject: Add support for the biblatex package; search for new keywards to get side effects and dependencies right --- src/CHANGES.txt | 1 + src/engine/SCons/Scanner/LaTeX.py | 5 +- src/engine/SCons/Tool/tex.py | 16 +++--- test/TEX/biblatex.py | 118 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 132 insertions(+), 8 deletions(-) create mode 100755 test/TEX/biblatex.py diff --git a/src/CHANGES.txt b/src/CHANGES.txt index f759622..605af5b 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -28,6 +28,7 @@ RELEASE 2.X.X - From Rob Managan: - Updated the TeX builder to support LaTeX's multibib package. + - Updated the TeX build to support LeTeX's biblatex package. From Arve Knudsen: - Test for FORTRANPPFILESUFFIXES (#2129). diff --git a/src/engine/SCons/Scanner/LaTeX.py b/src/engine/SCons/Scanner/LaTeX.py index 2f0b263..2cb1ed5 100644 --- a/src/engine/SCons/Scanner/LaTeX.py +++ b/src/engine/SCons/Scanner/LaTeX.py @@ -159,6 +159,9 @@ class LaTeX(SCons.Scanner.Base): 'includegraphics': 'TEXINPUTS', 'bibliography': 'BIBINPUTS', 'bibliographystyle': 'BSTINPUTS', + 'addbibresource': 'BIBINPUTS', + 'addglobalbib': 'BIBINPUTS', + 'addsectionbib': 'BIBINPUTS', 'makeindex': 'INDEXSTYLE', 'usepackage': 'TEXINPUTS', 'lstinputlisting': 'TEXINPUTS'} @@ -172,7 +175,7 @@ class LaTeX(SCons.Scanner.Base): # line followed by one or more newline characters (i.e. blank # lines), interfering with a match on the next line. # add option for whitespace before the '[options]' or the '{filename}' - regex = r'^[^%\n]*\\(include|includegraphics(?:\s*\[[^\]]+\])?|lstinputlisting(?:\[[^\]]+\])?|input|bibliography|usepackage)\s*{([^}]*)}' + regex = r'^[^%\n]*\\(include|includegraphics(?:\s*\[[^\]]+\])?|lstinputlisting(?:\[[^\]]+\])?|input|bibliography|addbibresource|addglobalbib|addsectionbib|usepackage)\s*{([^}]*)}' self.cre = re.compile(regex, re.M) self.comment_re = re.compile(r'^((?:(?:\\%)|[^%\n])*)(.*)$', re.M) diff --git a/src/engine/SCons/Tool/tex.py b/src/engine/SCons/Tool/tex.py index 0d871ad..83de5bb 100644 --- a/src/engine/SCons/Tool/tex.py +++ b/src/engine/SCons/Tool/tex.py @@ -62,7 +62,7 @@ all_suffixes = check_suffixes + ['.bbl', '.idx', '.nlo', '.glo', '.acn'] # or outputs that require rerunning latex # # search for all .aux files opened by latex (recorded in the .fls file) -openout_aux_re = re.compile(r"INPUT *(.*\.aux)") +openout_aux_re = re.compile(r"OUTPUT *(.*\.aux)") #printindex_re = re.compile(r"^[^%]*\\printindex", re.MULTILINE) #printnomenclature_re = re.compile(r"^[^%]*\\printnomenclature", re.MULTILINE) @@ -87,6 +87,7 @@ makeindex_re = re.compile(r"^[^%\n]*\\makeindex", re.MULTILINE) bibliography_re = re.compile(r"^[^%\n]*\\bibliography", re.MULTILINE) bibunit_re = re.compile(r"^[^%\n]*\\begin\{bibunit\}", re.MULTILINE) multibib_re = re.compile(r"^[^%\n]*\\newcites\{([^\}]*)\}", re.MULTILINE) +addbibresource_re = re.compile(r"^[^%\n]*\\(addbibresource|addglobalbib|addsectionbib)", re.MULTILINE) listoffigures_re = re.compile(r"^[^%\n]*\\listoffigures", re.MULTILINE) listoftables_re = re.compile(r"^[^%\n]*\\listoftables", re.MULTILINE) hyperref_re = re.compile(r"^[^%\n]*\\usepackage.*\{hyperref\}", re.MULTILINE) @@ -317,8 +318,8 @@ def InternalLaTeXAuxAction(XXXLaTeXAction, target = None, source= None, env=None result = BibTeXAction(bibfile, bibfile, env) if result != 0: check_file_error_message(env['BIBTEX'], 'blg') - #must_rerun_latex = must_rerun_latex or check_MD5(suffix_nodes['.bbl'],'.bbl') must_rerun_latex = True + # Now decide if latex will need to be run again due to index. if check_MD5(suffix_nodes['.idx'],'.idx') or (count == 1 and run_makeindex): # We must run makeindex @@ -630,6 +631,7 @@ def tex_emitter_core(target, source, env, graphics_extensions): bibliography_re, bibunit_re, multibib_re, + addbibresource_re, tableofcontents_re, listoffigures_re, listoftables_re, @@ -646,6 +648,7 @@ def tex_emitter_core(target, source, env, graphics_extensions): ['.bbl', '.blg','bibliography'], ['.bbl', '.blg','bibunit'], ['.bbl', '.blg','multibib'], + ['.bbl', '.blg','addbibresource'], ['.toc','contents'], ['.lof','figures'], ['.lot','tables'], @@ -698,10 +701,9 @@ def tex_emitter_core(target, source, env, graphics_extensions): file_list = glob.glob(file_basename) # remove the suffix '.aux' for i in range(len(file_list)): - file_list[i] = SCons.Util.splitext(file_list[i])[0] + file_list.append(SCons.Util.splitext(file_list[i])[0]) # for multibib we need a list of files if suffix_list[-1] == 'multibib': - file_list = [] for multibibmatch in multibib_re.finditer(content): if Verbose: print "multibib match ",multibibmatch.group(1) @@ -716,14 +718,14 @@ def tex_emitter_core(target, source, env, graphics_extensions): for suffix in suffix_list[:-1]: env.SideEffect(file_name + suffix,target[0]) if Verbose: - print "side effect :",file_name + suffix + print "side effect tst :",file_name + suffix, " target is ",str(target[0]) env.Clean(target[0],file_name + suffix) for aFile in aux_files: aFile_base = SCons.Util.splitext(aFile)[0] env.SideEffect(aFile_base + '.aux',target[0]) if Verbose: - print "side effect :",aFile_base + '.aux' + print "side effect aux :",aFile_base + '.aux' env.Clean(target[0],aFile_base + '.aux') # read fls file to get all other files that latex creates and will read on the next pass # remove files from list that we explicitly dealt with above @@ -736,7 +738,7 @@ def tex_emitter_core(target, source, env, graphics_extensions): out_files.remove(filename) env.SideEffect(out_files,target[0]) if Verbose: - print "side effect :",out_files + print "side effect fls :",out_files env.Clean(target[0],out_files) return (target, source) diff --git a/test/TEX/biblatex.py b/test/TEX/biblatex.py new file mode 100755 index 0000000..35c3997 --- /dev/null +++ b/test/TEX/biblatex.py @@ -0,0 +1,118 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test creation of a Tex document that uses the multibib oackage + +Test courtesy Rob Managan. +""" + +import TestSCons +import os + +test = TestSCons.TestSCons() + +latex = test.where_is('pdflatex') +if not latex: + test.skip_test("Could not find 'pdflatex'; skipping test.\n") + +gloss = os.system('kpsewhich biblatex.sty') +if not gloss==0: + test.skip_test("biblatex.sty not installed; skipping test(s).\n") + + +test.write(['SConstruct'], """\ +#!/usr/bin/env python + +import os +env = Environment(ENV=os.environ) +main_output = env.PDF(target='biblatextest.pdf', source='biblatextest.tex') +""") + + +sources_bib_content = r""" +@book{mybook, + title={Title}, + author={Author, A}, + year={%s}, + publisher={Publisher}, +} +""" +test.write(['ref.bib'],sources_bib_content % '2013' ) + +test.write(['biblatextest.tex'],r""" +\documentclass{article} + +\usepackage{biblatex} +\addbibresource{ref.bib} + +\begin{document} + +Hello. This is boring. +\cite{mybook} +And even more boring. + +\printbibliography +\end{document} +""") + + +test.run() + + +# All (?) the files we expect will get created in the docs directory +files = [ + 'biblatextest.aux', + 'biblatextest.bbl', + 'biblatextest.blg', + 'biblatextest-blx.bib', + 'biblatextest.fls', + 'biblatextest.log', + 'biblatextest.pdf', + 'biblatextest.run.xml', +] + +for f in files: + test.must_exist([ f]) + +pdf_output_1 = test.read('biblatextest.pdf') + + + +test.write(['ref.bib'],sources_bib_content % '1982') + +test.run() + +pdf_output_2 = test.read('biblatextest.pdf') + +pdf_output_1 = test.normalize_pdf(pdf_output_1) +pdf_output_2 = test.normalize_pdf(pdf_output_2) + +# If the PDF file is the same as it was previously, then it didn't +# pick up the change from 1981 to 1982, so fail. +test.fail_test(pdf_output_1 == pdf_output_2) + +test.pass_test() -- cgit v0.12