Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.tonymanou:AndroidLaTeXMath:library-1.0.0'
}
dependencies {
implementation("com.github.tonymanou:AndroidLaTeXMath:library-1.0.0")
}
<dependency>
<groupId>com.github.tonymanou</groupId>
<artifactId>AndroidLaTeXMath</artifactId>
<version>library-1.0.0</version>
</dependency>
libraryDependencies += "com.github.tonymanou" % "AndroidLaTeXMath" % "library-1.0.0"
:dependencies [[com.github.tonymanou/AndroidLaTeXMath "library-1.0.0"]]
AndroidLaTeXMath is a port to Android of JLaTeXMath, a mathematical formulas-oriented LaTeX rendering library.
It is still a work in progress, many things could be improved and a better wrapper should be developed.
The library will be available soon as a jCenter/sonatype dependency, until then you can include the compiled
androidlatextmath-1.0.0.aar
file into your project.
Before using the library, you must initialize it from the onCreate()
method of your application class:
public class MainApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
AssetHelper.initialize(this);
TeXFormula.setDensityFrom(this);
}
}
N.B.: Fonts, pictures and files referenced from your LaTeX formulas must be put in the assets
folder (not in res
!)
Now, you can create your LaTeX formula and render it to a Canvas:
TeXFormula formula = new TeXFormula("\\text{Hello world}");
TeXIcon icon = formula.createTeXIconBuilder()
.setStyle(TeXConstants.STYLE_DISPLAY)
.setSize(16)
.build();
icon.paintIcon(canvas, 0, 0);
Have fun!
Do not hesitate to take a look at the various samples provided with the library for more information.