Convert ChatGPT Formula Format to Obsidian-Compatible Format
The formulas generated by ChatGPT use the following format:
1 | \[ |
However, Obsidian renders formulas using the following format:
1 | $$ |
When copying a formula from ChatGPT to Obsidian, this difference prevents proper rendering.
Solution
We can create a script for Obsidian to automatically replace the formula format when pasting.
1. Create the Script
We can solve this issue using a plugin in Obsidian.
In your vault, create a file named fixlatex.js
under the template
directory, and input the following content:
1 | module.exports = async (params) => { |
2. Set Up the Script in QuickAdd
Install the QuickAdd plugin and create a Macro
, configuring it as shown below, then save it. The first step in the Macro is to execute our user script fixlatex.js
, the second step is to wait for 100 milliseconds, and the third step is to execute the paste action.
3. Set Sidebar Shortcut in Commander
Install the Commander plugin and set up the QuickAdd action we just created as a sidebar shortcut. You can also skip this step and directly use an Obsidian command to execute this action.
4. Verify the Effect
Now, on the ChatGPT webpage (currently there seems to be an issue when clicking the copy button in the app), click the copy button, then in Obsidian, click the sidebar shortcut or manually execute the QuickAdd command. This will copy the content from ChatGPT to Obsidian and automatically convert the LaTeX format.