{"id":32385021,"url":"https://github.com/xemlock/php-latex","last_synced_at":"2026-01-17T20:48:56.084Z","repository":{"id":24760585,"uuid":"28173601","full_name":"xemlock/php-latex","owner":"xemlock","description":"LaTeX parser and renderer written in PHP","archived":false,"fork":false,"pushed_at":"2026-01-12T17:07:15.000Z","size":146,"stargazers_count":50,"open_issues_count":2,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2026-01-12T21:57:53.808Z","etag":null,"topics":["latex","latex-parser","php","php-latex"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/xemlock/php-latex","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xemlock.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2014-12-18T07:45:11.000Z","updated_at":"2026-01-12T17:06:30.000Z","dependencies_parsed_at":"2024-11-16T08:16:10.102Z","dependency_job_id":null,"html_url":"https://github.com/xemlock/php-latex","commit_stats":{"total_commits":71,"total_committers":3,"mean_commits":"23.666666666666668","dds":"0.028169014084507005","last_synced_commit":"d60bf4c919426d4fa6978aa1f63208d64df5cc73"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/xemlock/php-latex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xemlock%2Fphp-latex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xemlock%2Fphp-latex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xemlock%2Fphp-latex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xemlock%2Fphp-latex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xemlock","download_url":"https://codeload.github.com/xemlock/php-latex/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xemlock%2Fphp-latex/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28518198,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T18:55:29.170Z","status":"ssl_error","status_checked_at":"2026-01-17T18:55:03.375Z","response_time":85,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["latex","latex-parser","php","php-latex"],"created_at":"2025-10-25T02:31:51.164Z","updated_at":"2026-01-17T20:48:56.059Z","avatar_url":"https://github.com/xemlock.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# php-latex\n\n[![Build status](https://github.com/xemlock/php-latex/workflows/build/badge.svg)](https://github.com/xemlock/php-latex/actions?query=workflow/build)\n[![License](https://img.shields.io/github/license/xemlock/php-latex.svg)](https://packagist.org/packages/xemlock/php-latex)\n\n\nThe 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\nlibrary - in the browser. For this I recommend using [MathJax](https://www.mathjax.org/).\n\nBear in mind that not every LaTeX command is recognized or implemented. If you happen to need a command that's\nnot supported you can either define it manually (see description below), or file a [feature request](https://github.com/xemlock/php-latex/issues/new/choose).\n\n## Installation\n\nTo use php-latex, you install it just as any other php package - with [Composer](https://getcomposer.org/).\n\n```\ncomposer require xemlock/php-latex\n```\n\n## Usage\n\nBasic usage is as follows:\n\n### Parsing LaTeX source code\n\n```php\n$parser = new PhpLatex_Parser();\n$parsedTree = $parser-\u003eparse($input);\n// $parsedTree contains object representation of the LaTeX document\n```\n\n### Render parsed LaTeX source\n\nOnce you have a parsed source code, you can render it to HTML (or to LaTeX) - please mind that math-mode code is rendered as-is.\n\n```php\n// render parsed LaTeX code to HTML\n$htmlRenderer = new PhpLatex_Renderer_Html();\n$html = $htmlRenderer-\u003erender($parsedTree);\n\n// render parsed LaTeX code to sanitized LaTeX code\n$latex = PhpLatex_Renderer_Abstract::toLatex($parsedTree);\n```\n\n### Customization\n\nYou can add custom (or not yet implemented) commands to the parser:\n\n```php\n$parser = new PhpLatex_Parser();\n$parser-\u003eaddCommand(\n    '\\placeholder',\n    array(\n        // number of arguments\n        'numArgs' =\u003e 1,\n        // number of optional arguments, default 0\n        'numOptArgs' =\u003e 1,\n        // mode this command is valid in, can be: 'both', 'math', 'text'\n        'mode' =\u003e 'both',\n        // whether command arguments should be parsed, or handled as-is\n        'parseArgs' =\u003e false,\n        // whether command allows a starred variant\n        'starred' =\u003e false,\n    )\n);\n```\n\n### pdflatex\n\nAdditionally, this library provides a wrapper for pdflatex to make rendering and compiling `.tex` files\nfrom PHP scripts easier.\n\n```php\n$pdflatex = new PhpLatex_PdfLatex();\n\n// to generate a PDF from .tex file\n$pathToGeneratedPdf = $pdflatex-\u003ecompile('/path/to/document.tex', \n    array(/* optional paths to files included by .tex file (images) */])\n);\n```\n\nYou can access the build log of the last `compile` call via:\n\n```php\necho $pdflatex-\u003egetLog();\n```\n\nYou can even compile on the fly a LaTeX string:\n\n```php\n$pathToGeneratedPdf = $pdflatex-\u003ecompileString('\n\\documentclass{article}\n\\begin{document}\nHello from \\LaTeX!\n\\end{document}\n');\n```\n\nBy default, a system temp dir is used for generating PDF from string. You can however customize it:\n\n```php\n$pdflatex-\u003esetBuildDir('/path/to/temp'); \n```\n\n## License\n\nThe MIT License (MIT). See the LICENSE file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxemlock%2Fphp-latex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxemlock%2Fphp-latex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxemlock%2Fphp-latex/lists"}