-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathREADME.md~
96 lines (74 loc) · 3.7 KB
/
README.md~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# MathView
Simple and light third-party view library written in `Kotlin` to ease displaying math formulas using [jqMath](https://mathscribe.com/author/jqmath.html). `MathView` is based on `WebView` and works similar to other math-rendering libraries, but it allows user to customize the text a bit more.
## About [jqMath](https://mathscribe.com/author/jqmath.html)
jqMath is a JavaScript module that makes it easy to put formatted mathematical expressions in web pages. It uses a simple TeX-like syntax, with MathML semantics and is roughly 5 times faster than MathJax (which is actually much bigger). jqMath is lightweight, fast and concise. It is standards-based and cross-browser, using MathML when available, else simple HTML and CSS, and avoiding pixel-map images. Thus pages load quickly, and expressions can be resized by the user, or easily passed to screen reading, graphing, or computer algebra software.
## Building equations
The HTML source patterns that will result in math equations can be checked [here](https://mathscribe.com/author/jqmath.html).
### Referencing characters
All HTML characters can be added by Unicode code point (decimal) reference.
```html
⊗ = Î
```
There is no need to add every special character by [Unicode](https://www.w3schools.com/charsets/ref_utf_misc_symbols.asp) reference. The HTML characters can be copied straight into your code. Referencing is handy when you are entering characters with `EditText` widget.
### Kotlin String interpolation
When building equations in Kotlin sometimes double backslash is needed to escape Kotlin String Interpolation
```kotlin
var math = "$\\F࢔{→}=ma_g$"
```
# Demo
![Demo RecyclerView](/MathViewGif.gif)
# Installation
Add below lines to app's build.gradle
```groovy
repositories {
maven { url 'https://jitpack.io' }
}
```
```groovy
dependencies {
implementation 'com.github.jstarczewski:MathView:0.2.1'
}
```
# Usage
`MathView` works nearly as `TextView`. It renders math equation with MathML semantics.
## In layout file
```xml
<com.jstarczewski.pc.mathview.src.MathView
android:id="@+id/mvTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
```
## In Activity
```kotlin
mvTest.apply {
textZoom = 120
textColor = Color.GREEN.toString()
backgroundColor = Color.WHITE
text = "$\\F↖{→}=ma_g$"
}.updaet()
```
## Or set text directly in xml
Remember to encode HTML special characters when referencing with xml `& = &`
```xml
<com.jstarczewski.pc.mathview.src.MathView
android:id="@+id/mvTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:text="$F=mg$"/>
```
# Interface
There are currently five custom functions available for the user. I plan to refactor them to fit more in Kotlin style.
```kotlin
// Apply properties, then call update()
var mathView : MathView = findViewById<MathView>(R.id.mvEditTextExample)
mathView.apply {
text = "$\\F=10$"
textColor = "red"
}.update()
// Only after setting textZoom property there is no need to call update()
mathView.textZoom = 120
```
# Why jqMath and why I created this library ?
Back in 2016 I created an Android App which contained a lot of equations rendered with jqMath. I plan to rerelease the app and it is easier for me to write this simple library rather than convert all my equations to fit other rendering engine. `MathView` is my first Android library and writing it is a great fun for me. I'm currently learning Kotlin so if you see situations where I am not using Kotlin's full potential, feel free to contribute.
# Contributing
Feel free to contribute and report issues. Feedback appreciated