Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
Escape backslash in math formula String

I use MathJax with React to display math formulas (mathjax-react). I need to extract the formula code from a JSON.

I have this :

import React from 'react'
import { MathComponent } from 'mathjax-react'

function Card({ formula }) {
    return (
         <div>
               <MathComponent tex={String.raw`\int_0^1 x^2\ dx`} />
         </div>
    )
}

Instead I want to insert the formula :

<MathComponent tex={ formula } />

formula will be extracted from a JSON :

{
    "formula": `\int_0^1 x^2\ dx`
}

But JSON does not permit using backticks. And String.raw seems to work escape backslash correctly only with backticks. I would like to escape \ without modify the TeX formula (like adding a second \ manually).

How could I do?

Thanks!

PS: I precise that there can be multiple backslash and everywhere in the string. Here some examples and how to create a math formula. Using String.raw() as un function, the backslash is not extracted without the character just after. Only String.raw with backticks works well.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

JS

const fx = {
  formula: `\int_0^1 x^2\ dx`
};

const formula = "\\" + String.raw({ raw: fx.formula });

in JSX

<MathComponent tex={formula} />

Codesandbox example https://codesandbox.io/s/late-morning-538gf

MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda