Sameer Agarwal | fa21df8 | 2013-02-18 08:48:52 -0800 | [diff] [blame] | 1 | #!/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 Agarwal | fa21df8 | 2013-02-18 08:48:52 -0800 | [diff] [blame] | 35 | import glob |
Sameer Agarwal | 931c309 | 2013-02-25 09:46:21 -0800 | [diff] [blame] | 36 | import os |
| 37 | import sys |
Sameer Agarwal | fa21df8 | 2013-02-18 08:48:52 -0800 | [diff] [blame] | 38 | |
| 39 | if len(sys.argv) < 3: |
| 40 | print "make_docs.py src_root destination_root" |
Sameer Agarwal | beb4505 | 2013-02-22 13:37:01 -0800 | [diff] [blame] | 41 | sys.exit(1) |
Sameer Agarwal | fa21df8 | 2013-02-18 08:48:52 -0800 | [diff] [blame] | 42 | |
| 43 | src_dir = sys.argv[1] + "/docs/source" |
| 44 | build_root = sys.argv[2] |
| 45 | doctrees_dir = build_root + "/doctrees" |
| 46 | html_dir = build_root + "/html" |
| 47 | |
| 48 | # Run Sphinx to build the documentation. |
| 49 | os.system("sphinx-build -b html -d %s %s %s" %(doctrees_dir, src_dir, html_dir)) |
| 50 | |
| 51 | input_pattern = """config=TeX-AMS-MML_HTMLorMML"></script>""" |
| 52 | output_pattern = """config=TeX-AMS_HTML"> |
| 53 | MathJax.Hub.Config({ |
| 54 | "HTML-CSS": { |
| 55 | availableFonts: ["TeX"] |
| 56 | } |
| 57 | }); |
| 58 | </script>""" |
| 59 | |
| 60 | # By default MathJax uses does not use TeX fonts. This simple search |
Sameer Agarwal | beb4505 | 2013-02-22 13:37:01 -0800 | [diff] [blame] | 61 | # and replace fixes that. |
Sameer Agarwal | fa21df8 | 2013-02-18 08:48:52 -0800 | [diff] [blame] | 62 | for name in glob.glob("%s/*.html" % html_dir): |
| 63 | print "Postprocessing: ", name |
Sameer Agarwal | beb4505 | 2013-02-22 13:37:01 -0800 | [diff] [blame] | 64 | fptr = open(name) |
| 65 | out = fptr.read().replace(input_pattern, output_pattern) |
Sameer Agarwal | 931c309 | 2013-02-25 09:46:21 -0800 | [diff] [blame] | 66 | fptr.close() |
| 67 | |
| 68 | fptr = open(name, "w") |
| 69 | fptr.write(out) |
| 70 | fptr.close() |