4.47 how to generate Latex from other programming languages?

This shows how to use other environments to generate Latex code. In Mathematica

s = ToString["\\documentclass[12pt,titlepage]{article} 
\\begin{document} 
It is known that $\\sin(0)=" <> ToString[Sin[0]] <> "$ 
\\end{document}"]; 
 
file = OpenWrite["C:\\tmp\\p.tex", PageWidth -> Infinity]; 
WriteString[file, s]; 
Close[file];
 

This generates the Latex file p.tex

\documentclass[12pt,titlepage]{article} 
\begin{document} 
It is known that $\sin(0)=0$ 
\end{document}
 

Using Python

import math 
s=r""" 
\documentclass[12pt,titlepage]{article} 
\begin{document} 
It is known that $\sin(0)="""+repr(math.sin(0))+r"""$ 
\end{document}""" 
 
text_file = open(r"C:\tmp\p.tex", "w") 
text_file.write(s) 
text_file.close()
 

The above generates the Latex file

\documentclass[12pt,titlepage]{article} 
\begin{document} 
It is known that $\sin(0)=0.0$ 
\end{document}
 

From C++ (needs C++11)

#include <iostream> 
#include <string> 
#include <math.h> 
using namespace std; 
 
 
int main() 
{ 
            //int r = 5; 
        string s =R"( 
 
\documentclass[12pt,titlepage]{article} 
\begin{document} 
 It is known that (a) $\sin(\pi)=)" + std::to_string(sin(M_PI)) + R"($ 
\end{document} 
 
)"; 
 
        cout << s << endl; 
        return 0; 
}
 

And now compile and run

>g++ -Wall -std=c++0x try_string_literal.cpp 
>./a.out 
 
 
\documentclass[12pt,titlepage]{article} 
\begin{document} 
 It is known that (a) $\sin(\pi)=0.000000$ 
\end{document}