1

Я работаю над разработкой мобильного приложения, которое набирает математическое приложение, но перед вами стоит проблема. Код в порядке в соответствии с правилами, но выражение не изменяется. Не выполняется набор.Разработка автономного приложения для мобильных устройств MathJax

Это мой MainActivity код, скажите на милость, где лазейку:

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; 
} 

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]);"); 
    } 
} 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.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); 

} 
} 
+0

Может быть, это может помочь: HTTP: //stackoverflow.com/q/17029780/1919013 – Neoh

ответ

5

К сожалению для саморекламы. Но, возможно, вы можете попробовать MathView. Это обычная библиотека просмотра на основе Android WebView и используйте MathJax для отображения математической формулы.

Использование MathView точно так же, как TextView, но оно автоматически отобразит код TeX.

<io.github.kexanie.library.MathView 
    android:id="@+id/formula_one" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    auto:text="When \\(a \\ne 0\\), there are two solutions to \\(ax^2 + bx + c = 0\\) and they are $$x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.$$" 
    > 
</io.github.kexanie.library.MathView> 

Надеюсь, это поможет!

0

Используйте этот код

w.loadDataWithBaseURL("http://bar", 
"<html><head>" + 
" <meta name=\"viewport\" content=\"width=device-width, user-scalable=yes\" />" + 
"</head>" + 
"" + 
"<body style=\"font-size:18px\" >" + 
"<b>Put here your equation</b> </br> " + 
"<script type=\"text/x-mathjax-config\">" + 
" MathJax.Hub.Config({\n" + 
" CommonHTML: { linebreaks: { automatic: true },EqnChunk:(MathJax.Hub.Browser.isMobile?10:50) },displayAlign: \"left\",\n" + 
" \"HTML-CSS\": { linebreaks: { automatic: true } ," + 
"\n" + 
" preferredFont: \"STIX\"}," + 
"extensions: [\"tex2jax.js\"],messageStyle:\"none\"," + 
"jax: [\"input/TeX\", \"input/MathML\",\"output/HTML-CSS\"]," + 
"tex2jax: {inlineMath: [['$','$'],['\\\\(','\\\\)']]}" + 
"});" + 
"</script>" + 
"<script type=\"text/javascript\" async src=\"file:///android_asset/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML\"></script>" + 
"" + 
"</body>" + 
"</html>", "text/html", "utf-8", ""); 
+0

Не могли бы вы добавить объяснение того, что вы изменили/сделал и почему? – Dekker

+0

@Dekker i Ну, у меня мало знаний о HTML, но я потратил много времени на поиск решения, и этот код хорошо работал с последней автономной библиотекой ** MathJax **. –

Смежные вопросы