# Jekyll Liquid Problem with a Mathjax Expression

**URL:** <https://talk.jekyllrb.com/t/jekyll-liquid-problem-with-a-mathjax-expression/7847>\
**Category:** Help\
**Created:** [December 1, 2022, 3:46am UTC](https://talk.jekyllrb.com/t/jekyll-liquid-problem-with-a-mathjax-expression/7847 "2022-12-01T03:46:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RSEF](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/rsef/32/5010_2.png) [@RSEF](https://talk.jekyllrb.com/u/RSEF)\
**Post date:** [December 1, 2022, 3:46am UTC](https://talk.jekyllrb.com/t/jekyll-liquid-problem-with-a-mathjax-expression/7847/1 "2022-12-01T03:46:08Z")

</div>

There is a particular Mathjax expression which chokes when I build Github Pages using Mathjax

Use the expression `$g^{\frac {p-1} {{p_i}^{n_i}}\$` in a github page where you import Mathjax. The page errors out while building.  
This is the build error I get.

```auto
github-pages 227 | Error: Liquid syntax error (line 3): Variable '{{p_i}' was not properly terminated with regexp: /\}\}/

```

I use Jekyll Now

I opened an issue with Mathjax - [Github Mathjax chokes on the expression $g^{\frac {p-1} {{p\_i}^{n\_i}}}$ · Issue #2971 · mathjax/MathJax · GitHub](https://github.com/mathjax/MathJax/issues/2971#issue-1466209640)

But they said it’s an issue with the Liquid Template of Jekyll

> <https://github.com/mathjax/MathJax/issues/2971#issuecomment-1331263752>
>
> \### Issue Summary
> 
> Github Mathjax chokes on the expression \`$g^{\\frac {p-1} {{…p\_i}^{n\_i}}}$\` in the build phase.
> 
> \### Steps to Reproduce:
> 
> Use the expression \`$g^{\\frac {p-1} {{p\_i}^{n\_i}}\\$\` in a github page where you import Mathjax. The page errors out while building.
> This is the build error I get.
> 
> \`\`\`
> github-pages 227 | Error: Liquid syntax error (line 3): Variable '{{p\_i}' was not properly terminated with regexp: /\\}\\}/
> \`\`\`
> 
> \### Technical details:
> 
> \* MathJax Version: Latest
> Client & Browser version aren't relevant because this is a build issue.
> 
> 
> I am using the following MathJax configuration:
> 
> \`\`\` js
> \<script type="text/x-mathjax-config"\>
> MathJax.Hub.Config({
> tex2jax: {
> inlineMath: \[\['$','$'\], \["\\\\(","\\\\)"\] \],
> processEscapes: true
> }
> });
> \`\`\`
> 
> and loading MathJax via
> 
> \`\`\` html
> \</script\>
> 
> \<script type="text/javascript" charset="utf-8" src="\[https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML\_HTMLorMML\](view-source:https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML\_HTMLorMML)"\>
> \</script\>
> 
> \<script type="text/javascript" charset="utf-8" src="\[https://vincenttam.github.io/javascripts/MathJaxLocal.js\](view-source:https://vincenttam.github.io/javascripts/MathJaxLocal.js)"\>
> \</script\>
> 
> \`\`\`
> 
> \### Supporting information:
> 
> 1) When you save the page in github, the github preview renders it fine without errors. However when the page builds, it errors out.
> 
> 2) There is a simple workaround to fix this - If you use \`$g^{\\frac {p-1} {p\_i^{n\_i}}}$\` instead of \`$g^{\\frac {p-1} {{p\_i}^{n\_i}}}$\`, it no longer chokes, but the other form also shouldn't choke.

As you point out, this is a build issue; MathJax isn’t involved until the page is viewed in a browser, so it is not a MathJax problem, and there is nothing MathJax can do about it.

> It appears that the Liquid Template for GitHub pages uses `{{ variable }}` to insert the value of a variable into your output, so that is conflicting with the use of braces in LaTeX notation. The `{{` at the beginning of `{{p_i}...` is being picked up by the Liquid template as an attempted variable reference that isn’t closed properly by `}}` since the next brace is a single brace. You will need to either protect the braces in the math (perhaps via `\{`) or do something like insert spaces so that you have `{ {` rather than `{{` (I haven’t tested either of those suggestions).
> 
> In any case, it is something that must be dealt with at the template level, as it occurs long before MathJax itself is involved.

I tried opening an issue in Jekyll, but the Submit button remains greyed out even if I have filled all fields.

---

<div class="post-metadata">

**Author:** ![BillRaymond](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/billraymond/32/5963_2.png) [@BillRaymond](https://talk.jekyllrb.com/u/BillRaymond)\
**Post date:** [December 1, 2022, 5:06pm UTC](https://talk.jekyllrb.com/t/jekyll-liquid-problem-with-a-mathjax-expression/7847/2 "2022-12-01T17:06:00Z")

</div>

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 🙂

## ⤵ Assigning and then displaying a variable

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

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

```

**Output**

```auto
$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:

```auto
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**

```auto
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}}\$

```

## 🦁 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.

```auto
Here is a formula:

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

```

**Output**

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

```

## 🔖 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:

> **[Template](https://shopify.github.io/liquid/tags/template/)**
>
> An overview of template tags in the Liquid template language.

---

<div class="post-metadata">

**Author:** ![RSEF](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/rsef/32/5010_2.png) [@RSEF](https://talk.jekyllrb.com/u/RSEF)\
**Post date:** [December 2, 2022, 12:25am UTC](https://talk.jekyllrb.com/t/jekyll-liquid-problem-with-a-mathjax-expression/7847/3 "2022-12-02T00:25:25Z")

</div>

As I have already mentioned in my bug description, I know a workaround & have mentioned the workaround. My point in posting this here is to get the Liquid bug fixed. I first tried to open an issue on jekyll github but I don’t seem to be able to do that. Even after filling all the elements of the Issue form, my submit button remains grayed out.

---

<div class="post-metadata">

**Author:** ![BillRaymond](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/billraymond/32/5963_2.png) [@BillRaymond](https://talk.jekyllrb.com/u/BillRaymond)\
**Post date:** [December 2, 2022, 12:33am UTC](https://talk.jekyllrb.com/t/jekyll-liquid-problem-with-a-mathjax-expression/7847/4 "2022-12-02T00:33:05Z")

</div>

Unfortunately, I am not someone that manages the Jekyll project. I am however, a person that likes to freely help people when I have the time and knowledge to help. The title and the content of your question suggested you (a) can’t perform a certain function and (b) cannot submit an issue. I was trying to help you with (a).

That said, I am not sure opening an issue that attempts to change Jekyll’s code-recognition of double-brackets will make it too far.

Perhaps this will fix your issue?

> **[LaTeX in Jekyll](http://www.iangoodfellow.com/blog/jekyll/markdown/tex/2016/11/07/latex-in-markdown.html)**
>
> To write about machine learning, I will naturally want to use some math symbols. Using LaTeX math in Jekyll is not completely straightforward, so I will desc...

---

<div class="post-metadata">

**Author:** ![ashmaroli](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ashmaroli](https://talk.jekyllrb.com/u/ashmaroli)\
**Post date:** [December 2, 2022, 5:56am UTC](https://talk.jekyllrb.com/t/jekyll-liquid-problem-with-a-mathjax-expression/7847/5 "2022-12-02T05:56:48Z")

</div>

Hello,  
I am one of the maintainers of the Jekyll repository.

The primary issue here is definitely the presence of `{{` that gets picked up by Jekyll’s template engine, Liquid.  
This is not a bug, but simply a side-effect. The only solution is to work around the muddy area.

Even if you were to file at ticket at GitHub, the response would remain the same: _work around the obstacle._

Like @BillRaymond suggested, the workarounds primarily consist of using `{% raw %} ... {% endraw %}` wherever one would have `{{` or `{%` or their closing counterparts to be _escaped_ / overlooked by Liquid.

One additional workaround is to declare `render_with_liquid: false` in the front matter to disable Liquid processing for the entire file.

A

---

<div class="post-metadata">

**Author:** ![RSEF](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/rsef/32/5010_2.png) [@RSEF](https://talk.jekyllrb.com/u/RSEF)\
**Post date:** [December 10, 2022, 9:54am UTC](https://talk.jekyllrb.com/t/jekyll-liquid-problem-with-a-mathjax-expression/7847/6 "2022-12-10T09:54:06Z")

</div>

> [@ashmaroli](#):
>
> One additional workaround is to declare `render_with_liquid: false` in the front matter to disable Liquid processing for the entire file.

Thank you both the render\_with\_liquid & @BillRaymond’s “raw” workaround are great considering that this is not a bug.

Thank you both of you.
