\documentclass[a4paper]{article}

\title{Lua\LaTeX\ as a macro processor}
\author{Richard}

\usepackage{luacode}
\parskip4pt
\parindent0pt

% it's convenient to have the call-lua comand as a separate command.
\newcommand\lua[1]{\luaexec{#1}}

\begin{document}

\begin{luacode}
dofile("myluamacros.lua")
\end{luacode}

\maketitle

This shows how Lua can be used as an alternative and rather
sophisticated mechanism that is a possible alternative to \LaTeX\ macros.

Suppose you want a macro that repeats a piece of \LaTeX\ a particular
number of times.  Then just write,
\begin{luacode}
repeattext(7,"my text, ")
\end{luacode}
and you will get whatever you want that number of times.  For another example
\begin{luacode}
repeattext(11,"one two three\\ldots\\ ")
\end{luacode}

Suppose you want a macro that evaluates a numerical answer where
possible but leaves the expression in algebraic form otherwise, then
try this: The logarithm of $x^y$ is $\lua{mylog("x^y")}$, of $\sin x$
is $\lua{mylog("\\sin x")}$, and the logarithm of $1.0001$ is
$\lua{mylog(1.0001)}$ and the logarithm of $2.71828$ is
$\lua{mylog("2.71828")}$ (quotes are optional for numbers).

Try to modify this as you desire.  I am sure you can think of other
things you might like to have.

(Note: I am aware that having to double the backslash for various of these
things is not ideal\ldots)

\end{document}
