This is a workflow question.
Let’s say I have a Scricener project which consists of two parts. Part 1 is an extensice summary, written by moi. Part 2 is an annotated version of a law. I’d like to end up with a pdf containing an extensive ToC as well as an epub with a digital version of the ToC. The ToC is going to be four but probably five levels. So,
Compile to LaTeX gets me the pdf, but what about the epub?
Compiling in Scrivener to ePub3 will generate a ToC for e-readers as the first page of the book. This should normally be invisible to humans, but picked up by devices to show in Navigation UI.
Copying this content to a normal XHTML-file would provide a Contents file for human to see and navigatie.
Also, the Copy as ToC menu item would create a series of links you can Convert to a Contents page.
To recreate the four levels of your ToC, the structure of your Binder is important. Make sure all levels are nested you want them to show up in the ToC, and they are separated in Pages.
To handle the e-book after generation by Scrivener, I use https://sigil-ebook.com/.
If the project is producing .tex files with something akin to the Non-Fiction (LaTeX) project template, then it might be more difficult to untangle that into an ePub file—this project template is designed pretty much for a single-type workflow. That said, it does depend on how you use that project. If it is solely through the use of styles and section layouts to generate LaTeX markup, then it would be a whole lot easier to adapt to another compile format.
But on the other hand if you started with Markdown, and that is how you are getting LaTeX, then you may well not need to do much at all. You can use the Pandoc → ePub conversion from the Compile for menu. You should find threads on that that specifically, around here, so I think what is more interesting about a brand new thread here is, rather than reiterating the details of how to make a Pandoc ePub, is how to handle both that and LaTeX (possibly with MMD).