React-Latex Repeats the text

457 views Asked by At

I'm trying to use the package react-latex to create pretty mathematical notation. Whenever I type the latex string, it repeats the text twice - once in pretty latex rendering, once in non-pretty latex rendering. For example the code below produces the text twice once as an exponent and once as an ugly "a2"

import Latex from 'react-latex'
export default function Home() {
  <div>
    <Latex> $$\a^2 $$</Latex>
  </div>
}
3

There are 3 answers

0
Nick B On

Looks like there is an 'output' option. It displays both by default.

https://katex.org/docs/options.html

The docs for the react component aren't very clear but maybe try

<Latex output="mathml"> $$\a^2 $$</Latex>
0
Luis Colon On

In LaTeX, to represent an exponent, you should use the caret (^) symbol followed by the exponent value. However, in your code, you are using a backslash () before the letter "a", which is causing the duplication.

import Latex from 'react-latex';

export default function Home() {
  return (
    <div>
      <Latex> $$a^2$$ </Latex>
    </div>
  );
}

Hope this helps :)

1
Iam Cardona On

Install katex and react-katex packages and that will solve it