0

I have 2 .md files, formula.md and note.md. I want to put all the formula in formula.md and explain how to use them in note.md. I do not want to maintain 2 copies of formula in both files. Is that any way to make note.md show the formula stated in the formula.md?

I am using Obsidian and I aware that I can use the following method to embed or reference to the line of formula but that is not what I want. I hope the formula from formula.md can be showed inline in the note.md.

![[VIB#^e2b106]]
[[VIB#^e2b106]]
Sam
  • 1,252
  • 5
  • 20
  • 43

1 Answers1

1

TLDR; No, but you can have workarounds depending on your implementation

The official markdown specification doesn't have anything like that, but you can probably do some workarounds depending on what you use. Basically, you have to set it up:

Setup codebraid

codebraid is a build tool that lets you run code that is written and inserts the results as if it were templating. Here is a link to their repository: https://github.com/gpoore/codebraid#readme. As shown in this StackOverflow answer: https://stackoverflow.com/a/69659435/13514657, you can run some python code to read from a table and output the value there.

Here is an example for reading formula.md:

```{.python .cb.run}
with open('formula**strong text**.md') as fp:
    print(fp.read())
```

Write a plugin for your transpiler

If you are using something like remark, markdown-it, or markedjs, then they probably have a plugin system in which you can write a custom plugin that will allow you to import markdown files.

MarkedJS

  1. Insert the imports before passing them to markedjs
  2. Create a plugin that provides a tokenizer that marks imports with a special token and a renderer that transpiles the markdown to HTML with the given rendering configuration
  3. Create a renderer that detects an existing syntax (say links) with a special flag that will interpret it as an import

Web

Write a browser extension or userscript.

Visual Studio Code

You can write a markdown-it plugin and turn it into a Visual Studio Code extension. Here is an example where someone wrote their own markdown language: https://github.com/mjbvz/vscode-markdown-mermaid/blob/master/src/index.ts.

MDX

If you are using mdx, then it is as simple as importing the other file and displaying it inside your file.

import Formula from './Formula.mdx';

# My math work

## Formula

If you wanted to see the formula to do the above here it is:

<Formula />

Image

You could probably convert the markdown file into an SVG or take a screenshot of it and reference it, but of course, that means that you have to take a screenshot every single time.

Saiansh Singh
  • 583
  • 5
  • 16