What tool do you use to write an ebook?

I'm currently looking for a tool to use in my "scientific research" for school tomorrow. Any suggestions? It will contain many code snippets so I thought LibreOffice/MS Word won't be enough.

Update: will try to experiment with but open to suggestions

I’m partial to writing in Markdown using iA Writer. It’s a super low friction way to write, which I enjoy.

iA Writer can do a passable export to pdf I think. For Serverless Handbook, I used to export to the various formats. Did great

I’ve also heard asciidoc as a popular suggestion when markdown isn’t enough anymore. Haven’t tried it myself

I've written a few using -- Solid editor and all the exports needed but unsure if it has all the snippets you need.

Thanks for all the suggestions!

In the end, found Ibis, made a few changes and it worked well

Also used Sublime Text to write markdown