obsidian-linter
                                
                                 obsidian-linter copied to clipboard
                                
                                    obsidian-linter copied to clipboard
                            
                            
                            
                        FR: empty lines before/after math environments and general math linting
Is Your Feature Request Related to a Problem? Please Describe.
I have alot of math equations in one md file. And I use LivePreview to edit them. I also want them to look tidy, so I add an empty line before and after them (for these standalone $$...$$ ones, not for the inline ones $...$).
Furthermore, when I have long equations I insert spaces before and after all =, +, - etc.
Describe the Solution You'd Like
Make several options, for linting math environments:
- before/after whole math block
- make the $$in their own line
- space before/after some symbols like =,+,-etc.
- space before \begin{}and after\end{}environment
- space before/after &and\\inside\begin{} ... \end{}environments (but dont separate eg&=)
Please include an example where applicable:
some text
$$\boldsymbol{w}=\begin{bmatrix}w_x \\ w_y\end{bmatrix} =
\begin{bmatrix}L_1 \cos(q_1)+L_2 \cos(q_1+q_2)\\L_1 \sin(q_1)+L_2 \sin(q_1+q_2)\end{bmatrix}=f(\boldsymbol{q}) \qquad\Rightarrow\qquad \boldsymbol{q}=\begin{bmatrix}q_1\\ q_2\end{bmatrix}=\text{?}=f^{-1}(\boldsymbol{w})$$
some more text
some text
$$
\boldsymbol{w} = \begin{bmatrix}w_x \\ w_y\end{bmatrix} =
\begin{bmatrix}L_1 \cos(q_1) + L_2 \cos(q_1+q_2) \\ L_1 \sin(q_1) + L_2 \sin(q_1+q_2)\end{bmatrix} =
f(\boldsymbol{q}) \qquad\Rightarrow\qquad \boldsymbol{q} = \begin{bmatrix}q_1 \\ q_2\end{bmatrix} =
\text{?} = f^{-1}(\boldsymbol{w})
$$
some more text
Describe Alternatives You've Considered
For now I do this manually...
Additional Context
I also use the plugin quick_latex_obisidan which is really handy (https://github.com/joeyuping/quick_latex_obsidian)
Thanks so far for the awesome plugin! I really eased my workflow. Keep up the good work :)
This is something that can likely be added, but it may take time. Right now I am focused on bugs and then the addition of a warning mode. I am open to PRs to add the desired changes in the meantime. It looks like the blank lines around the math block do not look difficult to add, but I am not sure about the other changes as they would likely take longer to add.
I just added logic to allow for math support if someone were to add it.
If you have some spare time, could you then please add the two 'simple' option to go from this:
some text
$$\boldsymbol{a}=\begin{bmatrix}a_x \\ a_y\end{bmatrix}$$
some more text
to that:
some text
$$
\boldsymbol{a}=\begin{bmatrix}a_x \\ a_y\end{bmatrix}
$$
some more text
so no change in the actual formuas, but have a blank line before and after the block and also put the mathmode-dollar signs on their own dedicated line? Thank you very much!
I can see about adding that this release (either this or next week is when it would get released).
I may also be able to add a textbox where you can add a list of strings you would like to put spaces around in the math block as well. The only problem is how to properly set that up as it would be a new type of rule. The problem I am seeing is not separating = and &=, but that will have to be handled at some point down the road.
Yes, the rule-maker for putting spaces around certain characters would be a thing that may achieve my "ideal" format. But this might take more time to implement. And in markdown it does not really matter how long the lines get. So this formatting of formulae with line breaks is really a personal preference and heavily depends on the actual line break length (aka line width).
I guess, the easiest to implement and clearest would be, to put \begin{#environment} and \end{#environment} in their own respective line. (Ofc as a toggleable option)
Although, I dont think that separating & and = eg in the align block actually makes a difference:
$$
\begin{align}
a & = 123456789 \\
b &= 123456789
\end{align}
$$
results in the same spacing.
As I see it, there are a couple of rules that are being requested here:
- Ensure blank lines around math blocks
- Put dollar signs ($$) on their own line
- Environments on their own line (my assumption is that an env is \begin{*}...\end{*}
- Allow for spacing to be added around specified strings in a math block
I plan on adding the first and second one tonight if I have time, but I wanted to make sure that I am not missing something. I am not the most familiar with Latex math blocks.
Also, I am pretty sure the following is considered inline math rather than block math:
$$\boldsymbol{a}=\begin{bmatrix}a_x \\ a_y\end{bmatrix}$$
I am not sure whether I am doing something wrong or if there is something messed up in my imports again, but the math blocks are not registering correctly for me from what I can tell. It keeps adding excess info.
The answer I get on https://github.com/remarkjs/remark/discussions/1056 will dictate how I proceed with this change.
Looks like the math parser does not automatically recognize any number of $$ as math blocks when they are on a single line. So I will need to figure out a way of getting the user to let me know what denotes a singe line math block.
Looks like the rule to format the math blocks will need to be run prior to other rules running since the following is all considered a single math block by the parser:
$$L = \frac{1}{2}
\rho v^2 S C_L$$
text here
Thus the formatting rule for getting the $$ on its own line would have to run before ensuring blank lines around the values as it would not be feasible to do so otherwise. This means that two rules will need to be turned on or a single rule that also allows you to specify what a single line version of the math block would be indicated by (i.e. how many $).
I have made changes that now allow for formatting math blocks where there is a general setting for determining how many dollar signs denote a math block. This looks to be working from my tests. I will move onto the the other logic for putting the math block indicators on their own line and also adding environments to be placed on their own lines as well in math blocks.
I believe I have something that will cover the rules for blank lines around math blocks and having the dollar signs on their own lines. However, I don't think I will be able to get to the environments being on their own lines at this time. I hope to have something ready for it by the time of the next release which is planned for this coming weekend, but that will depend on how a couple of other changes go.
This will have to go out piecemeal as I can address some things and not others. Right now it looks like the following 2 things can be done:
- Dollar signs on their own line when it is a math block and not inline math
- Empty lines around math blocks
The rest will have to wait for later releases.
Hi, thanks for adding the feature! But unfortunately, I encountered files, where the linting is not consistent. It seems like only the first few lines are checked and not the whole file, as the "putting dollar signs on their own line" just does not work at one point till the end of the document.
Here is an arbitrary 500 lines document i created for my studies, with which you might test out stuff: Rob_UB02.md (Linting the math environments stopped at line 36)
Thanks for taking a look into this.
Gotcha. I will take a look and see what is going on. It could be a nesting issue.