OK, after some investigation I found a promising direction.
By default, the protocols that we are allowed to use in \href
are the following.
- file:
- http:
- https:
(You can check it by MathJax.config.options.safeOptions.safeProtocols
)
So we can’t use obsidian:
or javascript:
to open a note in the vault. However, we can change this setting afterward. For example, running the following in the dev console (or as a Templater/QuickAdd startup script) will enable us to use Obsidian URI inside \href
.
MathJax.config.options.safeOptions.safeProtocols.obsidian = true;
MathJax.startup.getComponents();
For example: $\href{obsidian://open?vault=my%20vault&file=my%20note}{link}$
This way we can insert a link to another note inside an equation. Also it will be possible to create a plugin that renders [[internal link|display text]]
as if it were \href{obsidian://...}{display text}
.
Find more information at:
- Configuring and Loading MathJax — MathJax 3.2 documentation
- Safe Extension Options — MathJax 3.2 documentation
Remark
There are some important concerns regarding using [[internal links]]
or \href
with Obsidian URIs:
- It will make our notes more Obsidian-dependent and less future-proof.
- They will not appear in the graph view or backlink view (this is the biggest drawback for me). So it would be best if it could be implemented as a core feature of Obsidian (not as a plugin)