Code Monkey home page Code Monkey logo

tex2max's Introduction

TeX2Max

npm version Language grade: JavaScript

TeX2Max is a JavaScript library for converting LaTeX math to Maxima code.

Environments in which to use TeX2Max

TeX2Max supports Node and AMD, in addition to normal browser support.

Main

lib/
├── tex2max.amd.js        (AMD)
├── tex2max.js            (UMD)
└── tex2max.common.js     (CommonJS, default)

Getting started

Installation

npm install tex2max

In browser:

<script src="/path/to/tex2max.js"></script>

The unpkg provides CDN support for tex2max.js's JavaScript. You can find the links here.

Alternativeley, you can download the latest standalone JavaScript files (ES5)

Usage

Syntax

new tex2max(options)
  • options (optional)
    • Type: Object
    • The options for the converter. Check out the available options.

Examples

Node
const TeX2Max = require('tex2max');
const converter = new TeX2Max(options);
AMD
define(['./path/to/tex2max.amd'], function(TeX2Max) {
    const converter = new TeX2Max(options);
});
Window
const TeX2Max = window.tex2max;
const converter = new TeX2Max(options);

⬆ back to top

Options

The TeX2Max class also support multiple optional configurations. These should be passed as an object to the TeX2Max class object. If no manual configurations are set, default options are used.

onlySingleVariables

  • Type: Boolean
  • Default: false

Enable to only allow single variable names.

handleEquation

  • Type: Boolean
  • Default: false

Enable to let Maxima solve an algebraic equation.

addTimesSign

  • Type: Boolean
  • Default: true

Add multiplication sign where multiplication is implied.

disallowDecimalPoints

  • Type: Boolean
  • Default: false

Enable to disallow decimal point separators . in numbers.

disallowllowDecimalCommas

  • Type: Boolean
  • Default: false

Enable to disallow decimal comma separators , in numbers.

onlyGreekName

  • Type: Boolean
  • Default: false

Enable to convert all greek letters to names.

onlyGreekSymbol

  • Type: Boolean
  • Default: false

Enable to convert all greek letters to symbols.

debugging

  • Type: Boolean
  • Default: false

Enable to produce debugging info.

Methods

toMaxima(latex)

  • latex:

    • Type: String
    • LaTeX math string.
  • (return value):

    • Type: String
    • Maxima code string.

Convert LaTeX math into Maxima code.

updateOptions(options)

  • options (optional):
    • Type: Object
    • Default: See the defaults for all the options.
    • The options for the converter. Check out the available options.

Update the converter options.

Note: This resets all settings. If one or more settings passed as parameter are missing, defaults will be used.

getLastInput()

Get the latest latex input.

getLastResult()

Get the latest conversion result.

Build instructions

Clone a copy of the main TeX2Max git repo by running:

git clone git://github.com/KQMATH/tex2max.git

Enter the TeX2Max directory and run the build script:

npm run build

Feedback:

Project lead: Hans Georg Schaathun [email protected]

Developer: André Storhaug [email protected]

License

TeX2Max is Licensed under the GNU General Public, License Version 3.

⬆ back to top

tex2max's People

Contributors

andstor avatar dependabot[bot] avatar sebastsg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

tex2max's Issues

Parse mathematical constants "e" and "pi"

When LaTeX expression contains mathematical constants "e" and "pi", it's impossible to run in Maxima: for example \lim_{x\to\pi}(e^x) converts to limit(((e^x)),x,(pi))
Perhaps it should be converted to limit(((%e^x)),x,(%pi)) (with %) or is this how it should be?

Operatorname macro is not supported

Some LaTeX functions are defied within the macro operatorname. MathQuill does this with e.g. the function "arccsc": \operatorname{arccsc x}.

Operations with functions

When i use LaTeX expressions like '\\sin(x)+\\cos(x)', the produced output is 'sin(x)cos(x)', but the output should be 'sin(x)+cos(x)'; the same happends with operators like +,-,*,/ and expressions like \\sin(x)+\\cos(x)+...+\\tan(x) or \\sin(x)+\\frac{3x}{2}. It seems that only happens when the LaTeX expression have a trigonometric function and later an operator.

Importing into an angular project via npm / index.html

Describe the bug

When I try to import tex2max using declare var tex2max: any; I get a ReferenceError: tex2max is not defined. But this doesn't occur with other packages. I have tried binding the scripts by installing the npm package and through the script tag in index.html

To Reproduce
Steps to reproduce the behavior:

  1. Install npm package using npm install tex2max --save-dev
  2. Try to import and use a tex2max object
  3. See error

Expected behavior
tex2max object should be created, I need the toMaxima() method specifically

Desktop (please complete the following information):

  • MacOS 10.14.6
  • Firefox 78.0.1

Possible security issue

hgThe following was received back in February. Has it been reviwed? If it has already been addressed, the issue can be closed.

:-- hg

We found a potential security vulnerability in a repository for which you have been granted security alert access.

KQMATH/tex2max
https://github.com/KQMATH/tex2max
Known low severity security vulnerability in lodash v< 4.17.11, defined in https://github.com/KQMATH/tex2max/blob/develop/package-lock.json
https://github.com/KQMATH/tex2max/blob/develop/package-lock.json update suggested: lodash v4.17.11
Always verify the validity and compatibility of suggestions with your codebase.
Review the vulnerable dependency:
https://github.com/KQMATH/tex2max/network/alert/package-lock.json/lodash/open

Only users who have been assigned access to security alerts will receive these notifications.

Add support for decimal comma

Decimal numbers are currently supported. However, only support for decimal points . are implemented while decimal commas , aren't.

It should be possible to implement decimal commas. However, there are some caveats that needs to be resolved first. See issue #44. This is also related to issue #47 and #48.

When the issues above are resolved, it should be made optional whether to allow only decimal points or decimal commas as input (in floating numbers). As default it should be possible to use both types as input.

Since Maxima only allows decimal points in floating numbers, all transpiled floating numbers should only contain decimal points.

Can you add an html input output interface?

Dear developer, thanks a lot for the great project!

I am completely a newbie in programming. I would like to have an html input output interface that I can use instantly. I tried to learn a little html and javascript and have written a stupid html with the following code, which does not work at all. Could you please help make it work? Or even better, you can provide a better version? Thanks a lot anyway!

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>tex2max</title>

<script src="C:/Users/dell/node_modules/tex2max/lib/tex2max.js">
const tex2max = require('tex2max');
const converter = new tex2max();
</script>

</head>

<body>

<form oninput="y.value=converter.toMaxima(z.value)">
LaTeX: <input type="text" id="z" value=" "><br>
Maxima: <output name="y" for="z"></output>

<br>
converter.toMaxima("z.value")
z.value

</body>
</html>

Decimals aren't supported

Decimals aren't supported.
Both decimal point . and comma , should be supported.

This means that they needs to be defined as accepted tokens, see tokens.js. Further, they need to be parsed as being a part of a number. This should most likely be implemented in the parseNumber function in the parser.js file.

Add unit testing

Unit tests should be added to maintain code health, ensure code coverage, and detect errors and faults.

AVA should be used as testing framework.

Unfinished merge conflict committed to codebase

There is an unresolved merge conflict in the post-parser.js file.

tex2max/src/post-parser.js

Lines 176 to 192 in fb50ee0

<<<<<<< HEAD
index += length;
=======
function parseSet() {
// Implement sets here
// handle commas as entities separator within the braces {a, b}
// Enforce correct number of commas.
// Only allow period in floats.
// split items between braces in an array and itterate it, recursively post parce it.
}
function parseFloat() {
let node;
let float;
>>>>>>> a9ffa167458e14e413ed0155ccff00296927cdd7

Add support for sets

Sets aren't currently supported.

In Maxima, to construct a set, one should write set(...) or {...}.
For example, set(a, b, a) or {a, b}.
To construct the empty set, write set() or {}.

See the Maxima manual - Sets.

Browser (UMD) build is broken

The tex2max.js file is currently not working. This is most likely a breaking change in the Webpack version.

When trying to run the file in the browser, it complains about SyntaxError: Invalid regular expression: range out of order in character class.

Some Matrix environments fail transpilation

Only the matrix matrix environment works, even though other types such as pmatrix is susposed to be supported.

This fails:

\begin{pmatrix}
1 & 2\\ 
3 & 4
\end{pmatrix}

while this works as expected:

\begin{matrix}
1 & 2\\ 
3 & 4
\end{matrix}

Thank you *so* much for this

Feel free to close or delete this issue, but I just wanted to say thank you for this library! Just saved me many hours of doing this myself. Let me know if there's anything I can do to help with the project.

times sign (the asterisk) is in the result

times sign (the asterisk) is in the result

here is the tex2max instance from the console:

TeX2Max {options: {…}, lastInput: "", lastResult: ""}
options:
----------------
onlySingleVariables: false
handleEquation: false
addTimesSign: true
onlyGreekName: false
onlyGreekSymbol: false
debugging: false
disallowllowDecimalCommas: false
lastInput: "\sin(x+t)\cdot x"
lastResult: "sin(x+t)x"
structure: (4) [{…}, {…}, {…}, {…}]
----------------
lastResult: "sin(x+t)x",

The last result is: sin(x+t)x.

I expected to see: sin(x+t)*x.

Add support to logarithms with different bases

Is it possible to add support for logarithms with different bases by formula log_a(b) = log(b)/log(a)?
\log _2(10) => (log(10)/log(2))
\log _{2-x}\(\frac{5+2}{x^2}) => (log(\frac{5+2}{x^2})/log(2-x))

P.S. Thanks a lot for the great library!

Parse piped expressions to Maxima's abs function

Would be really nice if tex2max supported parsing strings like ln|x| and transpiled them to ln(abs(x)). Seems doable, and I don't mind taking this on as I need it as soon as possible but if I could get some advice on where/how to start that'd be awesome. Thanks!

Sine argument rules

The LaTeX expression \sin x\cos y produces sin(x*cos(y)).
Trigonometric functions should only include the subsequent expressions that isn't +, -, +- or any type of function as their argument.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.