Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for inline math expressions #117

Closed
p-gw opened this issue Dec 19, 2019 · 6 comments
Closed

Support for inline math expressions #117

p-gw opened this issue Dec 19, 2019 · 6 comments

Comments

@p-gw
Copy link

p-gw commented Dec 19, 2019

Thank you for this great theme.

Since Katex shortcodes are already implemented I wondered whether inline math expressions are supported as well. I already tried the basic inline syntax using $$ (e.g. some text $$x = 1$$ some more text), but it gets rendered as a block.

It is suggested here to add markup: mmark to the front matter or to save the *.md files as *.mmark. When doing so the inline math expressions do get rendered correctly with $$ but the table of contents in the right column vanishes.

Is there a way to both get inline math as well as keep the table of contents when using hugo-book?

@alex-shpak
Copy link
Owner

alex-shpak commented Dec 19, 2019

Hi!
Unfortunately, I think mmark renderer doesn't support ToC listing.
Also it is about to be removed from Hugo https://gohugo.io/content-management/formats/

@BettyFabre
Copy link

Hi,
I faced this issue too and solved it by modifying the katex shortcode by :

{{ if not (.Page.Scratch.Get "katex") }}
<!-- Include katext only first time -->
<link rel="stylesheet" 
...
  onload="
      renderMathInElement(
          document.body,
          {
              delimiters: [
                  {left: '$$', right: '$$', display: true},
                  {left: '\\[', right: '\\]', display: true},
                  {left: '$', right: '$', display: false},
                  {left: '\\(', right: '\\)', display: false}
              ]
          }
      );"></script>
{{ .Page.Scratch.Set "katex" true }}
{{ end }}

<p class="katex{{ with .Get "class" }} {{ . }}{{ end }}">
  $$ {{ .Inner }} $$
</p>

it just changes the call of auto-rendering from Katex like in the KaTex repo

Then I created another shortcode (based of the katex one) for inline math that uses span & the $.$ syntax :

...
<span class="katex{{ with .Get "class" }} {{ . }}{{ end }}">
  ${{ .Inner }}$
</span>

Finally I can call this shortcode to generate inline math in a post like for example
a permutation {{< katex_inline >}}\pi(x){{< /katex_inline >}} and it works fine.

It may not be optimal but it can be a start.

@alex-shpak
Copy link
Owner

I updated KaTeX shortcode so that it accepts display param. So:
{{< katex >}}\pi(x){{< /katex >}} will produce \( ... \) wrap for inline text and
{{< katex display >}}\pi(x){{< /katex >}} will procude \[ ... \] wrap for display mode.

@alex-shpak
Copy link
Owner

This will work for now, but it have high chance to mess with markdown. For example if you put inline shortcode in the middle of heading (like ## heading <shortcode> rest of it) it will break markdown layout.

@p-gw
Copy link
Author

p-gw commented Jan 14, 2020

Thank you @BetFab for the modification and @alex-shpak for the implementation! This will work just fine for my use case.

@alex-shpak
Copy link
Owner

👍 I will close this issue then, write here if you want me to reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants