# LaTeX - errors while compiling to pdf - sometimes

I'm writing my assignments in latex. Everything works cool, but time to time, when i press F1, a lot of errors occur. Like everything should be wrong even if I pressed F1 2 minutes ago. When I save the file with a new name in a new file, everything works again, as i should. Does anybody know where could be this weird problem of a random "rebellion" of LaTeX?

Example of one error

 ! Missing $inserted. <inserted text>$
l.7 ... {1.2}_Historie e-knih}{10}{subsection.1.2}
I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.
! Extra }, or forgotten $. <argument> ...}{\numberline {1.2}_Historie e-knih} \hyper@linkend l.7 ... {1.2}_Historie e-knih}{10}{subsection.1.2} I've deleted a group-closing symbol because it seems to be spurious, as in $x}$'. But perhaps the } is legitimate and you forgot something else, as in \hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing I\$}'.


• Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Reinstate Monica - M. Schröder Feb 1 '18 at 9:02
• Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. – Werner Feb 2 '18 at 17:20

This problem only occurs on the second run since it's not in your .tex source file, but in the .aux or .toc file, which are generated by the first run. When you save with a different file name, you generate new aux etc. files, which is why the problem seems to go away.
It's also possible that not all of the commands you use in your section title are what is called robust, which boils down to you can't have them in footnotes, section titles, etc. Try prepending \protect to those, that might help. (You will still need to delete the aux and toc` files and compile twice.)