Latex array and PHP array conflict

30 views
Skip to first unread message

arin...@gmail.com

unread,
Sep 30, 2017, 7:06:46 AM9/30/17
to MathJax Users
Hi,
I am using mathjax. I am facing problem when I am using latex array environment within an php array.

I write the following php file (for output see: www.arinmath.in/a/32/7.php):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>Questionnaire</title>

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({tex2jax: {inlineMath: [['#','#'], ['\\(','\\)']]}});
</script>
<script type="text/javascript" async
</script>
<style type="text/css"> 
    span {color: #FF00CC}
</style>

<style>
table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
}
</style>

</head>
<body>
<?php
$a = array(
array("The iterative scheme #x_{n+1}=\\frac{1}{2}\\left(x_{n}+\\frac{a}{x_{n}}\\right)# converges to #\sqrt{a}#. The convergence is", array("linear", "quadratic", "cubic", "bi-quadratic"), "quadratic"),
array("The fourth order divided difference of the polynomial #3x^{3}+11x^{2}-5x+11# over the points #x=0, 1, 4, 6\\textrm{ and }7# is", array("#18#", "#11#", "#3#", "#0#"), "#0#"),
array("What is the degree of polynomial of least degree which takes the following data?
#\\begin{array}{|c|c|c|c|c|c|c|}{\\hline x & 0 & 1 & 2 & 3 & 4 & 5\\\\\\hline f(x) & 0 & 3 & 8 & 15 & 24 & 35\\\\\\hline}\\end{array}#", array("#4#", "#2#", "#3#", "#5#"), "#2#"),
array("The trapezoidal rule applied to #\int\limits_{1}^{3}f(x)dx# gives the value #8# and Simpson's rule gives the value #4#. What is #f(2)#?", array("#2#", "#0#", "#1#", "#3#"), "#1#"),
array("A polynomial #p(x)# satisfies the following: #p(1)=p(3)=p(5)=1, p(2)=p(4)=-1#. Then the minimum degree of such a polynomial is", array("#1#", "#2#", "#3#", "#4#"), "#4#"));
?>

<form name="quiz" id="myquiz" onsubmit="return validate()" method="post" action="1001.php">
First Name: <input type="text" name="firstname" id="fname"/>
<p></p>
Last Name: <input type="text" name="lastname" id="lname"/>
<p></p>
#\newcommand\T{\Rule{0pt}{1em}{.3em}}#
<p>(1) <?php echo $a[0][0];?> </p>
<p><input type="radio" name="answer1" value="a"/><?php echo $a[0][1][0];?><br/>
<input type="radio" name="answer1" value="b"/><?php echo $a[0][1][1];?><br/>
<input type="radio" name="answer1" value="c"/><?php echo $a[0][1][2];?><br/>
<input type="radio" name="answer1" value="d"/><?php echo $a[0][1][3];?><br/>
<input type="radio" checked="checked" name="answer1" value="e" style="display:none"/><br/></p>

<p>(2) <?php echo $a[1][0];?></p>
<p><input type="radio" name="answer2" value="a"/><?php echo $a[1][1][0];?><br/>
<input type="radio" name="answer2" value="b"/><?php echo $a[1][1][1];?><br/>
<input type="radio" name="answer2" value="c"/><?php echo $a[1][1][2];?><br/>
<input type="radio" name="answer2" value="d"/><?php echo $a[1][1][3];?><br/>
<input type="radio" checked="checked" name="answer2" value="e" style="display:none"/><br/></p>

<p>(3) <?php echo $a[2][0];?></p>
<p><input type="radio" name="answer3" value="a"/><?php echo $a[2][1][0];?><br/>
<input type="radio" name="answer3" value="b"/><?php echo $a[2][1][1];?><br/>
<input type="radio" name="answer3" value="c"/><?php echo $a[2][1][2];?><br/>
<input type="radio" name="answer3" value="d"/><?php echo $a[2][1][3];?><br/>
<input type="radio" checked="checked" name="answer3" value="e" style="display:none"/><br/></p>

<p>(4) <?php echo $a[3][0];?></p>
<p><input type="radio" name="answer4" value="a"/><?php echo $a[3][1][0];?><br/>
<input type="radio" name="answer4" value="b"/><?php echo $a[3][1][1];?><br/>
<input type="radio" name="answer4" value="c"/><?php echo $a[3][1][2];?><br/>
<input type="radio" name="answer4" value="d"/><?php echo $a[3][1][3];?><br/>
<input type="radio" checked="checked" name="answer4" value="e" style="display:none"/><br/></p>

<p>(5) <?php echo $a[4][0];?></p>
<p><input type="radio" name="answer5" value="a"/><?php echo $a[4][1][0];?><br/>
<input type="radio" name="answer5" value="b"/><?php echo $a[4][1][1];?><br/>
<input type="radio" name="answer5" value="c"/><?php echo $a[4][1][2];?><br/>
<input type="radio" name="answer5" value="d"/><?php echo $a[4][1][3];?><br/>
<input type="radio" checked="checked" name="answer5" value="e" style="display:none"/><br/></p>

<input type="submit" name="submitbutton" value="Go"></input>
<input type="reset" value="clear all"></input>
</form>
</body>
</html>


In the above php file, the following portion
array("What is the degree of polynomial of least degree which takes the following data?
#\\begin{array}{|c|c|c|c|c|c|c|}{\\hline x & 0 & 1 & 2 & 3 & 4 & 5\\\\\\hline f(x) & 0 & 3 & 8 & 15 & 24 & 35\\\\\\hline}\\end{array}#", array("#4#", "#2#", "#3#", "#5#"), "#2#")

is not displaying.

Please help me.
With regards,
Arindam Bandyopadhyay
Khalore, Bagnan, Howrah, West Bengal, India.

Davide Cervone

unread,
Sep 30, 2017, 7:13:30 AM9/30/17
to mathja...@googlegroups.com
> In the above php file, the following portion
> array("What is the degree of polynomial of least degree which takes the following data?
> #\\begin{array}{|c|c|c|c|c|c|c|}{\\hline x & 0 & 1 & 2 & 3 & 4 & 5\\\\\\hline f(x) & 0 & 3 & 8 & 15 & 24 & 35\\\\\\hline}\\end{array}#", array("#4#", "#2#", "#3#", "#5#"), "#2#")
>
> is not displaying.

Remove the braces around the content of the array environment. That is the open brace before \\hline and the close brace before \\end{array}. Those are not correct LaTeX and are preventing the math from processing.

Davide

arin...@gmail.com

unread,
Sep 30, 2017, 9:37:59 AM9/30/17
to MathJax Users
Thank you Davide for the quick reply.
I remove it. But still it is not working.
Please help.
With regards, 
Arindam

Davide Cervone

unread,
Sep 30, 2017, 9:55:00 AM9/30/17
to mathja...@googlegroups.com
The LaTeX code that is actually in the page (that is, the php output) is

\begin{array}{|c|c|c|c|c|c|c|}{\hline x & 0 & 1 & 2 & 3 & 4 & 5\\hline f(x) & 0 & 3 & 8 & 15 & 24 & 35\\hline} nd{array}

Note that there are several things wrong with this LaTeX:  the second and third \hline macros are missing the backslash (you should have \\\hline not \\hline).  Also, the \e is missing from the \end{array}.  Finally, you have not removed the braces that I mentioned. I've marked the incorrect characters in red below (they need to be removed), and the missing ones in green.

\begin{array}{|c|c|c|c|c|c|c|}{\hline x & 0 & 1 & 2 & 3 & 4 & 5\\\hline f(x) & 0 & 3 & 8 & 15 & 24 & 35\\\hline} \end{array}

You need to make sure the php is generating this text.  It currently isn't.  I can't help you with that, as I don't know very much about php.  But it looks like there may be a backslash issue and you may need to double more of them that you currently have (perhaps there are two rounds of processing backslashes in the php code?).

In any case, that should tell you want you need your php to generate.

Davide


--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

arin...@gmail.com

unread,
Sep 30, 2017, 1:00:20 PM9/30/17
to MathJax Users
Thank you Davide.
Using the correction made by you, the php script now works fine.
Thanks a lot once again.
With regards,
Arindam
Reply all
Reply to author
Forward
0 new messages