jagermesh / latex-tools
Library to render LaTeX formula into image
Requires
- php: >=5.3
- dev-master
- 1.0.23
- 1.0.22
- 1.0.21
- dev-dependabot/npm_and_yarn/minimist-1.2.8
- dev-dependabot/npm_and_yarn/decode-uri-component-0.2.2
- dev-dependabot/npm_and_yarn/minimatch-3.1.2
- dev-dependabot/npm_and_yarn/async-2.6.4
- dev-dependabot/npm_and_yarn/copy-props-2.0.5
- dev-dependabot/npm_and_yarn/path-parse-1.0.7
- dev-dependabot/npm_and_yarn/lodash-4.17.21
- dev-dependabot/npm_and_yarn/hosted-git-info-2.8.9
- dev-dependabot/npm_and_yarn/y18n-3.2.2
- dev-dependabot/add-v2-config-file
This package is auto-updated.
Last update: 2024-11-05 20:34:10 UTC
README
Library to render LaTeX formula into image
Requirements
Linux
- Install TexLive from https://tug.org/texlive/
Mac OS
- Install MacTex from https://tug.org/mactex/
- Install dvipng
$ sudo tlmgr update --self
$ sudo tlmgr install dvipng
Installation
Easiest way is to use composer
composer require jagermesh/latex-tools
Usage
<?php require_once(__DIR__ . '/vendor/autoload.php'); // Or library directly // require_once('LatexTools.php'); $latexTools = new \LatexTools\LatexTools(); $latexTools->renderIntoResponse('(\frac{\beta }{\mu})^\beta {\Gamma(\beta )} \, e^{-\frac{V\,\beta }{\mu }} \label{gamma}');
Will render this nice formula :)
Functions reference
Render formula and return image in response
$latexTools->renderIntoResponse($formula, $params = []);
Render image into file
$fileName = $latexTools->renderIntoFile($formula, $params = []);
In above calls $params
could be any of these values:
density
- formula densityfallbackToImage
- if need to render regular image for incorrect formula (true
by default)fallbackImageFontName
- font name for regular image (fonts/PlayfairDisplay-Regular.ttf
by default)fallbackImageFontSize
- font size for regular image (16
by default)
Also these paramatares could be set globally. Please see below.
Set formula density (160
by default)
$latexTools->setDensity($value);
By default regular image will be rendered if formula incorrect (true
by default)
$latexTools->setFallbackToImage(true|false);
Example
<?php require_once(__DIR__ . '/vendor/autoload.php'); $latexTools = new \LatexTools\LatexTools(); $latexTools->renderIntoResponse('x^2');
Font name for regular image (fonts/PlayfairDisplay-Regular.ttf
by default)
$latexTools->setFallbackImageFontName($value);
Font size for regular image (16
by default)
$latexTools->setFallbackImageFontName($value);
Check if formula correct
$result = $latexTools->isValidLaTeX($formula);
Set directory for cache files (/tmp
by default)
$latexTools->setCachePath($value);
Set directory for temp files (/tmp
by default)
$latexTools->setTempPath($value);