How can I make some version of exercises from a list and get the LaTeX file?

I have a list

list = {{{6, 8, 5}, {7, 4, 2}, {9, 3, 1}}, {{6, 8, 5}, {7, 4, 3}, {9,
1, 2}}, {{6, 8, 5}, {7, 4, 3}, {9, 2, 1}}, {{6, 9, 1}, {7, 2,
3}, {8, 4, 5}}, {{6, 9, 1}, {7, 2, 3}, {8, 5, 4}}, {{6, 9, 1}, {7,2, 4}, {8, 3, 5}}}

and write the equation of the plane passing through three points of each element of list.

Table[{pA, pB, pC} = points;
mylist = {pA, pB, pC,
TraditionalForm[Subtract @@ Expand[CoplanarPoints[{pA, pB, pC, {x, y, z}}]]] == 0}, {points, list}]

I want to make some exercises in LaTeX like this:

\documentclass[12pt,a4paper]{article}
\usepackage[left=2cm, right=2cm, top=2cm, bottom=2cm]{geometry}
\usepackage{amsmath}
\usepackage{amsthm}
\theoremstyle{definition}
\newtheorem{ex}{Exercise}
\begin{document}
\begin{ex}
The equation of the plane passing through three points $A(6, 8, 5)$, $B(7, 4, 2)$, $C(9, 3, 1)$ is $x-5 y+7 z-1=0$.
\end{ex}
\begin{ex}
The equation of the plane passing through three points $A(6, 8, 5)$, $B(7, 4, 3)$, $C(9, 1, 2)$ is $2 x+3 y-5 z-11=0$.
\end{ex}
\begin{ex}
The equation of the plane passing through three points $A(6, 8, 5)$, $B(7, 4, 3)$, $C(9, 2,1)$ is $2 x-y+3 z-19=0$.
\end{ex}
\begin{ex}
The equation of the plane passing through three points $A(6, 9, 1)$, $B(7, 2, 3)$, $C(8, 4, 5)$ is $2 x-z-11=0$.
\end{ex}
\end{document}

How can I tell Mathematica to do this?

1 Answer

Code below generates

The LaTeX generated by Mathematica is

\documentclass[12pt,a4paper]{article}
\usepackage[left=2cm, right=2cm, top=2cm, bottom=2cm]{geometry}
\usepackage{amsmath}
\usepackage{amsthm}
\theoremstyle{definition}
\newtheorem{ex}{Exercise}
\begin{document}
\begin{ex}
The equation of the plane passing through three points $A(6,8,5)$, $B(7,4,2)$, $C(9,3,1)$ is $x-5 y+7 z-1=0$
\end{ex}
\begin{ex}
The equation of the plane passing through three points $A(6,8,5)$, $B(7,4,3)$, $C(9,1,2)$ is $2 x+3 y-5 z-11=0$
\end{ex}
\begin{ex}
The equation of the plane passing through three points $A(6,8,5)$, $B(7,4,3)$, $C(9,2,1)$ is $2 x-y+3 z-19=0$
\end{ex}
\begin{ex}
The equation of the plane passing through three points $A(6,9,1)$, $B(7,2,3)$, $C(8,4,5)$ is $2 x-z-11=0$
\end{ex}
\begin{ex}
The equation of the plane passing through three points $A(6,9,1)$, $B(7,2,3)$, $C(8,5,4)$ is $13 x-y-10 z-59=0$
\end{ex}
\begin{ex}
The equation of the plane passing through three points $A(6,9,1)$, $B(7,2,4)$, $C(8,3,5)$ is $5 x-y-4 z-17=0$
\end{ex}
\end{document}

Code from clean kernel

SetDirectory[NotebookDirectory[]]
list = {{{6, 8, 5}, {7, 4, 2}, {9, 3, 1}}, {{6, 8, 5}, {7, 4, 3}, {9,
1, 2}}, {{6, 8, 5}, {7, 4, 3}, {9, 2, 1}}, {{6, 9, 1}, {7, 2,
3}, {8, 4, 5}}, {{6, 9, 1}, {7, 2, 3}, {8, 5, 4}}, {{6, 9, 1}, {7,
2, 4}, {8, 3, 5}}};

data = Table[{pA, pB, pC} = points;
mylist = {pA, pB, pC,
Subtract @@ Expand[CoplanarPoints[{pA, pB, pC, {x, y, z}}]] ==
0}, {points, list}]

toX[e_]:=StringReplace[ToString[TeXForm[e]],{"\\}"->")","\\{"->"("}]

fileName=FileNameJoin[{Directory[],"my_HW.tex"}]
If[FileExistsQ[fileName],DeleteFile[fileName]];
file=OpenWrite[fileName,PageWidth->Infinity];
WriteString[file,"\\documentclass[12pt,a4paper]{article}\n"<>
"\\usepackage[left=2cm, right=2cm, top=2cm, bottom=2cm]{geometry}\n"<>
"\\usepackage{amsmath}\n"<>
"\\usepackage{amsthm}\n"<>
"\\theoremstyle{definition}\n"<>
"\\newtheorem{ex}{Exercise}\n"<>
"\\begin{document}\n"];
Do[WriteString[file,"\\begin{ex}\n"<>
"The equation of the plane passing through three points $$A"<> toX[data[[n,1]]] <>"$$, $$B"<>toX[data[[n,2]]]<> "$$, $$C"<>toX[data[[n,3]]]<>"$$ is $$"<>toX[data[[n,4]]]<> "$$\n\\end{ex}\n"],{n,1,Length@data}
];
WriteString[file,"\\end{document}\n"];
Close[file]
• Does your code support Vietnamese? Commented May 19 at 12:02
• @JohnPaulPeter , Yes, Latex handle other langauges, Add \usepackage[utf8]{inputenc} and \usepackage[vietnam,english]{babel} to the preamble. See tex.stackexchange.com/questions/40482/… But the question is how to enter Vietnamese Language as string inside the notebook in Mathematica itself. I could not do it. Mathematica messes up the string when writing it to the file using WriteString. So this is the issue to solve. But Latex itself can handle other languages and even mixed ones inside same document. Commented May 19 at 19:56
• @JohnPaulPeter You could make separate question asking how to write Vietnamese in string in Mathematica and save it to file without the characters getting missed up. I am sure someone will know how. If there is a way, then you can adopt it to the above code. Commented May 19 at 20:02
• If I want to use data[[n,1]] in stead of $A"<>toX[data[[n,2]]]<>"$ and data[[n,2]] in stead of $B"<>toX[data[[n,2]]]<>"$ to calculate data[[n,2]] - data[[n,1]]. How can I do that? Commented Jun 5 at 2:16
• @JohnPaulPeter I do not understand. data[[n,1]] and data[[n,2]] need to be converted to Latex then to String to be written to file. If you do not want to do that, you can try replacing $A"<>toX[data[[n,1]]]<>"$ with just String[ data[[n,1]] ] and same for data[[n,2]] and see if this what you wanted. Commented Jun 5 at 8:28