Reputation: 827
I am using the Desmos API for a math project and am trying to set the latex of an expression to f(x) = { x^2 : x > 1}
for piecemeal function. However, I cannot get the {
or }
within the latex. Function does not work without this character.
I have also used Mathquill for this equation to give me correct latex but even that (f\left(x\right)=\left\{x^2:x>1\right\}
) does not work
I have been searching around stackoverflow and google for a while now. I have attempted \{\}
, \\left( \\right)
only provide (
and )
. Nothing will seem to work.
<div id="calculator" style="width: 100%; height: 500px"></div>
var elt = document.getElementById('calculator');
var calculator = Desmos.GraphingCalculator(elt);
calculator.setExpression({
id:'1',
latex: "f(x)=\{x^2:x>1\}"
});
The curly braces are destroyed and the piecemeal function is not applied
This doesn't return any errors to my console. The only error is on the desmos calculator which says it doesnt understand why ":" is present (It would not do this if there was curly brackets specifying its the piecemeal function). The correct result should be
f(x) = {x^2 : x > 1}
but the actual result is
f(x) = x^2 : x > 1
Upvotes: 3
Views: 704
Reputation: 1817
You need to double escape the curly braces and you also have your condition and value reversed. Here is a working snippet.
var elt = document.getElementById('calculator');
var calculator = Desmos.GraphingCalculator(elt);
calculator.setExpression({
id:'1',
latex: "f(x)=\\left\\{x>1:x^2\\right\\}"
});
<script src="https://www.desmos.com/api/v1.3/calculator.js?apiKey=dcb31709b452b1cf9dc26972add0fda6"></script>
<div id="calculator" style="width: 100%; height: 500px"></div>
Upvotes: 2