summaryrefslogtreecommitdiffstats
path: root/common/latex.py
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2016-11-06 12:02:47 +1100
committerChris Johns <chrisj@rtems.org>2016-11-06 12:02:47 +1100
commit8330198edc3ec08021f358c3030266194278c5a2 (patch)
treedfab1a147e46f0bc95abfd1d75863da52c1c4e15 /common/latex.py
parentwaf: note about tex noise when running configure. (diff)
downloadrtems-docs-8330198edc3ec08021f358c3030266194278c5a2.tar.bz2
waf: Add support to handle missing Latex packages on hosts they are not available on.
It appears the support for texlive packages on some hosts is variable. This patch lets us add missing packages to our source tree so a PDF can be built on those hosts. The quality of the PDFs created may vary as some short cuts may have been take. For example lato is a font and only the sty file as been added and not the actual font which means it's use will default to another font.
Diffstat (limited to 'common/latex.py')
-rw-r--r--common/latex.py145
1 files changed, 145 insertions, 0 deletions
diff --git a/common/latex.py b/common/latex.py
new file mode 100644
index 0000000..186a64f
--- /dev/null
+++ b/common/latex.py
@@ -0,0 +1,145 @@
+#
+# Support for Latex used to build the PDF output format.
+#
+
+import os
+import platform
+import re
+
+package_test_preamble = ['\\newif\\ifsphinxKeepOldNames \\sphinxKeepOldNamestrue',
+ '\documentclass[a4paper,11pt,english]{report}']
+package_test_postamble = ['\\begin{document} test \\end{document}']
+package_tests = {
+ 'Bjarne' : ['\\usepackage[Bjarne]{fncychap}'],
+ 'alltt' : ['\\usepackage{alltt}'],
+ 'amsmath' : ['\\usepackage{amsmath}'],
+ 'amssymb' : ['\\usepackage{amssymb}'],
+ 'amstext' : ['\\usepackage{amstext}'],
+ 'array' : ['\\usepackage{array}'],
+ 'atbegshi' : ['\\usepackage{atbegshi}'],
+ 'babel' : ['\\usepackage{babel}'],
+ 'babel' : ['\\usepackage{babel}'],
+ 'calc' : ['\\usepackage{calc}'],
+ 'capt-of' : ['\\usepackage{capt-of}'],
+ 'charter' : ['\\usepackage{charter}'],
+ 'cmap' : ['\\usepackage{cmap}'],
+ 'color' : ['\\usepackage{color}'],
+ 'eqparbox' : ['\\usepackage{eqparbox}'],
+ 'etoolbox' : ['\\usepackage{etoolbox}'],
+ 'fancybox' : ['\\usepackage{fancybox}'],
+ 'fancyhdr' : ['\\usepackage{fancyhdr}'],
+ 'fancyvrb' : ['\\usepackage{fancyvrb}'],
+ 'float' : ['\\usepackage{float}'],
+ 'fncychap' : ['\\usepackage{fncychap}'],
+ 'fontenc' : ['\\usepackage[T1]{fontenc}'],
+ 'footnote' : ['\\usepackage{footnote}'],
+ 'framed' : ['\\usepackage{framed}'],
+ 'graphicx' : ['\\usepackage{graphicx}'],
+ 'hypcap' : ['\\usepackage{hyperref}',
+ '\\usepackage{hypcap}'],
+ 'hyperref' : ['\\usepackage{hyperref}'],
+ 'ifplatform' : ['\\usepackage{ifplatform}'],
+ 'ifthen' : ['\\usepackage{ifthen}'],
+ 'inconsolata' : ['\\usepackage{inconsolata}'],
+ 'inputenc' : ['\\usepackage{inputenc}'],
+ 'keyval' : ['\\usepackage{keyval}'],
+ 'kvoptions' : ['\\usepackage{kvoptions}'],
+ 'lato' : ['\\usepackage{lato}'],
+ 'lineno' : ['\\usepackage{lineno}'],
+ 'longtable' : ['\\usepackage{longtable}'],
+ 'makeidx' : ['\\usepackage{makeidx}'],
+ 'multirow' : ['\\usepackage{multirow}'],
+ 'parskip' : ['\\usepackage{parskip}'],
+ 'pdftexcmds' : ['\\usepackage{pdftexcmds}'],
+ 'textcomp' : ['\\usepackage{textcomp}'],
+ 'threeparttable' : ['\\usepackage{threeparttable}'],
+ 'times' : ['\\usepackage{times}'],
+ 'titlesec' : ['\\usepackage{titlesec}'],
+ 'upquote' : ['\\usepackage{upquote}'],
+ 'utf8' : ['\\usepackage[utf8]{inputenc}'],
+ 'wrapfig' : ['\\usepackage{wrapfig}'],
+ 'xcolor' : ['\\usepackage{xcolor}'],
+ 'xstring' : ['\\usepackage{xstring}'],
+}
+
+#
+# Add per host support. If there is a version clash for the same texlive
+# package create a directory, add to that directory and use the path in this
+# name here.
+#
+hosts = {
+ # All versions of CentOS until told otherwise
+ 'Linux/centos' : { '.*' : ['capt-of.sty',
+ 'eqparbox.sty',
+ 'environ.sty',
+ 'inconsolata.sty',
+ 'ifplatform.sty',
+ 'lato.sty',
+ 'trimspaces.sty',
+ 'slantsc.sty',
+ 'upquote.sty'] }
+}
+
+def tex_test(test):
+ return os.linesep.join(package_test_preamble +
+ package_tests[test] +
+ package_test_postamble)
+
+def host_name():
+ uname = os.uname()
+ if uname[0] == 'Linux':
+ distro = platform.dist()
+ name = '%s/%s' % (uname[0], distro[0])
+ version = distro[1]
+ else:
+ name = uname[0]
+ version = uname[2]
+ return name, version
+
+def local_packages():
+ host, version = host_name()
+ packages = None
+ if host in hosts:
+ for version in list(hosts[host].keys()):
+ if re.compile(version).match(version) is not None:
+ packages = hosts[host][version]
+ return packages
+
+def configure_tests(conf):
+
+ #
+ # Using a hint from ita (thank you) :
+ # https://github.com/waf-project/waf/blob/master/demos/tex/wscript
+ #
+ def build_latex_test(bld):
+ def write_tex_test(tsk):
+ tsk.outputs[0].write(tex_test(tsk.env.TEST))
+
+ test = bld.kw['tex_test']
+ bld.env.TEST = test
+
+ bld.to_log('%s.tex %s' % (test, '=' * (40 - len(test) + 5)))
+ bld.to_log(tex_test(test))
+ bld.to_log('=' * 40)
+
+ bld(rule = write_tex_test, target = 'main.tex')
+ bld(features = 'tex', type = 'pdflatex', source = 'main.tex', prompt = 0)
+
+ tests = sorted(package_tests.keys())
+ excludes = [p[:p.rfind('.')] for p in local_packages()]
+ for e in excludes:
+ if e in tests:
+ tests.remove(e)
+
+ fails = 0
+ for t in tests:
+ r = conf.test(build_fun = build_latex_test,
+ msg = "Checking for Tex package '%s'" % (t),
+ tex_test = t,
+ okmsg = 'ok',
+ errmsg = 'not found (please install)',
+ mandatory = False)
+ if r is None:
+ fails += 1
+ if fails > 0:
+ conf.fatal('There are %d Tex package failures. Please fix.' % (fails))