widcardw / obsidian-asciimath

Asciimath support for Obsidian (based on asciimath-parser)
MIT License
28 stars 2 forks source link

Alignment of block, can we have it left-aligned instead of centered? #12

Open stecydube opened 9 months ago

stecydube commented 9 months ago

As of now, having an asciimath block makes the block horizontally centered.

Can we have it left-aligned instead?

Even better, have a way to select the correct behavior in the block, or at least a setting?

Kudos for this excellent plugin 😊

kwinso commented 9 months ago

I think it can be done by adding an option for this (something like "align equations to the left"), and then tweaking MathJax settings just like here:

https://stackoverflow.com/a/61503435

I think it also worth thinking about block-local alignment, though I don't know what is the good way to implement this.

widcardw commented 9 months ago

I think it's okay to just use the inline asciimath, and it is a paragraph in markdown and will be automatically aligned left...🤔

stecydube commented 9 months ago

Yes, I'm using that for the moment. The only thing is it does not align the formulas this way.

kwinso commented 9 months ago

Also related to alignment. On mobile with new-syntax blocks (dollar signs), I get my math right-aligned for some reason:

Screenshot_20231001_120253

kwinso commented 9 months ago

^^^

This happens only with more than one line blocks.

widcardw commented 9 months ago

Oh, this is because the multiline formulas will be wrapped with aligned environment, and then the default style of Latex is aligned right, unless you use & at the start of each line.

The example below will be aligned right.

\begin{aligned}
aaaaa\\
bb
\end{aligned}

If you add a & at the beginning of each line, it will be aligned left.

kwinso commented 9 months ago

If you add a & at the beginning of each line, it will be aligned left.

But what about centered?

widcardw commented 9 months ago

The reason why I do not add a & at the beginning of each line in asciimath is that, if we meet this kind of formulas:

f(x) & = xe^x

f'(x) & = (x+1)e^x

f''(x) & = (x+2)e^x

Then all the f(x)s will be aligned left instead of sticking on the left edge of the equal sign.

In your case, it is recommended to just add a & at the beginning of each line of formula.

widcardw commented 9 months ago

I have no idea how to center all the aligned formulas. The way I've thought about is to split them into different blocks.

kwinso commented 8 months ago

How about adding some modifier like color inside of ASCIIMath parser library code?

It'll work like this:

centered(
   ... Centered ASCIIMath code... 
)
widcardw commented 8 months ago

I've found that if we use gathered environment, the formulas will be aligned center.

However, it's quite hard for this package to analyze when to stop at the closing paren. For example, there may be [x,y) in the center environment, and it will stop earlier and cause problems.

The only solution I can think about is to make backtick ` be the delimiter, thus deprecating some rarely used accent symbols.

kwinso commented 8 months ago

I'm thinking of rust multiline strings, which start and end with the #. In fact, it can be ## or ### as long as there's matching closing sequence.

So, what I'm trying to say is that we can find some rarely used character that is almost never used twice in a row, maybe even that same ## and use this as the delimiter.

aurkaxi commented 7 months ago

for multi line math block the '=' equal sign should be aligned in the middle. ....2x = 6 .... ......x = 3/2..

widcardw commented 7 months ago

for multi line math block the '=' equal sign should be aligned in the middle. ....2x = 6 .... ......x = 3/2..

The math block should be

2x &= 6

x &= 3

Then the equal sign will be aligned by their left edge, and the whole block is aligned center.