Question: How can I put the results of Maple in to a TeX file in environment \begin{ex} \end{ex} like this>

I have this file
 

restart:
F := proc(ee,LL)
  uses InertForm, Typesetting;
  mrow(Typeset(Display(eval(eval(MakeInert(factor(ee)),[`%*`=`*`])
                                 =MakeInert(subs(b=MakeInert(b*y)/y,
                        a=MakeInert(a*x)/x,p)),[a,b]=~LL),
                       inert=false)),
       mo("="),Typeset(eval(ee,[a,b]=~LL)))
end proc:
p := (a*x)^2 - 2*a*x*b*y + (b*y)^2:
L := [[sqrt(2),3],[2,5],[3,12],[1/3,5/7]];
ans := F~(p, L):
print~(ans):

How can I put the results like this
 

\documentclass[12pt,a4paper]{article}
\usepackage[left=2cm, right=2cm, top=2cm, bottom=2cm]{geometry}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{enumitem}
\theoremstyle{definition}
\newtheorem{ex}{Exercise}
\begin{document}
\begin{ex}
\[(\sqrt{2} x-3 y)^2=(\sqrt{2} \cdot x)^2-2 \cdot(\sqrt{2} \cdot x) \cdot(3 \cdot y)+(3 \cdot y)^2=2 x^2-6 \sqrt{2} x y+9 y^2.\]
\end{ex}

\begin{ex}
\[(2 x-5 y)^2=(2 \cdot x)^2-2 \cdot(2 \cdot x) \cdot(5 \cdot y)+(5 \cdot y)^2=4 x^2-20 x y+25 y^2. \]
\end{ex}

\begin{ex}
\[(3 x-12 y)^2=(3 \cdot x)^2-2 \cdot(3 \cdot x) \cdot(12 \cdot y)+(12 \cdot y)^2=9 x^2-72 x y+144 y^2. \]
\end{ex}

\begin{ex}
\[\left(\frac{x}{3}-\frac{5 y}{7}\right)^2=\left(\frac{1}{3} \cdot x\right)^2-2 \cdot\left(\frac{1}{3} \cdot x\right) \cdot\left(\frac{5}{7} \cdot y\right)+\left(\frac{5}{7} \cdot y\right)^2=\frac{1}{9} x^2-\frac{10}{21} x y+\frac{25}{49} y^2. \]
\end{ex}
 
\end{document} 

Please Wait...