PHP code example of corny-phoenix / tex-tools

1. Go to this page and download the library: Download corny-phoenix/tex-tools library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

corny-phoenix / tex-tools example snippets


use CornyPhoenix\Tex\Repositories\TemporaryRepository;

$job = (new TemporaryRepository())->createJob( /* TeX source */ );
$job->runPdfLaTex();
$job->hasErrors(); // False if everything went fine

use CornyPhoenix\Tex\Repositories\TemporaryRepository;
use CornyPhoenix\Tex\Exceptions\CompilationException;

$job = (new TemporaryRepository())->createJob( /* TeX source */ );
$job->runPdfLaTex()
    ->runBibTex()
    ->runMakeIndex()
    ->runPdfLaTex()
    ->runPdfLaTex();

use CornyPhoenix\Tex\Repositories\TemporaryRepository;
use CornyPhoenix\Tex\Exceptions\CompilationException;

$job = (new TemporaryRepository())->createJob( /* TeX source */ );
try {
    $job->runPdfLaTex()
        ->runBibTex()
        ->runMakeIndex()
        ->runPdfLaTex()
        ->runPdfLaTex();
} catch (CompilationException $e) {
    $format = 'Error in %s, line %d: %s';
    $log = $job->createLog();
    
    foreach ($log->getErrors() as $error) {
        echo sprintf(
            $format, 
            $error->getFilename(),
            $error->getLine(),
            $error->getMessage()
        );
        // handle error ...
    }
}

use CornyPhoenix\Tex\Repositories\TemporaryRepository;

$repo = new TemporaryRepository();
touch($repo->getDirectory() . '/file.unknown.to.tex');
$repo->clean();
assert(file_exists($repo->getDirectory() . '/file.unknown.to.tex')); // True