/ php-latex Public

LaTeX parser and renderer written in PHP

# xemlock/php-latex

Switch branches/tags
Nothing to show

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

## Files

Failed to load latest commit information.
Type
Name
Commit time

# php-latex

The main purpose of this library is to provide a valid LaTeX output from, not always valid, user input. You can also render LaTeX code to HTML, with one limitation though - rendering to HTML is done only for the text mode, the math mode needs to be handled by a JavaScript library - in the browser. For this I recommend using MathJax.

Bear in mind that not every LaTeX command is recognized or implemented. If you happen to need a command that's not supported you can either define it manually (see description below), or file a feature request.

## Installation

To use php-latex, you install it just as any other php package - with Composer.

composer require xemlock/php-latex:dev-master


## Usage

Basic usage is as follows:

### Parsing LaTeX source code

$parser = new PhpLatex_Parser();$parsedTree = $this->parse($input);
$parser->addCommand( '\placeholder', array( // number of arguments 'numArgs' => 1, // number of optional arguments, default 0 'numOptArgs' => 1, // mode this command is valid in, can be: 'both', 'math', 'text' 'mode' => 'both', // whether command arguments should be parsed, or handled as-is 'parseArgs' => false, // whether command allows a starred variant 'starred' => false, ) ); ### pdflatex Additionally, this library provides a wrapper for pdflatex to make rendering and compiling .tex files from PHP scripts easier. $pdflatex = new PhpLatex_PdfLatex();

// to generate a PDF from .tex file
$pathToGeneratedPdf =$pdflatex->compile('/path/to/document.tex',
array(/* optional paths to files included by .tex file (images) */])
);

You can access the build log of the last compile call via:

echo $pdflatex->getLog(); You can even compile on the fly a LaTeX string: $pathToGeneratedPdf = $pdflatex->compileString(' \documentclass{article} \begin{document} Hello from \LaTeX! \end{document} '); By default, a system temp dir is used for generating PDF from string. You can however customize it: $pdflatex->setBuildDir('/path/to/temp');

LaTeX parser and renderer written in PHP

## Releases

No releases published