Skip to content

how can i use variables as katex functions? #2094

Answered by edemaine
xed3x asked this question in Q&A
Discussion options

You must be logged in to vote

Here are a few ways:

  1. using template literals:
    katex.render(`${a} + ${b} = ${c}`, symbole_40d);
  2. Using + operator on strings, like you did in the console.log call:
    katex.render(a + ' + ' + b + ' = ' + c, symbole_40d);
  3. Using KaTeX macros:
    katex.render("\\a + \\b = \\c", symbole_40d, {
      macros: {
        "\\a": a,
        "\\b": b,
        "\\c": c,
      }
    });
    (Note that this overrides the default meaning of \c (a type of accent). It might be better to call the macro something else.)

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ylemkimon
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2094 on August 10, 2020 15:43.