(我正在使用stix字体,但问题也与Tex字体有关。(
我的问题:我如何在网页上配置Mathjax,以便查看页面的用户经历以下1-> 2-> 3后备链?
- html-css(webfont" stix-web",local" stix"(
- svg(" stix-web"(
- 所有其他后备选项(本地通用,图像等(
换句话说,这个想法是将html-css保持为首选,但是如果HTML-CSS失败,则归还给SVG,而不是本地通用或Image Fonts 。
后备需要用于(1(的各种失败。例如,当无法使用HTML-CSS中的本地字体时,它都应该使用(因为用户没有本地安装的字体,或者是因为我通过availableFonts: []
和preferredFont: null
在网页中明确禁用本地字体,也可以通过HTML在网页中禁用本地字体。-CSS Web字体无法使用(用户已禁用WebFonts,浏览器相同的Origin策略将得到执行,等等(。
它也应独立于客户用户在数学上下文菜单中的最后选择。当前,如果在客户端浏览器上,用户上次选择了HTML-CSS作为渲染器,则每当(1(失败时,MathJax都会落后于(3(,跳过(2(。如果用户上次选择了SVG作为渲染器,则HTML-CSS不再是第一个首选选择,即(1(完全跳过。
以下配置似乎实现了所需的后备链 (在我有限的测试中(。
<script type="text/javascript"
src="../MathJax-2.7.1/MathJax.js?config=TeX-AMS-MML_SVG">
</script>
<script type="text/x-mathjax-config">
//
// - Mathjax config to implement the following fallback chain:
//
// 1. HTML-CSS webFont ("STIX-Web")
// 2. SVG ("STIX-Web")
// 3. Other fallback fonts (local generic, image, etc)
//
// - Change availableFonts to ["STIX"] and preferredFont to "STIX"
// to allow local STIX fonts. Implements the fallback chain below:
//
// 1. HTML-CSS local ("STIX")
// 2. HTML-CSS webFont ("STIX-Web")
// 3. SVG ("STIX-Web")
// 4. Other fallback fonts (local generic, image, etc)
//
//
// Use STIX font consistently across HTML-CSS and SVG
//
MathJax.Hub.Config({
jax: ["input/TeX", "input/MathML",
"output/HTML-CSS", "output/SVG", "output/PreviewHTML"
],
"HTML-CSS": {
imageFont: null,
webFont: "STIX-Web",
availableFonts: [], // Or: ["STIX"], to allow local
preferredFont: null // Or: "STIX", to allow local
},
"SVG": {
font: "STIX-Web"
}
});
MathJax.Hub.Register.StartupHook("End Jax", function() {
// 1. Set HTML-CSS as the initially preferred output processor.
// (Temporarily overrides the renderer value set by MathMenu
// without affecting the user's chosen renderer elsewhere.)
var jax = "HTML-CSS";
MathJax.Hub.setRenderer(jax);
// 2. Install callback which switches renderer to SVG if HTML-CSS fails.
var nopast = true;
MathJax.Hub.Startup.signal.Interest(QueSVGfallback, nopast);
});
</script>
<script>
//
// This callback (when installed) scans through messages to check
// (as in FontWarnings.js) if HTML-CSS font loading has failed.
// If so, it queues a request to switch to SVG rendering.
//
var QueSVGfallback = (function() { // Anonymous "closure" to keep quecount
var quecount = 0;
return function(m) { // The real callback function
if (quecount > 0) return; // Prevent multiple queueing
m = m + "";
if (m.match(/HTML-CSS Jax - /)) {
if (m.match(/- using image fonts/) ||
m.match(/- no valid font/) ||
m.match(/- disable web fonts/)) {
MathJax.Hub.Queue(
["setRenderer", MathJax.Hub, "SVG", "jax/mml"],
["Rerender", MathJax.Hub]
);
quecount++;
}
}
}
})();
</script>