4
$\begingroup$

Based on the answer in tried in Vietnamese

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[], "Vietnamese.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[utf8]{vietnam}\n" <> 
   "\\usepackage{amsthm}\n" <> "\\theoremstyle{definition}\n" <> 
   "\\newtheorem{ex}{Exercise}\n" <> "\\begin{document}\n"];
Do[WriteString[file, 
   "\\begin{ex}\n" <> "Phương trình mặt phẳng qua ba điểm $A" <> 
    toX[data[[n, 1]]] <> "$, $B" <> toX[data[[n, 2]]] <> "$, $C" <> 
    toX[data[[n, 3]]] <> "$$" <> toX[data[[n, 4]]] <> 
    "$\n\\end{ex}\n"], {n, 1, Length@data}];
WriteString[file, "\\end{document}\n"];
Close[file]

The LaTeX generated by Mathematica is

\documentclass[12pt,a4paper]{article}
\usepackage[left=2cm, right=2cm, top=2cm, bottom=2cm]{geometry}
\usepackage{amsmath}
\usepackage[utf8]{vietnam}
\usepackage{amsthm}
\theoremstyle{definition}
\newtheorem{ex}{Exercise}
\begin{document}
\begin{ex}
Ph\:01b0\:01a1ng tri`nh m\:1eb7t ph\:1eb3ng qua ba \:0111i\:1ec3m $A(6,8,5)$, $B(7,4,2)$, $C(9,3,1)$ la` $x-5 y+7 z-1=0$
\end{ex}
\begin{ex}
Ph\:01b0\:01a1ng tri`nh m\:1eb7t ph\:1eb3ng qua ba \:0111i\:1ec3m $A(6,8,5)$, $B(7,4,3)$, $C(9,1,2)$ la` $2 x+3 y-5 z-11=0$
\end{ex}
\begin{ex}
Ph\:01b0\:01a1ng tri`nh m\:1eb7t ph\:1eb3ng qua ba \:0111i\:1ec3m $A(6,8,5)$, $B(7,4,3)$, $C(9,2,1)$ la` $2 x-y+3 z-19=0$
\end{ex}
\begin{ex}
Ph\:01b0\:01a1ng tri`nh m\:1eb7t ph\:1eb3ng qua ba \:0111i\:1ec3m $A(6,9,1)$, $B(7,2,3)$, $C(8,4,5)$ la` $2 x-z-11=0$
\end{ex}
\begin{ex}
Ph\:01b0\:01a1ng tri`nh m\:1eb7t ph\:1eb3ng qua ba \:0111i\:1ec3m $A(6,9,1)$, $B(7,2,3)$, $C(8,5,4)$ la` $13 x-y-10 z-59=0$
\end{ex}
\begin{ex}
Ph\:01b0\:01a1ng tri`nh m\:1eb7t ph\:1eb3ng qua ba \:0111i\:1ec3m $A(6,9,1)$, $B(7,2,4)$, $C(8,3,5)$ la` $5 x-y-4 z-17=0$
\end{ex}
\end{document}

and PDF file. enter image description here

It means, the code does not support Vietnamese. How can I write the text in another language instead of English?

$\endgroup$
4
  • $\begingroup$ Isn’t the .tex file correct? What software is converting the .tex file to the incorrect.pdf file? Why do you think this is a Mathematica problem? $\endgroup$
    – Ghoster
    Commented May 20 at 4:39
  • $\begingroup$ And just remember to add \usepackage[vietnamese,english]{babel} to preamble also, else Latex will not compile it. $\endgroup$
    – Nasser
    Commented May 20 at 4:54
  • $\begingroup$ I do not think you need \usepackage[utf8]{vietnam} if you use \usepackage[vietnamese,english]{babel} but this is a Latex thing now and not Mathematica. For me it worked without using \usepackage[utf8]{vietnam}. Using lualatex compiler with TexLive 2023 on Linux. $\endgroup$
    – Nasser
    Commented May 20 at 5:00
  • $\begingroup$ @Nasser Only need \usepackage[utf8]{vietnam} $\endgroup$ Commented May 20 at 5:36

1 Answer 1

6
$\begingroup$

Specifying CharacterEncoding -> "UTF-8" in OpenWrite[] seems to produce the right output. (I don't know Vietnamese, so I'm not sure.)

file = OpenWrite[fileName, PageWidth -> Infinity, 
  CharacterEncoding -> "UTF-8"]
$\endgroup$
2
  • $\begingroup$ Yes, verified this made it work. V 14 $\endgroup$
    – Nasser
    Commented May 20 at 4:53
  • $\begingroup$ @Michael E2 It works fine. Thank you very much $\endgroup$ Commented May 20 at 5:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.