RyotaUshio / obsidian-inline-math

No longer disturbed by flickering inline math in Obsidian.
MIT License
18 stars 1 forks source link

Hidden Braces mess up tables #2

Closed heinrich26 closed 1 year ago

heinrich26 commented 1 year ago

Your hack to count the ${}... as one does not work inside tables/with the advanced tables plugin, thus formatting tables doesn't work anymore. You might want to look into advanced tables for a PR there to work arround this.

RyotaUshio commented 1 year ago

Hi, thanks for reporting this. Unfortunately, I couldn't see any problems in my quick test:

https://github.com/RyotaUshio/obsidian-inline-math/assets/72342591/242fcf4e-82b6-4320-9b41-902b35d7058c

  1. Can you reproduce it in the sandbox vault with only this plugin & Advanced Tables installed?
  2. If so, I would appreciate it if you could provide more information:
    • Result of the command "Show debug info"
    • .md file that can reproduce the problem
    • Screen recording with "Disable decorations" turned ON & "Disable atomic ranges" turned OFF" (these can be configured in the plugin settings)

Thank you in advance!

RyotaUshio commented 1 year ago

One possibility is that the debug mode (especially "Disable atomic ranges") might be turned on.

If your settings look like this, it's fine:

image
heinrich26 commented 1 year ago

Sorry, I should've been more clear ^^. As seen in your clip, the columns don't align anymore, that's my issue.

  1. I added this css-snippet to make the Latex Code have the same font size as the rest of the table. (You might need to disable the interactive editor)
    .cm-s-obsidian .HyperMD-table-row .cm-math {
    font-size: inherit;
    }

I'd want it to format to (look) exactly this: (of course keeping the ghost braces, just didn't bother writing them here)

| $E_{kin} = e \cdot U$ in $\text{eV}$         | 8   | 7    |
| -------------------------------------------- | --- | ---- |
| Wellenlänge $\lambda$ in $10^{-9}\ \text{m}$ | 120 | 133  |
| Frequenz $f$ in $10^{15}\ \text{Hz}$         | 2.5 | 2.26 |
| Auslösearbeit                                |     | 4.16 |

however, it'll look like this:

| ${} E_{kin} = e \cdot U$ in ${} \text{eV} {}$         | 8   | 7    |
| ----------------------------------------------------- | --- | ---- |
| Wellenlänge ${} \lambda$ in ${} 10^{-9}\ \text{m} {}$ | 120 | 133  |
| Frequenz $f$ in ${} 10^{15}\ \text{Hz}$               | 2.5 | 2.26 |
| Auslösearbeit                                         |     | 4.16 |

(the placement of ghost braces is also a bit strange there, but I don't mind...)

and being rendered as:

| $E_{kin} = e \cdot U$ in $\text{eV}$         | 8   | 7    |
| ----------------------------------------------------- | --- | ---- |
| Wellenlänge $\lambda$ in $10^{-9}\ \text{m}$ | 120 | 133  |
| Frequenz $f$ in $10^{15}\ \text{Hz}$               | 2.5 | 2.26 |
| Auslösearbeit                                         |     | 4.16 |

(this looks bad)

which shows that it counts {}$ as 4 chars instead of 1.

RyotaUshio commented 1 year ago

Ahh thanks for elaborating, I got it now.

As you might expect, I don't think this is something fixable within this plugin. As you know, this plugin presents ${} as if it were a single character $, but this hack only affects the UI and doesn't affect the actual/raw content of the note. And the Advanced Tables plugin seems to only care the actual content.

It seems that the only possibility is to sending a PR to Advanced Tables that patches this issue, although it's unclear whether they accept such a modification specific to this (pretty minor) plugin.

I might be able to find time to do that in the future, but I can't say when. If this problem is urgent for you, I'm sorry to say this but fixing it yourself may be the quickest solution.

RyotaUshio commented 1 year ago

Another workaround: simply disabling this plugin's feature inside tables. This seems to be doable within this plugin. What do you think? One thing to note is that essentially the same problem still remains even if this comes true because Advanced Tables doesn't care whether $ is hidden or not.

For example, this table

| col | col2 |
| --- | ---- |
| $a$ | $b$  |

is rendered like this even when this plugin is not installed:

image

Edit: If you're using Source mode, this won't be a problem

RyotaUshio commented 1 year ago

Released as 0.1.4. This is the best that I can do in a short term.

heinrich26 commented 1 year ago

Very nice, thanks alot ;)