-
I am trying to work on formatting some math blocks using remark to identify math blocks as opposed to inline math as the formatting I want to apply is different for each type. The problem is that the following seems to be considered inline math instead of block math: Here are two places that I have seen references stating that
Now I could just be doing something wrong or have some kind of format misunderstanding, so I wanted to check here if that was the case. Here is the AST parser result for the math provided above: https://astexplorer.net/#/gist/111c4f5728f9c80696a9422a7c9c99f0/aa4f9e212560494d7ebb5d826e6777137afa59d1 Here is also how I am reproducing the issue with a clean setup of the package: {
"name": "example",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"remark-gfm": "^3.0.1",
"remark-math": "^5.1.1",
"remark": "^14.0.2",
"unified": "^10.1.2"
}
}
# Header
$$\boldsymbol{a}=\begin{bmatrix}a_x \\ a_y\end{bmatrix}$$
some more text
$$L = \frac{1}{2} \rho v^2 S C_L$$
import fs from "node:fs/promises";
import {visit} from 'unist-util-visit';
import {remark} from 'remark';
import remarkMath from 'remark-math';
import remarkGfm from 'remark-gfm';
const file = await fs.readFile("example.md");
const fileContents = String(file);
const ast = remark().use(remarkGfm).use(remarkMath).parse(file);
console.log(ast)
visit(ast, 'math', (node) => {
console.log(fileContents.substring(node.position.start.offset, node.position.end.offset) + '\nEND\n')
});
visit(ast, 'inlineMath', (node) => {
console.log(fileContents.substring(node.position.start.offset, node.position.end.offset) + '\nEND2\n')
}); Here is the output I am getting:
I am expecting
I am on npm version Please let me know if this is how it is supposed to work. If that is the case, I can manage this by checking to see if the inline math block is surrounded by more than 1 Thanks for the help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Math has no spec. Nobody knows what should happen. Not everyone agrees that what you want, is the way it should happen. Particularly, in our case, we follow how code works in markdown, with two exceptions:
```inline code```
```
block code
``` For more information on how syntax works in our syntax plugins, see the Syntax section in each readme. |
Beta Was this translation helpful? Give feedback.
Math has no spec. Nobody knows what should happen. Not everyone agrees that what you want, is the way it should happen.
Particularly, in our case, we follow how code works in markdown, with two exceptions:
Code works like this:
For more information on how syntax works in our syntax plugins, see the Syntax section in each readme.
In this case: https://github.com/remarkjs/remark-math/tree/main/packages/remark-math#syntax