# How to document math formulations in scientific computing codes?

I am writing the code relate to math.

There is some complicated math formulation in the project.

Directly writing the calculation code leads to hard understanding; thus I want to comment on the formulation.

I want the comment can be readable, and easy for understand.

I know we can save the formulation in another document file like latex or markdown. But it always leads to the code is modified but the document is not updated. At that time, the document is useless and even harmful.

• If your text editor and compiler don't complain about non-standard unicode characters, you can directly insert mathematical symbols into a comment for convenience. I use the :digraph command in vim to write out formulations in the comment preceding a function that implements a complicated calculation. Of course, the comment does not get typeset, so you're still a bit limited in what you can do. – smh Jul 13 '20 at 13:14