Setting CSS styles, color, for MathJax

匿名 (未验证) 提交于 2019-12-03 02:28:01

问题:

Hi I am trying to add styles to my MathJax output. In particular I would like to set a global color for my equations (so that it matches the styles on the rest of my page). Currently I have the following configuration.

<script type="text/x-mathjax-config">     MathJax.Hub.Config({       jax: ["input/TeX", "output/HTML-CSS"],       tex2jax: {         inlineMath: [ ['$', '$'] ],         displayMath: [ ['$$', '$$']],         processEscapes: true,         skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']       },       messageStyle: "none",       "HTML-CSS": {            preferredFont: "TeX",            availableFonts: ["STIX","TeX"],            styles: {".MathJax" {color: "#CCCCCC";}}            }     }); </script> <script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML" type="text/javascript"></script> 

However if I include the styles tag in my configuration the math on my page just refuses to display at all. On the other hand if I remove it, it displays fine.

Edit: I should also note that I have tried adding the styles directly to my CSS as suggested in other questions but this resulted in the same thing, no math being displayed at all.


UPDATE: I have added the : as Davide suggests below, now my equations display but the styling information is ignored. The styling seems to be inherited from the body of the page but wrapping the math in a div with different styling doesn't seem to affect it either.

UPDATE2: I have solved my the issue of the mathjax ignoring style commands. The color for text was globally set by a line in my CSS * { colour: #292929 }. This meant that the style from MathJax was being ignored. Simply changing * to body, a, p, h1, h2 fixed the issue.

回答1:

You are missing the colon after ".MathJax". Your code should be

<script type="text/x-mathjax-config"> MathJax.Hub.Config({   jax: ["input/TeX", "output/HTML-CSS"],   tex2jax: {     inlineMath: [ ['$', '$'] ],     displayMath: [ ['$$', '$$']],     processEscapes: true,     skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']   },   messageStyle: "none",   "HTML-CSS": {        preferredFont: "TeX",        availableFonts: ["STIX","TeX"],        styles: {".MathJax": {color: "#CCCCCC"}}        } }); </script> 

and then it should work for you.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!