source view: latex.php


<?php



  require 'db.connect.php';

  if ( $_SERVER['SERVER_NAME'] != 'localhost' )
  {
    $random_formula_query = mysql_query('SELECT latexFormula, dpi FROM tblBlogFormulas ORDER BY RAND() LIMIT 1');
    $random_formula_row = mysql_fetch_row($random_formula_query);
    $dpi = $random_formula_row[1];
    $tex = $random_formula_row[0];
  }
  else
  {
    $dpi = 150;
    $tex = 'a ^ 2 + b ^ 2 = c ^ 2';
  }

  //
  // the latex.load script defines a whole bunch of variables that we're using here.
  // basically, there was a huge chunk of code that got pulled to another file for
  // simpler opening. realistically, we should instantiate some sort of class and
  // access the variables that way, but for now this'll work.
  //
  // but note that it's terrible, terrible form (check the references to $dpi and $filename...).
  //
  
  require '_pagewrapper.php';
  wrapPageTop( 'research.php', 'LaTeX to png' );
  include 'latex.load.php';

  if ( file_exists($filename) )
  {
?>
<h3 style="margin-bottom:1ex;">png output</h3>
        <p>
          <img alt="<?php print $_POST['tex'];?>" src="/<?php print $filename;?>" title="<?php print $_POST['tex'];?> (@ <?php print $dpi;?> DPI)" />
          <br />
          File at <a href="http://1.618034.com/<?php print $filename;?>">http://1.618034.com/<?php print $filename;?></a>
        </p>
<?php
  }
  else if ( isset( $error_string ) && strlen( $error_string ) > 0 )
  {
?>
<h3>LaTeX error</h3>
        <p>
          <div class="code_block" style="height:8em;"><pre>
<?php print str_replace('&#x0D;','',$error_string );?>
</pre></div>
<?php
  }
  else
  {
?>
<h3>LaTeX input</h3>
<?php
  }
?>
        <p>
          <form action="latex.php<?php print isset($_GET['xml'])?'?xml':'';?>" method="POST">
            <textarea id="tex" name="tex" rows="5" style="font-size:8pt;width:100%;" title="LaTeX source"><?php print str_replace('<','&lt;',$tex);?></textarea>
            DPI <input id="dpi" name="dpi" style="margin-left:1em;" type="text" value="<?php print $dpi;?>" />
            <input type="submit" value="Convert" />
          </form>
        </p>
        <p style="margin-top:1em;text-align:center;">
        </p>
        <h3>more information</h3>
        <p>
          After <a href="http://math.b3co.com/">math.b3co.com</a> went down, I needed a new source for my online LaTeX conversion. This page converts LaTeX fomulas to png &mdash; it automatically adds the necessary <tt>\begin{document}</tt> cruft &mdash;
          on a one-off basis; script access is available through POST.
          <ul>
            <li><tt>dpi=</tt> is the DPI of the result image; there is no default, but 150 is about right.</li>
            <li><tt>tex=</tt> is the LaTeX to convert</li>
          </ul>
        </p>
        <p>
          Optionally, you may pass <tt>?xml</tt> as a GET parameter, and the results will be returned as
        </p>
        <div class="code_block"><pre>&lt;?xml version="1.0"?&gt;
&lt;latexresult&gt;
  &lt;lateximage location="_url_" source="pngtex.618034.com" /&gt;
&lt;/latexresult&gt;
</pre></div>
        <p>
          This way, you can avoid parsing all the surrounding cruft. Images are maintained locally, so you don't need to copy them to your home server
          (however, as a nice script kiddie, that's a kind thing to do).
        </p>
<?php


  wrapPageBottom();
  

?>