About using \\ to wrap lines in latex mathematical formula

Things I have tried

I tried to use \\ in inline and block mathematical formulas to wrap lines. It could work correctly in Typora but failed in Obsidian.

I think it may be because of the settings of MathJax. So I should change which item in Obsidian or MathJax to let \\ work likely in Typora.

Thank you!

\\ in Typora

\\ in Obsidian

You have to specify that it’s an align environment in Obsidian

$$\begin{align}
first \\
second
\end{align}$$

Use an ampersand to specify where you want the align to be, e.g.

$$\begin{align}
x & = [something] \\
& = [something]
\end{align}$$

Thank you very much.

Does this mean I can’t use \\ like in Typora? I have many notes written in Typora, which have many expressions like this. It’s really hard work to transform these notes.

I’m by no means an expert on LaTeX, so I may be wrong, but AFAIK you would have to add the \begin{align}...\end{align} to your Typora notes when moving them to Obsidian.

I tried to write a Python script that would do this for you but I’m also not a Python expert so I couldn’t figure out how to make it work properly. I might return to it later if I have time.

Alright I actually figured it out. This should be able to detect all .md files in a directory and basically change

$$
math stuff here
$$

to

$$\begin{align}
math stuff here
\end{align}$$

Note:

  • This will overwrite the file contents, so make a backup before you run it
  • Before you run the script, open it in a text editor (i.e. Notepad) and change line 3 to your target folder
  • This won’t touch files in subdirectories. You will have to change line 3 again and re-run the program for any notes in other directories or subdirectories

I hope this helps!

1 Like

I don’t know how to express my appreciation. Thank you very much.

1 Like