Can I use an easy programming language with XeTeX?
My PythonTeX package is another Python-based option. PythonTeX was primarily developed for mathematical and scientific applications, but it's also suitable for much general-purpose work. I've included a few basic examples of creating macros with PythonTeX below. You do have to be careful about catcodes if you are working with special characters.
\documentclass{article}
\usepackage{pythontex}
\begin{document}
Basic math: \py{5324/251}
Macros that more closely interact with TeX:
\newcommand{\reverse}[1]{\py{"#1"[::-1]}}
\reverse{A sentence!}
\newcommand{\listtotabular}[1]{
\begin{tabular}{|c|c|c|c|}
\hline
\py{'&'.join("#1".split(','))} \\
\hline
\end{tabular}
}
\listtotabular{First, Second, Third, Fourth}
\end{document}
In addition to the examples above, and the examples included with the documentation, you might also look at the following examples.
- Plotting the derivative of a function
- Using Python to create tikz
- Solving an equation
- Python: package python, example
- Perl: PerlTeX, documentation
- (LuaTeX: reference, documentation for LuaLaTeX) (not for XeTeX)
While I haven't tried, you might be able to use bashful
to interact with programs written in other languages via stdin and stdout.
I had no problems with a simple example as long as I compiled with -shell-escape
:
\documentclass{article}
\usepackage{bashful}
\def\fortune{\splice{fortune}}
\begin{document}
\fortune
\fortune
\end{document}
I am not sure about the polyglossia
issue that is mentioned in the documentation.