Based on this answer, I tried this code
Clear["Global`*"]
list = {{a, b}, {c, d}, {m, n}} /.
Solve[{(a + c)/2 == m, (b + d)/2 == n, -5 <= a <= 5, -5 <= b <=
5, -5 <= c <= 5, -5 <= d <= 5, a > c, a b c d m n != 0,
a != b != c != d, a ∈ Integers, b ∈ Integers,
c ∈ Integers, d ∈ Integers,
m ∈ Rationals, n ∈ Rationals,
m ∉ Integers && n ∉ Integers }, {a, b,
c, d, m, n}];
pM = {x, y};
lis = list[[1 ;; 5]]
When I tried,
SetDirectory[NotebookDirectory[]]
fileName = FileNameJoin[{Directory[], "test.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 $M" <> ToString[e[[3]]] <> "$");
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]
I got the text file,
\documentclass[12pt,a4paper]{article}
\usepackage[letterpaper,margin=1.2in]{geometry}
\usepackage{enumitem}
\begin{document}
\begin{enumerate}[label=\arabic*)]
\item $A(-4, -3)$,\quad $B(-5, -2)$,\quad $M 9 5
(-(-), -(-))
2 2$
\item $A(-4, -3)$,\quad $B(-5, 2)$,\quad $M 9 1
(-(-), -(-))
2 2$
\item $A(-4, -3)$,\quad $B(-5, 4)$,\quad $M 9 1
(-(-), -)
2 2$
\item $A(-4, -2)$,\quad $B(-5, -3)$,\quad $M 9 5
(-(-), -(-))
2 2$
\item $A(-4, -2)$,\quad $B(-5, -1)$,\quad $M 9 3
(-(-), -(-))
2 2$
\end{enumerate}
\end{document}
How can I get the correct result?
ToString[e[[2]]]
toToString[InputForm@e[[2]]]
and same for the other onee[[3]]
if you do not useinputForm
you can get 2D strings which messes up things. $\endgroup$$M(-9/2, -5/2)$
has the form$M(-\dfrac{9}{2},-\dfrac{5}{2})$
? $\endgroup$M(-9/2, -5/2)
in Mathematica? This is not valid expression in Mathematica. If you are trying to generate this in Latex you'd have to do it manually. Like thisToString@TeXForm[M] <> "\\left(" <> ToString@TeXForm[-9/2] <> "," <> ToString@TeXForm[-5/2] <> "\\right)"
!Mathematica graphics since you can't useTeXForm
on the whole thing, You can only useTeXForm
on valid Mathematica expressions. $\endgroup$