What is principle of convert .tex to .pdf in LaTeX?

I am studying how to convert .tex to .pdf.

My goal is how to LaTex convert tex to pdf.

What is principle of convert .tex to .pdf?

I want to know process of compile.

Usually it’s either

lualatex document.tex

or

pdflatex document.tex

Sometimes you have to run the command twice to get the table of contents (or other indexes) right.