class LatexCompiler (View source)

Properties

protected obj|aray $data Data to be passed to $view
protected string $view view to be rendered
protected string $fileName File name without extension
protected int $runs Number of runs for pdflatex to run

Methods

__construct($data, $view, $fileName, $runs = null)

No description

string
compile()

Master Compile

deletePdf()

Delete PDF file

string
storagePath(string $storagePath)

Set Storage Path

string
fillTemplate(string $view)

Fills in the template

writeToFile(string $fileName, string $template)

Writes filled in template to file

compileTex(string $fileName, int $runs)

Sends to terminal to compile in tex

handlePDF(string $fileName)

Check for existing PDF and move from temp

tearDownTemp()

Tearsdown temp folder

Details

__construct($data, $view, $fileName, $runs = null)

Parameters

$data
$view
$fileName
$runs

string compile()

Master Compile

The master compilation function to generate a Latex Document from the shell and return the file path to the user.

Return Value

string

deletePdf()

Delete PDF file

Can be called anywhere to delete the PDF function generated from the class.

string storagePath(string $storagePath)

Set Storage Path

Called after the class is initialized to overide the default storage path

Parameters

string $storagePath overrides default storage path

Return Value

string

protected string fillTemplate(string $view)

Fills in the template

Parameters

string $view specific view to use when filling in

Return Value

string Compiled template

protected writeToFile(string $fileName, string $template)

Writes filled in template to file

Parameters

string $fileName file name without extension
string $template generated template

protected compileTex(string $fileName, int $runs)

Sends to terminal to compile in tex

Sets the absolute file position on the disk and attempts to run pdf latex after cding into the directory. If the exit code is anything other than 0, it logs the error in the latex.log, tears down the temp directory, and throws a new exception which can be caught if desired.

Parameters

string $fileName file name without extension
int $runs Optional number of times to run pdflatex, default 2, set in construct

Exceptions

Exception indicates failure to finish compiling in the shell.

protected handlePDF(string $fileName)

Check for existing PDF and move from temp

Checks the PDF path to see if there is already a PDF with the same name. If there is, it deletes the PDF in the path and then moves the new PDF there. If not, then it moves the PDF.

Parameters

string $fileName filename with pdf extension created in __construct

protected tearDownTemp()

Tearsdown temp folder

Deletes temp directory