How to view equations on Android?

Asked

Viewed 96 times

3

Does anyone know how to display mathematical equations in Android apps?

Actually there’s something like Latex where I put $f(x) = \frac{x^3}{\sqr{x}}$ and it shows on Texview:

Resultado Esperado

Does anyone know if there is a native form of Android to do this or a library, or a graphic component, anything?

1 answer

3

You can use the library jqmath it allows you to use formulas on android

Open the following website jqMath and download the Javascript library. Once you have downloaded the library, copy and Paste the Folder in the Asset Folder of your application. If your application does not contain an Asset Folder, create one first before dropping the plugins to the Folder.

First download the library on the site, deposi de baixa cole na Paste de Assets:

inserir a descrição da imagem aqui

I used it in the html file:

<head>
    <meta charset="utf-8">

    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=UnifrakturMaguntia">
    <link rel="stylesheet" href="mathscribe/jqmath-0.4.3.css">

    <script src="mathscribe/jquery-1.4.3.min.js"></script>
    <script src="mathscribe/jqmath-etc-0.4.3.min.js" charset="utf-8"></script>
    <!-- <script>M.MathPlayer = false; M.trustHtml = true;</script> →
</head>

Create a webview with the file:

<RelativeLayout
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="elearning.chidi.com.elearning.FormulaActivity">

 <WebView
        android:id="@+id/formula_page"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:layout_above="@+id/more_options"
        android:textSize="14sp"
        android:textColor="@color/primary_text"
        android:background="@color/icons"
        android:scrollbars="none" />
</RelativeLayout>

Finally change your Activity to call the webview created on the screen:

import android.content.res.AssetManager;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;

public class NumberBasicsActivity extends ActionBarActivity {
    private WebView articleContent;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_number_basics);

        Toolbar topToolBar = (Toolbar)findViewById(R.id.toolbar);
        setSupportActionBar(topToolBar);
        topToolBar.setLogo(R.drawable.logo);
        topToolBar.setLogoDescription(getResources().getString(R.string.logo_desc));
        articleContent = (WebView) findViewById(R.id.article);
        articleContent.getSettings().setJavaScriptEnabled(true);
        articleContent.getSettings().setBuiltInZoomControls(true);

        try {            
            articleContent.loadUrl("file:///android_asset/testfile.html");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_number_basics, menu);
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

The final result will be:

inserir a descrição da imagem aqui

Source: https://inducesmile.com/android/how-to-display-math-formula-and-equation-in-android-application/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.