Simple library for convert math formula to array of tokens.
Please help improve this documentation by sending a Pull request.
Install by Composer:
composer require mathematicator-core/tokenizer
Imagine you can:
- Convert all your math formulas to stream of tokens
- Convert user math input to LaTeX
- Solve your math problems by calculator
- Render tokens tree map for debug
Inject Tokenizer service by DIC and tokenize your query.
$tokenizer = new Tokenizer(/* some dependencies */);
// Convert math formule to array of tokens:
$tokens = $tokenizer->tokenize('(5+3)*(2/(7+3))');
// Now you can convert tokens to more useful format:
$objectTokens = $tokenizer->tokensToObject($tokens);
dump($objectTokens); // Return typed tokens with meta data
// Render to LaTeX
echo $tokenizer->tokensToLatex($objectTokens);
// Render to debug tree (extremely fast):
echo $tokenizer->renderTokensTree($objectTokens);Tokenizer needs your math configuration.
In common.neon simply define parameters:
parameters:
math:
functions:
- sin
- cos
- tan
- cotan
- log
- log\d*
- ln
- sqrt