2017 © Pedro PelĂĄez
 

library tex2png

LaTeX formula to PNG

image

gregwar/tex2png

LaTeX formula to PNG

  • Tuesday, November 28, 2017
  • by Gregwar
  • Repository
  • 6 Watchers
  • 39 Stars
  • 5,631 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 13 Forks
  • 0 Open issues
  • 2 Versions
  • 7 % Grown

The README.md

Tex2png

This class provides a way to create easily LaTeX formulas., (*1)

With it, you can convert raw formulas like:, (*2)

\sum_{i = 0}^{i = n} \frac{i}{2}, (*3)

To nice images like:, (*4)

Sum formula, (*5)

Requirement

To use this library you'll need :, (*6)

  • latex : to compile formulas (with math support)
  • dvipng : to convert dvis to png
  • shell_exec : you need to be able to call the php shell_exec() function

You'll also need a temporary folder and, of courses, enough permissions to write to the target directory, (*7)

Usage

Just include the Tex2png.php file or register this repository directory as the Gregwar\Tex2png\ namespace and do the following :, (*8)

<?php

// This will create a formula and save it to sum.png
Tex2png::create('\sum_{i = 0}^{i = n} \frac{i}{2}')
    ->saveTo('sum.png')
    ->generate();

You can have a look at the example in example/ directory., (*9)

Using the cache

Tex2png library includes a caching system allowing you to generate images only one time. To do so, just don't tell Tex2png what is the target file :, (*10)

<?php

Tex2png::create('\sum_{i = 0}^{i = n} \frac{i}{2}')
    ->generate();

// The filename will be choosen using an hash of the formula and
// the image density. (file name will look like cache/tex/3/0/2/e/6/8febefe7aaed9eeb8abf09070d10e02e93e.png)

If the file already exists, it will not generate anything, else, it will generate it. This results in a tiny but powerful caching system avoiding to regenerate a formula PNG twice., (*11)

Note that you can change the cache directory calling the setCacheDirectory() function, (*12)

This is based on the Gregwar/Cache library., (*13)

Changing the density

The second constructor/create() parameter is the image density :, (*14)

<?php

Tex2png::create('\sum_{i = 0}^{i = n} \frac{i}{2}', 300)
    ->generate();

Default density is 155, you can choose to generate really big images, this is an example of the formula with a density of 1000 :, (*15)

Sum formula (density=1000), (*16)

License

This class is under MIT license, for more information, please refer to the LICENSE file, (*17)

The Versions

28/11 2017

dev-master

9999999-dev https://github.com/Gregwar/Tex2png

LaTeX formula to PNG

  Sources   Download

MIT

The Requires

 

math image latex png formula

20/09 2015

v1.0.0

1.0.0.0 https://github.com/Gregwar/Tex2png

LaTeX formula to PNG

  Sources   Download

MIT

The Requires

 

math image latex png formula