Giter VIP home page Giter VIP logo

tex2png's Introduction

Tex2png

This class provides a way to create easily LaTeX formulas.

With it, you can convert raw formulas like:

\sum_{i = 0}^{i = n} \frac{i}{2}

To nice images like:

Sum formula

Requirement

To use this library you'll need :

  • 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

Usage

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

<?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.

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 :

<?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.

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

This is based on the Gregwar/Cache library.

Changing the density

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

<?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 :

Sum formula (density=1000)

License

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

tex2png's People

Contributors

gravatalonga avatar gregwar avatar jsmunich avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.