@@ -31,6 +31,7 @@ var fs = require('fs');
3131var path = require ( 'path' ) ;
3232var url = require ( 'url' ) ;
3333var jsdom = require ( 'jsdom' ) . jsdom ;
34+ var isFullwidthCodePoint = require ( 'is-fullwidth-code-point' ) ;
3435
3536require ( './patch/jsdom.js' ) . patch ( jsdom ) ; // Fix some bugs in jsdom
3637
@@ -47,6 +48,7 @@ var defaults = {
4748 useGlobalCache : false , // use common <defs> for all equations?
4849 linebreaks : false , // do linebreaking?
4950 equationNumbers : "none" , // or "AMS" or "all"
51+ cjkCharWidth : 13 , // width of CJK character
5052
5153 math : "" , // the math to typeset
5254 format : "TeX" , // the input format (TeX, inline-TeX, AsciiMath, or MathML)
@@ -309,7 +311,11 @@ function ConfigureMathJax() {
309311 if ( def [ "font-weight" ] === "" ) delete def [ "font-weight" ] ;
310312 this . SUPER ( arguments ) . Init . call ( this , def ) ;
311313 SVG . addText ( this . element , text ) ;
312- var bbox = { width : text . length * 8.5 , height : 18 , y : - 12 } ;
314+ // tweaking font fallback behavior: https://github.com/mathjax/MathJax-node/issues/299
315+ var textWidth = text . split ( '' )
316+ . map ( function ( c ) { return isFullwidthCodePoint ( c . codePointAt ( ) ) ? data . cjkCharWidth : 8.5 } )
317+ . reduce ( function ( a , b ) { return a + b } , 0 ) ;
318+ var bbox = { width : textWidth , height : 18 , y : - 12 } ;
313319 scale *= 1000 / SVG . em ;
314320 this . element . setAttribute ( "font-family" , "monospace" ) ;
315321 this . element . setAttribute ( "transform" , "scale(" + scale + ") matrix(1 0 0 -1 0 0)" ) ;
0 commit comments