{"id":13645475,"url":"https://github.com/jianzhongli/MathView","last_synced_at":"2025-04-21T14:31:09.970Z","repository":{"id":46751580,"uuid":"42708912","full_name":"jianzhongli/MathView","owner":"jianzhongli","description":"A library for displaying math formula in Android apps.","archived":false,"fork":false,"pushed_at":"2022-07-19T14:42:23.000Z","size":4175,"stargazers_count":1025,"open_issues_count":62,"forks_count":195,"subscribers_count":31,"default_branch":"master","last_synced_at":"2025-04-12T17:46:19.576Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jianzhongli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-18T08:23:52.000Z","updated_at":"2025-04-07T01:48:01.000Z","dependencies_parsed_at":"2022-08-12T13:01:08.975Z","dependency_job_id":null,"html_url":"https://github.com/jianzhongli/MathView","commit_stats":null,"previous_names":["kexanie/mathview"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jianzhongli%2FMathView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jianzhongli%2FMathView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jianzhongli%2FMathView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jianzhongli%2FMathView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jianzhongli","download_url":"https://codeload.github.com/jianzhongli/MathView/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250070173,"owners_count":21369839,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T01:02:35.693Z","updated_at":"2025-04-21T14:31:09.963Z","avatar_url":"https://github.com/jianzhongli.png","language":"Java","funding_links":[],"categories":["其他"],"sub_categories":[],"readme":"# MathView\n[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-MathView-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/2957) [![Download](https://api.bintray.com/packages/kexanie/maven/MathView/images/download.svg) ](https://bintray.com/kexanie/maven/MathView/_latestVersion) \n\n`MathView` is a third-party view library, which might help you display math formula on Android apps easier. Two rendering engines available: [MathJax] and [KaTeX]. Support Android version 4.1 (Jelly Bean) and newer. \n\n\u003cimg src=\"screenshot/screenshot.png\" width=\"250\"\u003e\n\n## Setup\n\nThere are two ways you can add `MathView` to your project in Android Studio:\n\n1. From a remote Maven repository (jcenter).\n2. From a local .aar file.\n\n### 1. Setup from a remote Maven repository (jcenter)\n\nAdd `compile 'io.github.kexanie.library:MathView:0.0.6'` into **dependencies** section of your **module** build.gradle file. For example:\n\n```groovy\ndependencies {\n    compile fileTree(include: ['*.jar'], dir: 'libs')\n    compile 'com.android.support:appcompat-v7:23.0.0'\n    compile 'io.github.kexanie.library:MathView:0.0.6'\n}\n```\n\n### 2. Setup from local .aar file \n\nYou can download the latest version of MathView from [Bintray](https://bintray.com/kexanie/maven/MathView/_latestVersion \"Bintray\").\n\n1) Import the module from local .aar file\n\nClick `File -\u003e New -\u003e New Module` (yes, not `import Module`) `-\u003e Import .JAR/.AAR Package`, and find out where the file located.\n\n2) Add dependency\n\nClick `File -\u003e Project Structure -\u003e Dependencies`, and then click the plus icon, select `3. Module Dependency`.\n\n#### For Eclipse users\nJust migrate to Android Studio.\n\n## Usage\n\nThe behaviour of `MathView` is nearly the same as `TextView`, except that it will automatically render **TeX code** (or MathML code if rendering with MathJax) into math formula. For basic tutorial and quick reference, please have a look on this [tutorial].\n\n**Caution**\n\n1. You should enclose the formula in `\\(...\\)` rather than `$...$` for inline formulas.\n2. You need to escape spacial characters like backslash, quotes and so on in Java code.\n3. If you want to make the height of `MathView` actually `wrap_content`, warp the views into `NestedScrollView`.\n\n**About the engines**\n\nKaTeX is faster than MathJax on mobile environment, but MathJax supports more features and is much more beautiful. Choose whatever suits your needs. \n\n### Define `MathView` in your layout file\nFor example:\n\n```xml\n\u003cLinearLayout ...\u003e\n\n    \u003cTextView\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:text=\"Formula one: from xml with MathJax\"\n        android:textStyle=\"bold\"/\u003e\n\n    \u003cio.github.kexanie.library.MathView\n        android:id=\"@+id/formula_one\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        auto:text=\"When \\\\(a \\\\ne 0\\\\), there are two solutions to \\\\(ax^2 + bx + c = 0\\\\)\n        and they are $$x = {-b \\\\pm \\\\sqrt{b^2-4ac} \\\\over 2a}.$$\"\n        auto:engine=\"MathJax\"\n        \u003e\n    \u003c/io.github.kexanie.library.MathView\u003e\n\n    \u003cTextView\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:text=\"Formula two: from Java String with KaTeX\"\n        android:textStyle=\"bold\"/\u003e\n\n    \u003cio.github.kexanie.library.MathView\n        android:id=\"@+id/formula_two\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        auto:engine=\"KaTeX\"\n        \u003e\n    \u003c/io.github.kexanie.library.MathView\u003e\n\n\u003c/LinearLayout\u003e\n\n```\n\n### Get an instance from your `Activity`\n```java\npublic class MainActivity extends AppCompatActivity {\n    MathView formula_two;\n    String tex = \"This come from string. You can insert inline formula:\" +\n            \" \\\\(ax^2 + bx + c = 0\\\\) \" +\n            \"or displayed formula: $$\\\\sum_{i=0}^n i^2 = \\\\frac{(n^2+n)(2n+1)}{6}$$\";\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n    }\n\n    @Override\n    protected void onResume() {\n        super.onResume();\n\n        formula_two = (MathView) findViewById(R.id.formula_two);\n        formula_two.setText(tex);\n    }\n}\n```\n\n**Noted that the method `MatView.getText()` will return the raw TeX code (Java `String`).**\n\n### Configuration\n\nI am not an expert in MathJax. Rather than providing a pre-configured version of MathJax, I choose to add another method `config()`(for MathJax only) to `MathView` in version `0.0.5`. You can tweak MathJax with more complicated configurations. For example, to enable auto linebreaking, you can call\n\n```java\nMathView.config(\n\"MathJax.Hub.Config({\\n\"+\n            \"  CommonHTML: { linebreaks: { automatic: true } },\\n\"+\n            \"  \\\"HTML-CSS\\\": { linebreaks: { automatic: true } },\\n\"+\n            \"         SVG: { linebreaks: { automatic: true } }\\n\"+\n            \"});\");\n```\nbefore `setText()`.\n\n## How it works\n\n`MathView` inherited from Android `WebView` and use javascript ( [MathJax] or [KaTeX] ) to do the rendering stuff. Another library called [Chunk] is just an lightweight Java template engine for filling the TeX code into an html file. So we can render it. It's still rather primitive, but at least functional. Check the code for more details.\n\n## Known Issues\n\n1. When rendering with MathJax, some characters are blank(like character 'B' of BlackBoard Bold font) due to MathJax's [bug] on Android `WebView`.\n2. Not all TeX commands are supported by KaTeX, check this [link] for more details.\n\n\n\n## Feedback\n\nIf you have any issues or need help please do not hesitate to create an issue ticket.\n\n[tutorial]: http://meta.math.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference\n[bug]: https://github.com/mathjax/MathJax/issues/403\n[MathJax]: https://www.mathjax.org/\n[KaTeX]: https://github.com/Khan/KaTeX\n[Chunk]: https://github.com/tomj74/chunk-templates/\n[link]: https://github.com/Khan/KaTeX/wiki/Function-Support-in-KaTeX\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjianzhongli%2FMathView","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjianzhongli%2FMathView","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjianzhongli%2FMathView/lists"}