gnab / remark

A simple, in-browser, markdown-driven slideshow tool.
http://remarkjs.com
MIT License
12.73k stars 857 forks source link

how to use katex environments like \begin{matrix} #551

Open floswald opened 5 years ago

floswald commented 5 years ago

hi there,

I have this index.html:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>{{title}}</title>
  {{{style}}}
  <script src="remark.min.js"></script>  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/katex.min.css" integrity="sha384-9eLZqc9ds8eNjO3TmqPeYcDj8n+Qfa4nuSiGYa6DjLNcv9BtN69ZIulL9+8CqC9Y" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/katex.min.js" integrity="sha384-K3vbOmF2BtaVai+Qk37uypf7VrgBubhQreNQe9aGsz9lB63dIFiQVlJbr92dw2Lx" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/contrib/auto-render.min.js" integrity="sha384-kmZOZB5ObwgQnS/DuDg6TScgOiWWBiVt0plIRkZCmE6rDZGrEOQeHM5PcHi+nyqe" crossorigin="anonymous"
    onload="renderMathInElement(document.body);"></script>

  <script>
    function create() {
      var renderMath = function() {
        // renderMathInElement(document.body);
        // or if you want to use $...$ for math,
        renderMathInElement(document.body, {
          delimiters: [
            {left: "$$", right: "$$", display: true},
            {left: "$", right: "$", display: false},
            {left: "\\(", right: "\\)", display: false},
            {left: "\\[", right: "\\]", display: true}
            // {left: "\\begin{equation}", right: "\\end{equation}", display: true},
            // {left: "\\begin{aligned}", right: "\\end{aligned}", display: true}
          ]
        });
      }
      remark.macros.scale = function (percentage) {
        var url = this;
        return '<img src="' + url + '" style="width: ' + percentage + '" />';
      };
      return remark.create({
        {{{source}}},
        ratio: '16:9',
        highlightLines: true,
        countIncrementalSlides: false,
        highlightStyle: 'github'
      },renderMath);
    }
  </script>
</head>
<body onload="slideshow = create()">
</body>
</html>

and I have this .md

# The basics

$\alpha$

$$\alpha + \beta$$

$$
\begin{matrix}
   a & b \\
   c & d
\end{matrix}
$$

but the environment stuff never works:

screenshot 2018-12-13 16 06 33

any ideas?

rhinopotamus commented 5 years ago

I ran into a similar problem recently that had to do with backslash escaping weirdness.

Note that when it gets rendered, the \\ separating the two lines becomes a single \. Thus, in your markdown, your line separator \\ should instead be \\\, and then it'll work right.

floswald commented 5 years ago

hey, thanks for that hint. i get a bit further now, but still weird.

# The basics

$\alpha$

\\[\alpha + \beta\\]

\\[\begin{array}{cc}
   a & b \\\
   c & d
\end{array}\\]
screenshot 2019-01-29 09 37 49
LiukDiihMieu commented 5 years ago

Many problems occur when I just tried to type several simple formulae. like subscripts $$\sigma_x = \frac{1}{2}$$ will not be displayed correctly.

floswald commented 5 years ago

I think you need to escape the underscore.

Try

\sigma_x

On Sat 12 Oct 2019 at 16:49, LiukDiihMrau notifications@github.com wrote:

Many problems occur when I just tried to type several simple formulae. like subscripts $$\sigma_x = \frac{1}{2}$$ will not be displayed correctly.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/gnab/remark/issues/551?email_source=notifications&email_token=AAHZM5TGWQPMOKG4DHQC7M3QOHPX3A5CNFSM4GKHJOMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBCBBAY#issuecomment-541331587, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHZM5THE3PQNEMJXQBQOIDQOHPX3ANCNFSM4GKHJOMA .

floswald commented 5 years ago

Also I think I remember that you need to put multi line latex environments on one markdown line inside $$ delims. Linebreaks after a \ for example will not work. That’s what I found with R xaringan package at least (that uses remark)

On Sat 12 Oct 2019 at 17:15, Florian Oswald florian.oswald@gmail.com wrote:

I think you need to escape the underscore.

Try

\sigma_x

On Sat 12 Oct 2019 at 16:49, LiukDiihMrau notifications@github.com wrote:

Many problems occur when I just tried to type several simple formulae. like subscripts $$\sigma_x = \frac{1}{2}$$ will not be displayed correctly.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/gnab/remark/issues/551?email_source=notifications&email_token=AAHZM5TGWQPMOKG4DHQC7M3QOHPX3A5CNFSM4GKHJOMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBCBBAY#issuecomment-541331587, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHZM5THE3PQNEMJXQBQOIDQOHPX3ANCNFSM4GKHJOMA .

ianfiske commented 4 years ago

I have run into some issues where in some of my slides, $$\sigma_{x + 1} = \frac{1}{2}$$ works, but in others I need to escape the underscore as in $$\sigma\_{x + 1} = \frac{1}{2}$$