# How can I convert a list containing three points and its equation passing three points to text file?

I have a lis

{{{-12,2,-1},{-11,1,-5},{-10,-2,3},10 x+6 y+z+109==0},{{-12,2,-1},{-11,1,-5},{-10,6,3},2 x-2 y+z+29==0},{{-12,2,-1},{-11,1,-5},{-9,5,-7},3 x-y+z+39==0}}


I would like to conver lis to text file has the form

\documentclass[12pt,a4paper]{article}
\usepackage{enumitem}
\usepackage[left=2cm,right=2 cm,top=2cm,bottom=2cm]{geometry}
$$\begin{document} \begin{enumerate}[label=\arabic*)] \item A(-12,2,-1), \quad B(-11,1,-5), \quad C(-10,-2,3), \quad (P):10 x+6 y+z+109=0. \item A(-12,2,-1), \quad B(-11,1,-5), \quad C(-10,6,3), \quad (P):2 x-2 y+z+29=0. \end{enumerate} \end{document}$$


I tried

lis={{{-12,2,-1},{-11,1,-5},{-10,-2,3},10 x+6 y+z+109==0},{{-12,2,-1},{-11,1,-5},{-10,6,3},2 x-2 y+z+29==0},{{-12,2,-1},{-11,1,-5},{-9,5,-7},3 x-y+z+39==0}}
SetDirectory[NotebookDirectory[]]
fileName=FileNameJoin[{Directory[],"plane.tex"}]
If[FileExistsQ[fileName],DeleteFile[fileName]];
file=OpenWrite[fileName,PageWidth->Infinity];
WriteString[file,"\\documentclass[12pt,a4paper]{article}\n"<>"\\usepackage{enumitem}\n"<>"\\begin{document}\n"<>"\\begin{enumerate}[label=\\arabic*)]\n"];

z=StringReplace[z,"{"->"$$("]; z=StringReplace[z,"}"->")$$"];
WriteString[file,"\\item "<>z<>"\n"],{n,1,Length@lis}];
WriteString[file,"\\end{enumerate}\n\\end{document}\n"];
Close[file]


I only get

\documentclass[12pt,a4paper]{article}
\usepackage{enumitem}
$$\begin{document} \begin{enumerate}[label=\arabic*)] \item (-12, 2, -1), \quad (-11, 1, -5) \item (-12, 2, -1), \quad (-11, 1, -5) \item (-12, 2, -1), \quad (-11, 1, -5) \end{enumerate} \end{document}$$


This code generates this PDF

Code

ClearAll["Global*"]
lis = {
{{-12, 2, -1}, {-11, 1, -5}, {-10, -2, 3},
10 x + 6 y + z + 109 == 0},
{{-12, 2, -1}, {-11, 1, -5}, {-10, 6, 3}, 2 x - 2 y + z + 29 == 0},
{{-12, 2, -1}, {-11, 1, -5}, {-9, 5, -7}, 3 x - y + z + 39 == 0}
}

SetDirectory[NotebookDirectory[]]
fileName = FileNameJoin[{Directory[], "main.tex"}]
If[FileExistsQ[fileName], DeleteFile[fileName]];
file = OpenWrite[fileName, PageWidth -> Infinity];
WriteString[file, "\\documentclass[12pt,a4paper]{article}\n" <>
"\\usepackage{enumitem}\n" <>
"\\begin{document}\n" <>
"\\begin{enumerate}[label=\\arabic*)]\n"];

format[e_List] := ("A" <> ToString[e[[1]]] <> ",\\quad B" <>
ToString[e[[2]]] <> ",\\quad C" <> ToString[e[[3]]] <>
",\\quad (P) : $$" <> ToString[TeXForm[e[[4]]]] <> "$$");
Do[myTMP = format[lis[[n]]];
myTMP = StringReplace[myTMP, "{" -> "("];
myTMP = StringReplace[myTMP, "}" -> ")"];
WriteString[file, "\\item " <> myTMP <> "\n"],
{n, 1, Length@lis}
];
WriteString[file, "\\end{enumerate}\n\\end{document}\n"];
Close[file]


Latex file generated

\documentclass[12pt,a4paper]{article}
\usepackage{enumitem}
$$\begin{document} \begin{enumerate}[label=\arabic*)] \item A(-12, 2, -1),\quad B(-11, 1, -5),\quad C(-10, -2, 3),\quad (P) : 10 x+6 y+z+109=0 \item A(-12, 2, -1),\quad B(-11, 1, -5),\quad C(-10, 6, 3),\quad (P) : 2 x-2 y+z+29=0 \item A(-12, 2, -1),\quad B(-11, 1, -5),\quad C(-9, 5, -7),\quad (P) : 3 x-y+z+39=0 \end{enumerate} \end{document}$$


Update

To make each field Math, you can use this version

Code

ClearAll["Global*"]
lis = {
{{-12, 2, -1}, {-11, 1, -5}, {-10, -2, 3},
10 x + 6 y + z + 109 == 0},
{{-12, 2, -1}, {-11, 1, -5}, {-10, 6, 3}, 2 x - 2 y + z + 29 == 0},
{{-12, 2, -1}, {-11, 1, -5}, {-9, 5, -7}, 3 x - y + z + 39 == 0}
}

SetDirectory[NotebookDirectory[]]
fileName = FileNameJoin[{Directory[], "main.tex"}]
If[FileExistsQ[fileName], DeleteFile[fileName]];
file = OpenWrite[fileName, PageWidth -> Infinity];
WriteString[file, "\\documentclass[12pt,a4paper]{article}\n" <>
"\\usepackage[letterpaper,margin=1.2in]{geometry}\n" <>
"\\usepackage{enumitem}\n" <>
"\\begin{document}\n" <>
"\\begin{enumerate}[label=\\arabic*)]\n"];

format[e_List] := ("$$A" <> ToString[e[[1]]] <> "$$,\\quad $$B" <> ToString[e[[2]]] <> "$$,\\quad $$C" <> ToString[e[[3]]] <> "$$,\\quad $$(P) : " <> ToString[TeXForm[e[[4]]]] <> "$$");
Do[myTMP = format[lis[[n]]];
myTMP = StringReplace[myTMP, "{" -> "("];
myTMP = StringReplace[myTMP, "}" -> ")"];
WriteString[file, "\\item " <> myTMP <> "\n"],
{n, 1, Length@lis}
];
WriteString[file, "\\end{enumerate}\n\\end{document}\n"];
Close[file]


Which generates this latex file

\documentclass[12pt,a4paper]{article}
\usepackage[letterpaper,margin=1.2in]{geometry}
\usepackage{enumitem}
$$\begin{document} \begin{enumerate}[label=\arabic*)] \item A(-12, 2, -1),\quad B(-11, 1, -5),\quad C(-10, -2, 3),\quad (P) : 10 x+6 y+z+109=0 \item A(-12, 2, -1),\quad B(-11, 1, -5),\quad C(-10, 6, 3),\quad (P) : 2 x-2 y+z+29=0 \item A(-12, 2, -1),\quad B(-11, 1, -5),\quad C(-9, 5, -7),\quad (P) : 3 x-y+z+39=0 \end{enumerate} \end{document}$$

• Can I use mathmode instead TeXForm? Jan 28 at 3:43
• @JohnPaulPeter what is mathmode ? I never seen this function in Mathematica. TeXForm is used to convert mathematica math expressions to Latex in Mathematica. Since the 4th field in your list is an question, I used TeXForm on it. Jan 28 at 4:06
• Please see my text file. Jan 28 at 4:11
• @JohnPaulPeter fyi, updated. Hopefully this is what you meant. Jan 28 at 4:23
• Thank you very much. Jan 28 at 5:39