All Projects → mzur → pretty-formula

mzur / pretty-formula

Licence: MIT license
A small Java library to parse mathematical formulas to LaTeX and display them as images

Programming Languages

java
68154 projects - #9 most used programming language
ANTLR
299 projects

Projects that are alternatives of or similar to pretty-formula

Csharpmath
LaTeX. in C#. (ported from the wonderful iosMath project).
Stars: ✭ 205 (+606.9%)
Mutual labels:  formula
wepy-plugin-resources-cdn
上传图片到云存储wepy plugin
Stars: ✭ 38 (+31.03%)
Mutual labels:  images
cloudinary-api
Shorter and lighter APIs for Cloudinary
Stars: ✭ 41 (+41.38%)
Mutual labels:  images
f1-telemetry-client
A Node UDP client and telemetry parser for Codemaster's Formula 1 series of games
Stars: ✭ 128 (+341.38%)
Mutual labels:  formula
oz-clear-unused-images-obsidian
Obsidian plugin to clear the images that are not used in note files anymore
Stars: ✭ 92 (+217.24%)
Mutual labels:  images
mSAT
A modular sat/smt solver with proof output.
Stars: ✭ 91 (+213.79%)
Mutual labels:  formula
Mathquill
Easily type math in your webapp
Stars: ✭ 1,968 (+6686.21%)
Mutual labels:  formula
pixel
A lightweight image loader for Android backed by Kotlin Coroutines.
Stars: ✭ 79 (+172.41%)
Mutual labels:  images
wordpress-plugin
Speed up your WordPress website. Optimize your JPEG and PNG images automatically with TinyPNG.
Stars: ✭ 78 (+168.97%)
Mutual labels:  images
Generative-Art
A selection of generative art scripts written in Python
Stars: ✭ 284 (+879.31%)
Mutual labels:  images
avif-sample-images
AVIF example images, licensed under CC-BY-SA.
Stars: ✭ 37 (+27.59%)
Mutual labels:  images
reddit get top images
Get top images from any subreddit
Stars: ✭ 37 (+27.59%)
Mutual labels:  images
Pikax
一个基于requests的P站下载器/ A pixiv downloader based on requests
Stars: ✭ 49 (+68.97%)
Mutual labels:  images
Hyperformula
A complete, open-source Excel-like calculation engine written in TypeScript. Includes 380+ built-in functions. Maintained by the Handsontable team⚡
Stars: ✭ 210 (+624.14%)
Mutual labels:  formula
RAImagePicker
📸 iMessage-like, Image Picker Controller Provides custom features.
Stars: ✭ 14 (-51.72%)
Mutual labels:  images
Calx.js
jQuery Calx - a jQuery plugin for creating formula-based calculation form
Stars: ✭ 190 (+555.17%)
Mutual labels:  formula
MediaSliderView
Pure java based, highly customizable media slider gallery supporting both images and videos for android.
Stars: ✭ 85 (+193.1%)
Mutual labels:  images
cdn
🚀 ✈️ 🚄 free CDN for everyone who wants to speed his website freely!😄
Stars: ✭ 16 (-44.83%)
Mutual labels:  images
danbooru-ruby-grabber
Danbooru, Konachan, Behoimi (3dbooru) and Yandere images downloader
Stars: ✭ 39 (+34.48%)
Mutual labels:  images
react-butterfiles
🦋 Component for building file fields - from basic file inputs to drag and drop image galleries.
Stars: ✭ 44 (+51.72%)
Mutual labels:  images

pretty-formula

A small Java library to parse mathematical formulas to LaTeX and display them as images.

Formula:

(a_1 / (b_1 + sqrt(c))^2) + sin(a_2 * b_2)

Image:

example

LaTeX:

\left(\frac{{a}_{1}}{{\left({b}_{1}+\sqrt{c}\right)}^{2}}\right)+\sin{\left({a}_{2}\cdot {b}_{2}\right)}

Installation

Grab the latest release and add the pretty-formula.jar as well as all the dependencies from the lib directory to your project.

Usage

Pretty-formula provides three functions to parse mathematical formulas either to LaTeX or to bitmap/vector graphics. It provides a basic GUI as an example how to use it as well. This means you even can run pretty-formula.jar on its own!

All the following functions are located in the package de.uni_bielefeld.cebitec.mzurowie.pretty_formula.main.

String parseToLatex(String formula)

Parses a mathematical formula String like (a+b)/c to valid math LaTeX.

formula: A raw formula input String.

Returns: The formula parsed to a small subset of LaTeX.

Throws: DetailedParseCancellationException When the parsing fails.

BufferedImage parseToImage(String formula)

Parses a mathematical formula String like (a+b)/c to a pretty image.

formula: A raw formula input String.

Returns: An image object containing the rendered formula.

Throws: ParseException When the formula rendering fails.

Throws: DetailedParseCancellationException when the formula parsing fails.

void saveToSVG(String formula, File file)

Parses a mathematical formula like (a+b)/c to a pretty image and saves it as an SVG file.

formula: A raw formula input String.

file: The SVG file to save to.

Throws: ParseException When parsing the LaTeX formula failed.

Throws: IOException When writing the file failed.

Throws: DetailedParseCancellationException When parsing the raw formula to LaTeX failed.

Example

You can find the fully working GUI example in GUIWindow.java. To run it, simply execute pretty-formula.jar.

The important part of parsing the formula to an image and do error handling and user feedback is this:

private void jTextPane1KeyReleased(java.awt.event.KeyEvent evt) {
	// feedback message
   this.jLabel1.setText("");
   
   // clear previously drawn formula
   this.jLabel2.getGraphics().clearRect(0, 0, this.jLabel2.getWidth(), this.jLabel2.getHeight());
   // remove error highlights from user input
   this.jTextPane1.getHighlighter().removeAllHighlights();

   try {
   	// parse the image
      BufferedImage image = FormulaParser.parseToImage(this.jTextPane1.getText());
      // display the image
      this.jLabel2.getGraphics().drawImage(image, 0, 0, null);
      
   } catch (DetailedParseCancellationException e) {
     // display user feedback on erroneous input
     this.handleDetailedParseCancellationException(e);
   } catch (ParseException e) {
   	// display user feedback on erroneous parsing (shouldn't happen, though)
      this.jLabel1.setText(e.getMessage());
   }
}

private void handleDetailedParseCancellationException(DetailedParseCancellationException e) {
   try {
      // highlight the position at which the error occurred
      this.jTextPane1.getHighlighter().addHighlight(
              e.getCharPositionInLine(), e.getEndCharPositionInLine(),
              this.errorHighlighter);
   } catch (BadLocationException ex) {
      // simply don't highlight
   }

   // display the error message in addition to the error highlighting
   this.jLabel1.setText(e.getMessage());
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].