Skip to content

Commit

Permalink
Rudimentary MathML output now working
Browse files Browse the repository at this point in the history
  • Loading branch information
zmichaelov committed Nov 27, 2011
1 parent b04401a commit 044dd5a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
6 changes: 0 additions & 6 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@
<div id="output""></div>
</div>
<div class="span8"><h3>MathML Output</h3>
<math>
<msub>
<mover><mi>x</mi><mo>&macr;</mo></mover>
<mn>1</mn>
</msub>
</math>
</div>
</div>
<div class="row">
Expand Down
42 changes: 34 additions & 8 deletions utils/espresso.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,41 @@ function int2bin($number, $numbits){

function getMathML($output) {
$lines = explode("\n", $output);
foreach($lines as $line){
$pos = strpos($line,$needle);
if($pos === false) {
// string needle NOT found in haystack
// get the number of terms in the output
$terms = substr(strstr($lines[2], ' '), 1);
$math = '<math><mi>f</mi><mo>=</mo>';
for ($i = 3; $i < $terms + 3; $i++)
{
$term = strstr($lines[$i], ' ', true);
for($j = 0; $j < strlen($term); $j++){
$char = $term{$j};
$num = $j+1;
switch($char) {
case '0':
$math .= "<msub><mover><mi>x</mi><mo>&macr;</mo></mover><mn>$num</mn></msub>";
break;
case '1':
$math .= "<msub><mi>x</mi><mn>$num</mn></msub>";
break;
case '-':
break;
}
}
else {
// string needle found in haystack
if($i < $terms + 2) {
$math .= '<mo>+</mo>';
}
}
$math .= '</math>';
return $math;
// foreach($lines as $line){
// $pos = strpos($line,$needle);
// if($pos === false) {
// // string needle NOT found in haystack
// }
// else {
// // string needle found in haystack
// }
// }
}
$inputs = $_POST['inputs'];
//convert minterms to array of numbers
Expand Down Expand Up @@ -58,7 +84,7 @@ function getMathML($output) {
$output = shell_exec("../bin/espresso $tempfname");
// close temporary file
fclose($temp);

$math = getMathML($output);
echo "<pre class=\"prettyprint\">$output</pre>";
echo $math;
?>

0 comments on commit 044dd5a

Please sign in to comment.