mathematicator-core / tokenizer
Math Tokenizer
Installs: 4 417
Dependents: 6
Suggesters: 0
Security: 0
Stars: 8
Watchers: 3
Forks: 2
Open Issues: 4
Requires
- php: ^8.0
- mathematicator-core/numbers: ^2.1
- nette/tokenizer: ^3.0
- nette/utils: ^3.0
Requires (Dev)
- brainmaestro/composer-git-hooks: dev-master
- jetbrains/phpstorm-attributes: ^1.0
- nette/bootstrap: ^3.0.1
- nette/tester: ^2.0
- phpstan/phpstan: ^0.12.74
- phpstan/phpstan-nette: ^0.12.14
- roave/security-advisories: dev-master
- spaze/phpstan-disallowed-calls: ^1.1
- tracy/tracy: ^2.8
Suggests
- nette/di: (^3.0) To use package in Nette Framework
- v3.0.1
- v3.0.0
- dev-master / 2.2.x-dev
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.1
- v2.0.0
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-dependabot/composer/spaze/phpstan-disallowed-calls-tw-1.1or-tw-3.0
- dev-dependabot/composer/nette/utils-tw-3.0or-tw-4.0
- dev-dependabot/composer/phpstan/phpstan-tw-0.12.74or-tw-1.0.0
- dev-dependabot/composer/phpstan/phpstan-nette-tw-0.12.14or-tw-1.0.0
- dev-dependabot/add-v2-config-file
- dev-remove-engine
This package is auto-updated.
Last update: 2024-12-10 06:06:18 UTC
README
PHP Math Tokenizer
Mathematicator Tokenizer is a simple library for converting string math formulas to a stream of tokens with LaTeX support.
Installation
composer require mathematicator-core/tokenizer
Features
- Convert all your math formulas to a stream of tokens
- Convert user math input to LaTeX
- Render the tokens tree map for debug
Usage
Inject the Tokenizer
service via DI
and tokenize your query.
use \Mathematicator\Tokenizer\Tokenizer; $tokenizer = new Tokenizer(/* some dependencies */); // Convert math formula to an array of tokens: $tokens = $tokenizer->tokenize('(5+3)*(2/(7+3))'); // Now you can convert tokens to a more useful format: $objectTokens = $tokenizer->tokensToObject($tokens); var_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);
Configuration
The tokenizer uses automatic configuration based on DI. Just use the DI container and the service will be fully available.
Mathematicator Framework tools structure
The biggest advantage is that you can choose which layer best fits your needs and start build on the top of it, immediately, without the need to create everything by yourself. Our tools are tested for bugs and tuned for performance, so you can save a significant amount of your time, money, and effort.
Framework tend to be modular as much as possible, so you should be able to create an extension on each layer and its sublayers.
Mathematicator framework layers ordered from the most concrete one to the most abstract one:
Third-party packages:
⚠️ Not guaranteed!
Contribution
Please help to improve this documentation by sending a Pull request.
Tests
All new contributions should have its unit tests in /tests
directory.
Before you send a PR, please, check all tests pass.
This package uses Nette Tester. You can run tests via command:
composer test
For benchmarking, we use phpbench. You can run benchmarks this way:
composer global require phpbench/phpbench @dev # only the first time
phpbench run
Before PR, please run complete code check via command:
composer cs:install # only first time composer fix # otherwise pre-commit hook can fail