All Projects → scarfboy → phplatex

scarfboy / phplatex

Licence: GPL-2.0 license
Inline TeX in PHP pages

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to phplatex

js.metaret
lightweight mutual tail recursion optimization without trampoline
Stars: ✭ 16 (-52.94%)
Mutual labels:  inline
editorjs-inline
Inline-Editor.js Tool for Editor.js
Stars: ✭ 23 (-32.35%)
Mutual labels:  inline
latex-cefetmg
Modelo de trabalho acadêmico utilizando LaTeX baseado nas normas da ABNT para o CEFET-MG.
Stars: ✭ 24 (-29.41%)
Mutual labels:  latex
asm-inline
Inline raw ASM instructions in Java
Stars: ✭ 23 (-32.35%)
Mutual labels:  inline
compact str
A memory efficient string type that can store up to 24* bytes on the stack
Stars: ✭ 322 (+847.06%)
Mutual labels:  inline
TJU-typora-latex-theme
天津大学本科生课程论文撰写:使用Typora代替LaTex
Stars: ✭ 24 (-29.41%)
Mutual labels:  latex
exe2hex
Inline file transfer using in-built Windows tools (DEBUG.exe or PowerShell).
Stars: ✭ 284 (+735.29%)
Mutual labels:  inline
Resume-Generator
A python tool help you generator your resume with your pre defined JSON file
Stars: ✭ 26 (-23.53%)
Mutual labels:  latex
inline-critical
Inline critical path CSS and async load existing stylesheets
Stars: ✭ 106 (+211.76%)
Mutual labels:  inline
jupyter-ieee-paper
Jupyter notebook to generate fully formatted IEEE papers
Stars: ✭ 26 (-23.53%)
Mutual labels:  latex
Inlin-Craft
Plugin for inlining files in templates.
Stars: ✭ 64 (+88.24%)
Mutual labels:  inline
node-inline-assets
Node API, CLI and Grunt Task for inlining external assets of HTML/CSS files
Stars: ✭ 18 (-47.06%)
Mutual labels:  inline
tabularray
Typeset tabulars and arrays with LaTeX3
Stars: ✭ 101 (+197.06%)
Mutual labels:  latex
USERGE-X
USERGE-X. What the X ?
Stars: ✭ 133 (+291.18%)
Mutual labels:  inline
LaTeX-OCR
pix2tex: Using a ViT to convert images of equations into LaTeX code.
Stars: ✭ 1,566 (+4505.88%)
Mutual labels:  latex
vue-svg-inline-plugin
Vue plugin for inline replacement of SVG images with actual content of SVG files.
Stars: ✭ 30 (-11.76%)
Mutual labels:  inline
inline-source-webpack-plugin
A webpack plugin to embed css/js resource in the html.
Stars: ✭ 18 (-47.06%)
Mutual labels:  inline
thesisthemeCSU
A template for the thesis of CSU (Central South University).
Stars: ✭ 13 (-61.76%)
Mutual labels:  latex
Study-LaTeX
LaTeX学习笔记
Stars: ✭ 22 (-35.29%)
Mutual labels:  latex
TJUThesisLatexTemplate
LaTeX templates for TJU graduate thesis. Originally forked from code.google.com/p/tjuthesis
Stars: ✭ 77 (+126.47%)
Mutual labels:  latex

Renders LaTeX into images by calling LaTeX itself from PHP.

See also http://phplatex.scarfboy.com/ and example use on http://latex.knobs-dials.com/

Requirements

  • PHP (>=4.3.0, as it uses sha1())
  • imagemagick (for convert)
  • ghostscript, and TeX Live or teTeX (for latex and dvips)
  • TeX packages: color, amsmath, amsfonts, amssymb, and the extarticle document class. Most are standard. You may need non-ancient versions of some.

Installation

  • Put phplatex.php somewhere from which you can include it

  • Have the requirements installed, and check they are where phplatex.php expects them to be (/usr/bin), or edit it as needed

  • Create subdirecties 'tmp' and 'images' in each directory you will be calling the script from, with write permissions for the effective user, for example mkdir tmp images; chown apache:apache tmp images

  • If you get "convert: not authorized" this is likely due to an 2018 ImageMagick update that disable PDF/PS conversions by default, apparently for security, and you need to tweak its policy.xml to re-enable it.

Use

  • Include the code: include('path/to/phplatex.php');
  • To render some TeX: echo texify("TeX");

Due to PHP parsing, you will need to double all your backslahes, and escape your dollar signs, like \$\\sqrt[3]{2}\$. PHP offers no alternatives to this. Yes, you can selectively get away with not doing it (e.g. if dollar signs aren't followed by text so can't name a variable, like in this example), but it's probably less confusing if you are consistent with this.

For advanced/creadive (ab)use, the function definition is actually:

  • texify(texstring, dpi, r,g,b, br,bg,bb, extraprelude); So, for example:
  • print texify('Times in TeX', 160, 0.2,0.0,0.0, 1.0,1.0,1.0, '\\usepackage{pslatex}');

Maintenance

  • Remove leftovers in the tmp directory at will
  • You can empty the img directory to remove unused images (still-used one will be regenerated)

Features

  • Will cache generated images, based on a hash of the document string. Meaning leaving the texify() calls on your page is cheap as successive runs will not run LaTeX at all.
  • CSS lowering to compensate for descenders, so TeX text used inline in HTML should look halfway decent.
  • Tweakable size. The default (90) is approximately the same size as HTML text. Capped at 300 for memory reasons.
  • Allows inclusion of extra TeX packages, via extraprelude.
  • Allows coloring of page background and default text color (default is black on white, 0.,0.,0. on 1.,1.,1.)
  • Generates PNGs with transparency (note: consider antialiasing to that background)
  • Relies on image trimming (instead of e.g. trusting dvips' bounding box)

Caveats

  • Won't work on safe-mode PHP, which is common enough on cheap oldschool shared hosting (though it was removed in PHP5.3)
  • I cannot guarantee this is safe from a security standpoint -- in theory it's mostly fine, but TeX is a full-fledged language. There is no input filter on what TeX is allowed, because that wouldn't even work. Know what this means security-wise - USE AT YOUR OWN RISK. In particular, the processes can do everything the effective user (of the apache process) can.
  • Fails on TeX that is more than one page. Should not bother you for most things that are inline. Sometimes-workaround: use \small or \footnotesize and a larger DPI setting. TODO: think about better fixes.
  • Image conversion can fail for very large images (hence the DPI cap)
  • the relative tmp and images directories are a little awkward. But the alternative (having a configurable path, to e.g. share the cache) would involve more thinking of how that is exposed URL-wise

Arguables

  • Uses latex's \nonstopmode, meaning TeX will best-guess-fix errors it can, rather than complain and stop. You can get away with some bad TeX and never know it
  • On low resolutions, the (default) Computer Modern fonts don't render as nicely as, say, pslatex fonts (Times, Helvatica, Courier), due to thickness and antialiasing. Change fontset to taste.
  • Image generation can take a second per image. You may hit your configured PHP max_execution_time limit a few times before a page with a lot of TeX images is all built and cached.
  • I'm no particular fan of PHP, but this does make it pretty portable.

When to use something else: Just math with fewer requirements

This project was made to get a real TeX environment, to compile arbitrary TeX.

If you care only about formulae on webpages, and don't care about the precise behaviour of compiled TeX, then you can get 95% of the way there without this heavy depdendency and its security issues, by considering options such as:

You may also care about live editing, like latex.js's, mathurl's, and others

Less interesting:

  • embedded MathML / element

  • ASCIIMathML.js

    • takes AsciiMath, makes MathML
    • useful as a component, integrated into mathJax
  • jsMath

    • takes LaTeX, MathML (XML based), and asciimath
    • produces HTML+CSS
    • code is pure JS
    • succeeded by mathJax
  • components such iTeX for TeX to MathML, svgmath for MathML to SVG

    • useful for projects but not end users directly
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].