Katex: rendering $..$ and macros not work

Created on 17 Apr 2019  路  5Comments  路  Source: KaTeX/KaTeX

Hi. I have followed all the instructions to render with $ .. $ and it does not work. And neither when creating my macros

<body>
<script>
$(document).ready(function() { katex.render(formula, element, {
delimiters: [
{left: "$$", right: "$$", display: true},
{left: "\\[", right: "\\]", display: true},
{left: "$", right: "$", display: false},
{left: "\\(", right: "\\)", display: false} ],
macros: {
// Algebra-Precal
"\\lcm": "\\mathop{\\mathrm{lcm}}",
"\\sen" "\text{sen}\\",
// Calculus
"\\dd": "\\mathop{\\mathrm{d} #1}",
"\\abs": "\\lvert#1\\rvert",
}
});
});
</script>
</body>

the page with this problem is https://prob.matematicauniversitaria.com/

in the CSS I only have:

p{ font-family: times new roman; /*Latin Modern Math*/ font-size: 100% }
.katex{ font-size: 1.10em; /*1.16em dicen q es el 100%*/ }

and in the head I have the same thing that it provides https://katex.org/docs/autorender.html

What should I correct?
Thanks in advance.

bug

All 5 comments

@MathSalomon Thanks for providing a demo page! If you look at the JavaScript console, you'll see that you're getting several parse errors on the KaTeX side, which is why some of those formulas are failing to render.

I see some bugs in your macro code; in particular "\\sen" "\text{sen}\\", should be "\\sen": "\\text{sen}\\\\", (missing colons and missing escapes). Can you try with this corrected?

Thanks. I already made the correction
"\\sen": "\\text{sen}\\,",
be cause in latex the macro should be:
\newcommand{\sen}{\text{sen}\,} or
\newcommand{\sen}{\operatorname{sen}}

But, the result is the same in
https://prob.matematicauniversitaria.com/

capture

Can anyone help me please? :(

You aren't loading katex properly with your document.ready code, it looks like you aren't loading jquery so you can't use $(document).ready(. I have put a fixed version below.
You should also remove onload="renderMathInElement(document.body);" or maybe even the whole katex auto-render load line, as currently you are loading katex twice.

  document.addEventListener("DOMContentLoaded", function() {
  renderMathInElement(document.body, {
    delimiters: [
    {left: "$$", right: "$$", display: true},
    {left: "\\[", right: "\\]", display: true},
    {left: "$", right: "$", display: false},
    {left: "\\(", right: "\\)", display: false} ],
    macros: {
      // Algebra-Precal
      "\\lcm": "\\mathop{\\mathrm{lcm}}",
      "\\sen": '\\text{sen}\\,',
      // Calculus
      "\\dd": "\\mathop{\\mathrm{d} #1}",
      "\\abs": "\\lvert #1 \\rvert",
      }
  });
 });

Thank you.
Now I can see that it renders perfectly with the macros.

capture

I used

<script> document.addEventListener("DOMContentLoaded", function() { renderMathInElement(document.body, { delimiters: [ {left: "$$", right: "$$", display: true}, {left: "\\[", right: "\\]", display: true}, {left: "$", right: "$", display: false}, {left: "\\(", right: "\\)", display: false} ], macros: { // Algebra-Precal "\\lcm": "\\mathop{\\mathrm{lcm}}", "\\sen": '\\text{sen}\\,', // Calculus "\\dd": "\\mathop{\\mathrm{d} #1}", "\\abs": "\\lvert #1 \\rvert", } }); }); </script>

in the <body>

Best regards!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jason-s picture jason-s  路  3Comments

pvnr0082t picture pvnr0082t  路  4Comments

mpolyak picture mpolyak  路  3Comments

fabiospampinato picture fabiospampinato  路  4Comments

oddhack picture oddhack  路  3Comments