Jekyll Liquid Problem with a Mathjax Expression

There are probably quite a few ways to accomplish this, but here are two that came to mind, which I tested and they work:

  • Assigning and then displaying a variable
  • Raw template tag

However, I will point out, I do not know MathJax and have not tested that element for the code I am sharing. Hopefully, this provides your solution or at least some inspiration :slight_smile:

:arrow_heading_down: Assigning and then displaying a variable

In this example, you will assign a variable with the formula you want to display on the page:

{% assign mj = '$g^{\frac {p-1} {{p_i}^{n_i}}\$' %}
{{mj}}

Output

$g^{\frac {p-1} {{p_i}^{n_i}}\$

I used the variable mj, but you can call it whatever you want. Also, if you have multiple formulas to display on a page, you can reuse the variable name like this:

Here is a formula that you should be aware of:
{% assign mj = '$g^{\frac {p-1} {{p_i}^{n_i}}\$' %}
{{mj}}

And here is another formula you should be aware of:
{% assign mj = '$g^{\div {p-1} {{p_i}^{n_i}}\$' %}
{{mj}}

Output

Here is a formula that you should be aware of:
$g^{\frac {p-1} {{p_i}^{n_i}}\$

And here is another formula you should be aware of:
$g^{\div {p-1} {{p_i}^{n_i}}\$

:lion: Raw template tag

In this example, you will use the Liquid raw tag to display your function. The nice thing about this option is you do not have to do as much coding to assign variables. I do not use this tag on my sites, so my suggestion is to make sure it displays properly within your theme. If it does display properly, this is probably what I would use over assigning a variable.

Here is a formula:

{% raw %}
$g^{\frac {p-1} {{p_i}^{n_i}}\$
{% endraw %}

Output

Here is a formula:
$g^{\frac {p-1} {{p_i}^{n_i}}\$

:bookmark: Reference

The raw tag is a Liquid template tag. If my examples are not exactly what you want, check out the documentation to see if there are other options that might be suitable for your situation: