I haven't saved it.
Well, if you do not save the latex to the file, it will not work. Here is a small template to use. This creates index.tex file, solves few integrals and solves an ode and saves the result. This shows how to use variables inside the latex and the final latex file and the PDF generated after compiling the pdf file.
SetDirectory[NotebookDirectory[]]
fileName = "index.tex";
file = OpenWrite[fileName, PageWidth -> Infinity];
ClearAll[x];
integrals = {Sin[x], x*Cos[x], Tan[x]}
toX[expr_] := ToString@TeXForm[expr];
s = "\\documentclass[12pt]{article}
\\usepackage{amsmath}
\\begin{document}
";
WriteString[file, s];
s = "Let us solve few integral problems to show how good Mathematica is
\\begin{align*}
";
WriteString[file, s];
Do[
currentIntegrand = integrals[[n]];
If[n < Length[integrals], end = "\\\\ \n", end = "\n"];
s = "\\int{" <> toX[currentIntegrand ] <> "\\,dx}&=" <>
toX[Integrate[currentIntegrand, x ]] <> " + c_1" <> end;
WriteString[file, s];
, {n, Length[integrals]}
]
s = "\\end{align*}
Mathematica can also solve differential equations. For example for \
the ode ";
WriteString[file, s];
ode = y''[x] + y'[x] + y[x] == 0;
s = "$" <> toX[ode] <> "$ it gives this solution
\\[
" <> toX[DSolve[ode, y[x], x]] <> "
\\]
Now we can close the file. Good bye.
\\end{document}
"
WriteString[file, s]
Close[file]
After you run the above there will be a file index.tex
in same folder.
\documentclass[12pt]{article}
\usepackage{amsmath}
\begin{document}
Let us solve few integral problems to show how good Mathematica is
\begin{align*}
\int{\sin (x)\,dx}&=-\cos (x) + c_1\\
\int{x \cos (x)\,dx}&=x \sin (x)+\cos (x) + c_1\\
\int{\tan (x)\,dx}&=-\log (\cos (x)) + c_1
\end{align*}
Mathematica can also solve differential equations. For example for the ode $y''(x)+y'(x)+y(x)=0$ it gives this solution
\[
\left\{\left\{y(x)\to c_2 e^{-x/2} \cos \left(\frac{\sqrt{3} x}{2}\right)+c_1 e^{-x/2} \sin \left(\frac{\sqrt{3} x}{2}\right)\right\}\right\}
\]
Now we can close the file. Good bye.
\end{document}
After you compile it using your Latex compiler, here is the result
You can now adjust the above to your needs.