Quellcode durchsuchen

Mathjax configuration option: Allow automatic line breaks

Barry Steyn vor 10 Jahren
Ursprung
Commit
8b7a086000
3 geänderte Dateien mit 8 neuen und 1 gelöschten Zeilen
  1. 3 0
      render_math/Readme.md
  2. 4 0
      render_math/math.py
  3. 1 1
      render_math/mathjax_script_template

+ 3 - 0
render_math/Readme.md

@@ -54,6 +54,9 @@ sequences. **Default Value**: True
 rendering LaTex. If set to `Tex`, then the TeX code is used as the preview 
 rendering LaTex. If set to `Tex`, then the TeX code is used as the preview 
 (which will be visible until it is processed by MathJax). **Default Value**: `Tex`
 (which will be visible until it is processed by MathJax). **Default Value**: `Tex`
  * `color`: controls the color of the mathjax rendered font. **Default Value**: `black`
  * `color`: controls the color of the mathjax rendered font. **Default Value**: `black`
+ * `linebreak_automatic`: Mathjax will try to *intelligently* break up any displayed math
+(Note: It will not work for inline math). This is very useful for a responsive site. It
+is turned off by default due to it potentially being CPU expensive. **Default Value**: False
 
 
 For example, in settings.py, the following would make math render in blue and
 For example, in settings.py, the following would make math render in blue and
 displaymath align to the left:
 displaymath align to the left:

+ 4 - 0
render_math/math.py

@@ -50,6 +50,7 @@ def process_settings(pelicanobj):
     mathjax_settings['process_escapes'] = 'true'  # controls whether escapes are processed
     mathjax_settings['process_escapes'] = 'true'  # controls whether escapes are processed
     mathjax_settings['latex_preview'] = 'TeX'  # controls what user sees while waiting for LaTex to render
     mathjax_settings['latex_preview'] = 'TeX'  # controls what user sees while waiting for LaTex to render
     mathjax_settings['color'] = 'black'  # controls color math is rendered in
     mathjax_settings['color'] = 'black'  # controls color math is rendered in
+    mathjax_settings['linebreak_automatic'] = 'false'  # Set to false by default for performance reasons (see http://docs.mathjax.org/en/latest/output.html#automatic-line-breaking)
 
 
     # Source for MathJax: Works boths for http and https (see http://docs.mathjax.org/en/latest/start.html#secure-access-to-the-cdn)
     # Source for MathJax: Works boths for http and https (see http://docs.mathjax.org/en/latest/start.html#secure-access-to-the-cdn)
     mathjax_settings['source'] = "'//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'"
     mathjax_settings['source'] = "'//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'"
@@ -88,6 +89,9 @@ def process_settings(pelicanobj):
 
 
         if key == 'color' and isinstance(value, basestring):
         if key == 'color' and isinstance(value, basestring):
             mathjax_settings[key] = value
             mathjax_settings[key] = value
+        
+        if key == 'linebreak_automatic' and isinstance(value, basestring):
+            mathjax_settings[key] = value
 
 
     return mathjax_settings
     return mathjax_settings
 
 

+ 1 - 1
render_math/mathjax_script_template

@@ -19,7 +19,7 @@ if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {{
         "        preview: '{latex_preview}'," +
         "        preview: '{latex_preview}'," +
         "    }}, " +
         "    }}, " +
         "    'HTML-CSS': {{ " +
         "    'HTML-CSS': {{ " +
-        "        styles: {{ '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {{color: '{color} ! important'}} }}" +
+        "        styles: {{ '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {{color: '{color} ! important'}} }}, linebreaks: {{ automatic: {linebreak_automatic}, width: 'container' }}" +
         "    }} " +
         "    }} " +
         "}}); ";
         "}}); ";
     (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
     (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);