Home | History | Annotate | Download | only in scripts
      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 (at] google.com (Sameer Agarwal)
     32 #
     33 # Note: You will need Sphinx and Pygments installed for this to work.
     34 
     35 import glob
     36 import os
     37 import sys
     38 
     39 # Number of arguments
     40 N = len(sys.argv)
     41 
     42 if N < 3:
     43   print "make_docs.py src_root destination_root"
     44   sys.exit(1)
     45 
     46 src_dir    = sys.argv[1] + "/docs/source"
     47 build_root = sys.argv[2]
     48 cache_dir  = build_root + "/doctrees"
     49 html_dir   = build_root + "/html"
     50 
     51 # Called from Command Line
     52 if N == 3:
     53   sphinx_exe = "sphinx-build"
     54 
     55 # Called from CMake (using the SPHINX_EXECUTABLE found)
     56 elif N == 4:
     57   sphinx_exe = sys.argv[3]
     58 
     59 # Run Sphinx to build the documentation.
     60 os.system("%s -b html -d %s %s %s" %(sphinx_exe, cache_dir, src_dir, html_dir))
     61 
     62 input_pattern = """config=TeX-AMS-MML_HTMLorMML"></script>"""
     63 output_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
     72 # and replace fixes that.
     73 for name in glob.glob("%s/*.html" % html_dir):
     74   print "Postprocessing: ", name
     75   fptr = open(name)
     76   out = fptr.read().replace(input_pattern, output_pattern)
     77   fptr.close()
     78 
     79   fptr = open(name, "w")
     80   fptr.write(out)
     81   fptr.close()
     82