blob: efbbf8802430309692784e62a1a4a0e12911597c [file] [log] [blame]
Sameer Agarwalfa21df82013-02-18 08:48:52 -08001#!/usr/bin/python
2#
3# Ceres Solver - A fast non-linear least squares minimizer
4# Copyright 2013 Google Inc. All rights reserved.
5# http://code.google.com/p/ceres-solver/
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions are met:
9#
10# * Redistributions of source code must retain the above copyright notice,
11# this list of conditions and the following disclaimer.
12# * Redistributions in binary form must reproduce the above copyright notice,
13# this list of conditions and the following disclaimer in the documentation
14# and/or other materials provided with the distribution.
15# * Neither the name of Google Inc. nor the names of its contributors may be
16# used to endorse or promote products derived from this software without
17# specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29# POSSIBILITY OF SUCH DAMAGE.
30#
31# Author: sameeragarwal@google.com (Sameer Agarwal)
32#
33# Note: You will need Sphinx and Pygments installed for this to work.
34
Sameer Agarwalfa21df82013-02-18 08:48:52 -080035import glob
Sameer Agarwal931c3092013-02-25 09:46:21 -080036import os
37import sys
Sameer Agarwalfa21df82013-02-18 08:48:52 -080038
Pablo Specialec51b11c2013-03-12 00:56:56 -070039# Number of arguments
40N = len(sys.argv)
41
42if N < 3:
Sameer Agarwalfa21df82013-02-18 08:48:52 -080043 print "make_docs.py src_root destination_root"
Sameer Agarwalbeb45052013-02-22 13:37:01 -080044 sys.exit(1)
Sameer Agarwalfa21df82013-02-18 08:48:52 -080045
Pablo Specialec51b11c2013-03-12 00:56:56 -070046src_dir = sys.argv[1] + "/docs/source"
Sameer Agarwalfa21df82013-02-18 08:48:52 -080047build_root = sys.argv[2]
Pablo Specialec51b11c2013-03-12 00:56:56 -070048cache_dir = build_root + "/doctrees"
49html_dir = build_root + "/html"
50
51# Called from Command Line
52if N == 3:
53 sphinx_exe = "sphinx-build"
54
55# Called from CMake (using the SPHINX_EXECUTABLE found)
56elif N == 4:
57 sphinx_exe = sys.argv[3]
Sameer Agarwalfa21df82013-02-18 08:48:52 -080058
59# Run Sphinx to build the documentation.
Pablo Specialec51b11c2013-03-12 00:56:56 -070060os.system("%s -b html -d %s %s %s" %(sphinx_exe, cache_dir, src_dir, html_dir))
Sameer Agarwalfa21df82013-02-18 08:48:52 -080061
62input_pattern = """config=TeX-AMS-MML_HTMLorMML"></script>"""
63output_pattern = """config=TeX-AMS_HTML">
64 MathJax.Hub.Config({
65 "HTML-CSS": {
66 availableFonts: ["TeX"]
67 }
68 });
69</script>"""
70
71# By default MathJax uses does not use TeX fonts. This simple search
Sameer Agarwalbeb45052013-02-22 13:37:01 -080072# and replace fixes that.
Sameer Agarwalfa21df82013-02-18 08:48:52 -080073for name in glob.glob("%s/*.html" % html_dir):
74 print "Postprocessing: ", name
Sameer Agarwalbeb45052013-02-22 13:37:01 -080075 fptr = open(name)
76 out = fptr.read().replace(input_pattern, output_pattern)
Sameer Agarwal931c3092013-02-25 09:46:21 -080077 fptr.close()
78
79 fptr = open(name, "w")
80 fptr.write(out)
81 fptr.close()