I have been using Zim[0] for quite few years now. With various plugins, it allows me to write LaTeX equations, formatted code, tables etc. Overall it has been really good, but I feel the only thing missing is the support for mobile devices.
[0]: http://zim-wiki.org/