|
hbghlyj
Posted at 2023-4-18 06:05:24
Mathpix官方API文档是用Python写的,需要转成Javascript
online converter to convert Python code to JavaScript:
Response: json() method
- const APP_ID='APP_ID', APP_KEY='APP_KEY';
- function mathpix(img){
- text=fetch("https://api.mathpix.com/v3/text", {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'app_id': APP_ID,
- 'app_key': APP_KEY
- },
- body: JSON.stringify({
- "src": img.src,
- "math_inline_delimiters": ["$", "$"],
- "rm_spaces": true
- })
- })
- .then(response => response.json())
- .then((data) =>img.replaceWith(data.text))
- .catch(console.error);
- }
Copy the Code 成功从网页图片中获取LaTeX代码:
其中.catch(console.error) 的作用是:如果出现网络错误,它将在控制台中提示错误:
TypeError: NetworkError when attempting to fetch resource. |
|