To make the installation as simple as possible, Latex to Photomath (LTP) is packaged by the Unified Model Definition (UMD). Thereby, it can be integrated just like any other UMD package.
- Download the tarball file from google drive: link
- Run
npm install path/to/latex-to-photomath-1.0.0.tgz - LTP can now be accessed by:
const latexToPhotomath = require("latex-to-photomath");
- Download the bundle from google drive: link
- Load the bundle into the site:
<script src="ltp.js"></script>
- The latexToPhotomath function becomes available globally.
- Download the zip file from google drive: link
- Unpack it.
Run the input to Solver through LTP before passing it forwards.
LTP comes with good error reporting which can be output to the user by printing the error object's message.
The implementation code should look something like this:
try{
inputForSolver = latexToPhotomath(inputFromUser);
} catch (err) {
if (err.name === "LtpError")
{
Output err.message to user
}
}
LTP understands all LaTeX that the Photomath app can display. It is expected that, in the future, more LaTeX syntax will be implemented into the app. For this reason, LTP is built to be scalable. New LaTeX tokens can easily be implemented. The general overview of how a new LaTeX function "\myLatexFunc{a}" would be implemented:
- Add "myLatexFunc" to one-argument functions in the grammar.
- Write a "myLatexFunc" translator method that looks something like this:
myfunc: (functionObject) => "mySolverFunc(" + functionObject.arg + ")";
Due to the innate ambiguity of LaTeX, there are some known restrictions to LTP:
- Integrals must be written in the form:
\displaystyle\int_a^b{funcHere}dx - Degrees must be written in the form:
{50}^{\circ} - The following solver functions are not implemented in LaTeX form: mean, nderivation, percent, line_segment_length