paste.tra.pt / math-for-php · 1 year ago·

Use this code to grab a Tex-to-MathML conversion while using PHP.  https://tra.pt/math for details
Update CURLOPT_POSTFIELDS with your TeX math function.

<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://trapt.vercel.app/api/mathml",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_POSTFIELDS => "G_{\\mu\\nu}=8\\pi G\\left(T_{\\mu\\nu}+{\\large \\rho}_\\Lambda {\\large g}_{\\mu\\nu} \\right)",
  CURLOPT_HTTPHEADER => [
    "Accept: application/json",
    "content-type: text/plain"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}