Mathjax“未捕获的ReferenceError:未定义MathJax”

时间:2018-06-29 14:53:14

标签: android mathjax

我想在android中显示数学或科学的复杂公式。我正在尝试使用Mathjax来显示公式或方程式。我也尝试了其他解决方案。但没有成功。我错过了什么吗?我遇到错误

I/chromium: [INFO:CONSOLE(1)] "Uncaught ReferenceError: MathJax is not defined", source:  (1)

我是否需要对清单文件进行任何更改?

这是我的MainActivity.java代码

    public class MainActivity extends Activity
            implements View.OnClickListener {

        private String doubleEscapeTeX(String s) {
            String t = "";
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) == '\'') t += '\\';
                if (s.charAt(i) != '\n') t += s.charAt(i);
                if (s.charAt(i) == '\\') t += "\\";
            }
            return t;
        }

        private int exampleIndex = 0;

        private String getExample(int index) {
            return getResources().getStringArray(R.array.tex_examples)[index];
        }

        public void onClick(View v) {
            if (v == findViewById(R.id.button2)) {
                WebView w = (WebView) findViewById(R.id.webview);
                EditText e = (EditText) findViewById(R.id.edit);
                w.loadUrl("javascript:document.getElementById('math').innerHTML='\\\\["
                        + doubleEscapeTeX(e.getText().toString()) + "\\\\]';");
                w.loadUrl("javascript:MathJax.Hub.Queue(['Typeset',MathJax.Hub]);");
            } else if (v == findViewById(R.id.button3)) {
                WebView w = (WebView) findViewById(R.id.webview);
                EditText e = (EditText) findViewById(R.id.edit);
                e.setText("");
                w.loadUrl("javascript:document.getElementById('math').innerHTML='';");
                w.loadUrl("javascript:MathJax.Hub.Queue(['Typeset',MathJax.Hub]);");
            } else if (v == findViewById(R.id.button4)) {
                WebView w = (WebView) findViewById(R.id.webview);
                EditText e = (EditText) findViewById(R.id.edit);
                e.setText(getExample(exampleIndex++));
                if (exampleIndex > getResources().getStringArray(R.array.tex_examples).length - 1)
                    exampleIndex = 0;
                w.loadUrl("javascript:document.getElementById('math').innerHTML='\\\\["
                        + doubleEscapeTeX(e.getText().toString())
                        + "\\\\]';");
                w.loadUrl("javascript:MathJax.Hub.Queue(['Typeset',MathJax.Hub]);");
            }
        }

        /**
         * Called when the activity is first created.
         */

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            WebView w = (WebView) findViewById(R.id.webview);
            w.getSettings().setJavaScriptEnabled(true);
            w.getSettings().setBuiltInZoomControls(true);       
            w.loadDataWithBaseURL("http://bar", "<script type='text/x-mathjax-config'>"
                    +"MathJax.Hub.Config({ "
                    +"showMathMenu: false, "
                    +"jax: ['input/TeX','output/HTML-CSS'], "
                    +"extensions: ['tex2jax.js'], "
                    +"TeX: { extensions: ['AMSmath.js','AMSsymbols.js',"
                    +"'noErrors.js','noUndefined.js'] } "
                    +"});</script>"
                    +"<script type='text/javascript' "
                    +"src='file:///android_asset/MathJax/MathJax.js'"
                    +"></script><span id='math'></span>","text/html","utf-8","");


            EditText e = (EditText) findViewById(R.id.edit);
            e.setBackgroundColor(Color.LTGRAY);
            e.setTextColor(Color.BLACK);
            e.setText("");
            Button b = (Button) findViewById(R.id.button2);
            b.setOnClickListener(this);
            b = (Button) findViewById(R.id.button3);
            b.setOnClickListener(this);
            b = (Button) findViewById(R.id.button4);
            b.setOnClickListener(this);
            TextView t = (TextView) findViewById(R.id.textview3);
            t.setMovementMethod(LinkMovementMethod.getInstance());
            t.setText(Html.fromHtml(t.getText().toString()));

        }
    }

这是我的资产文件夹。

enter image description here

0 个答案:

没有答案