The javascript file that would be imported:
let objek = {
"subjek": "10mat",
"10mat1": {
"id": "10mat1",
"noPertanyaan": 1,
"pertanyaan": "",
"jawaban": {
"a": "$ b - a < x - y < a - b $",
"b": "$ a - b < x - y < b - a $",
"c": "$ \frac {1}{2}\\ (b-a) < x - y < \frac {1}{2}\\ (a-b) $",
"d": "$ \frac {1}{2}\\ (a-b) < x - y < \frac {1}{2}\\ (b-a) $"
},
"kunci": "c"
},
"10mat2": {
"id": "10mat2",
"noPertanyaan": 2,
"pertanyaan": "",
"jawaban": {
"a": "$ 2 [\leq x \leq 3 $",
"b": "$ -1 \leq x \leq 2 $",
"c": "$ x \leq{2}\ \text{atau}\ x \geq{3}\ $",
"d": "$ x \leq{-1}\ \text{atau}\ x \geq{2}\ $"
},
"kunci": "e"
}
}
module.exports = objek
When I import this file, and I JSON.stringify and JSON.parse it, $ -1 \leq x \leq 2 $
becomes $ -1 leq x leq 2 $
, how can I fix this / make the JSON parser ignore the escape characters intended for a TeX syntax?
I tried to turn \
into \\
and also tried using .raw
but both don't work. I used a JS file instead of JSON because JSON wouldn't accept invalid escape characters but JS does, at least its what it seems. Like I said above, it simply ruins the TeX syntax when it's imported, even before it gets stringified and parsed.
I'm trying to write mathematical equations with MathJax so that it wouldn't be hard to display TeX on HTML, but as it turns out, I'm bombarded by problems on escape characters instead.