Multi-line TeX expressions with Django MathJax

97 views Asked by At

I am using MathType to convert formulas to TeX notation and pass them as template variables in Django. Most formulas convert to a single line and work fine. But there are some that convert to several lines and I am struggling to figure out if it is possible to render them in the template.

Working example:
Formula:
enter image description here


Django view:

def mmm(request):

    #The formula string is the result of conversion to Tex via MathType copy-paste option
    mean_formula = "$$\overline x  = {{\sum {{x_i}} } \over n}$$"

    return render(
        request,
        "statistics101/mmm.html",
        {
            "mean_formula": mean_formula,
        },
    )

Template:

<div class="formula">
    <div class="formula-maths">
        {{mean_formula}}
    </div>
    <div class="formula-desc">
        <p>
            Where,<br>
            <b>x</b> = each value in the data set<br>
            <b>i</b> = the counter of the values in the data set, from 1 to n<br>
            <b>n</b> = the total number of values in the data set<br>
        </p>
    </div>
</div>

Web:
enter image description here

Failing example:
Formula:
enter image description here

Tex conversion of the above comes out multi-line like this:

$$\left( {\matrix{
   n  \cr 
   x  \cr 

 } } \right){p^x}{(1 - p)^{n - x}}$$

I have tried to assign the variable in the view like this:

formula = "$$\left( {\matrix{\n   n  \cr \n   x  \cr \n\n } } \right){p^x}{(1 - p)^{n - x}}$$"

But on the web page that just comes out like this:
enter image description here

I have tried converting to LaTeX instead of TeX, but that also results in a multi-line formula.

0

There are 0 answers