Skip to content

Commit

Permalink
Update to version v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MuhammadSawalhy committed Sep 3, 2020
1 parent e7af8d1 commit 9b04430
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 9 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [Unreleased]


## [1.1.0] - 2020-3-9
### Added
- Tests for the basic arithmetics and autoMult option
- Tests for options.functions
- Preparing input before parsing, enabling parsing when the passed expression has some unimportant groups such as `as{da } ^{13}{/6}` -> `as da ^{13} /6 `
- Types "prod", "sqrt" to Node types.


### Changed
- the error message when parsing `\dfhgw`, which is not defined, the parser throw "undefined control sequence dfhgw";
- Sqrt now is parsed with type = "sqrt" not "function" as before.

### Fix

- `\lef( [expression] \right)`: an error was thrown when we try to parse such an epxression, it considered right as control sequance name
- Make the argument for BlockParentheses instance of Array
125 changes: 124 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,125 @@
# math-latex-parser
A mathematical parser for latex in math mode. We mean by mathematical that, arithmetic operations is considered for example if you pass "1+2", the result would by a (add node "+") with two children nodes of type number.
A mathematical parser for latex in math mode. We mean by mathematical that, arithmetic operations are considered. For example, if you pass "1+2", the result would by a (add node "+") with two children nodes of type number.

# Install

```
npm i @scicave/math-latex-parser
```

# Usage

```js
const {parse} = require('@scicave/math-latex-parser');

console.log(parse('12+3^6x \\frac 1 {5+3}'));
/*
You ge some thing like this
Notice: this is just a prototype, the result is more verbose.
{
"name": "+",
"type": "operator",
"args": [
12,
{
"type": "automult",
"args": [
{
"type": "automult",
"args": [
{
"name": "^",
"type": "operator",
"args": [
3,
6
]
},
"x"
]
},
{
"type": "frac",
"args": [
1,
{
"name": "+",
"type": "operator",
"args": [
5,
3
]
}
]
}
]
}
]
}
*/
```

You can also pass options to the parse function:

```js
console.log(parse(tex, options));
```

# Options

## autoMult: boolean
> Default: `true`
You can parse some thing like this `3^6cd\\sqrt af`, if false, the previous latex expression will throw an error while being parsed.

## singleCharName: boolean
> Default: `true`
if you want to use `asdas{d } _ {asdasd123}` as id for variable of function (see options.functions here below), you have to set options.singleCharName to false.

## functions: string []
> Default: []
Acceptable values: Array of checkers, which are functions or regex or another checker[].

this is useful in some cases like, `f(x)`, or `f\left(x\right)`, the function id here is `f`, you can use `blablabla` when singleCharName is `false`.

## operatorNames: checker[]
> Default: [
"floor", "ceil", "round", "random", "factorial",
"sech", "csch", "coth", "abs", "arsinh", "arcosh",
"artanh", "arasinh", "aracosh", "aratanh",
]

Acceptable values: Array of checkers, which are functions or regex or another checker[]

Some expressions such as `\operatorname{floor}` are valid, when one of the checkers processes `floor` and return `true`.

## builtInControlSeq: checker[]
> Default: [
"alpha", "Alpha", "beta", "Beta", "gamma", "Gamma", "pi", "Pi", "varpi", "phi", "Phi",
"varphi", "mu", "theta", "vartheta", "epsilon", "varepsilon", "upsilon", "Upsilon",
"zeta", "eta", "Lambda", "lambda", "kappa", "omega", "Omega", "psi", "Psi",
"chi", "tau", "sigma", "Sigma", "varsigma", "rho", "varrho", "Xi", "xi", "nu",
"imath", "jmath", "ell", "Re", "Im", "wp", "Nabla", "infty", "aleph", "beth",
"gimel", "comicron", "iota", "delta", "thetasym", "omicron", "Delta", "Epsilon",
"Zeta", "Eta", "Theta", "Iota", "Kappa", "Mu", "Nu", "Omicron", "Rho", "Tau", "Chi"
]

Acceptable values: Array of checkers, which are functions or regex or another checker[]

## builtInFunctions: checker[]
> Default: [
"sinh", "cosh", "tanh",
"sin", "cos", "tan", "sec", "csc", "cot",
"arcsin", "arccos", "arctan", "arcsec", "arccsc", "arccot",
"ln"
]

Acceptable values: Array of checkers, which are functions or regex or another checker[]


# License

MIT
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scicave/math-latex-parser",
"version": "1.0.1",
"version": "1.1.0",
"description": "A mathematical parser for latex in math mode. We mean by mathematical that, arithmetic operations is considered for example if you pass \"1+2\", the result would by a (add node \"+\") with two children nodes of type number.",
"main": "./lib/index.js",
"repository": {
Expand Down
8 changes: 2 additions & 6 deletions src/tex.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"Zeta", "Eta", "Theta", "Iota", "Kappa", "Mu", "Nu", "Omicron", "Rho", "Tau", "Chi"
],

builtInFunctions: [ // the same as the rul builtInFuncsTitles
builtInFunctions: [
"sinh", "cosh", "tanh",
"sin", "cos", "tan", "sec", "csc", "cot",
"arcsin", "arccos", "arctan", "arcsec", "arccsc", "arccot",
Expand Down Expand Up @@ -327,11 +327,7 @@ factorial = "!"
////// //////
// definitions

builtInFuncsTitles = // the same as builtInFunctions
"sinh" / "cosh" / "tanh" /
"sin" / "cos" / "tan" / "sec" / "csc" / "cot" /
"arcsin" / "arccos" / "arctan" / "arcsec" / "arccsc" / "arccot" /
"ln"
builtInFuncsTitles = "\\" name:[a-z]i+ !char &{ return check(name.join(''), options.builtInFunctions); }

/// this may be operator, if so, don't consider as specialSymbol
specialSymbolsTitles = a:[a-z]i+ &{ return !check(a.join(''), ignoreSpacialSymbols); }
Expand Down

0 comments on commit 9b04430

Please sign in to comment.