[Dev-luatex] A few idle questions...
Jonathan Sauer
Jonathan.Sauer at silverstroke.com
Wed May 7 14:18:16 CEST 2008
Hello,
> Are there any practical experiences with Coco in LuaTeX already?
Even though I would not call them "practical":
I once used coroutines in the file reading callback to convert a
text file to TeX using coroutine.yield to return each converted
line of text as well as a short preamble and a postamble. I posted
the example to the LuaTeX wiki:
<http://luatex.bluwiki.com/go/Typeset_non-TeX_files_by_converting_them_u
sing_Lua_code>
It works like a charm (even though the example is not very useful).
I was also thinking of implementing a LaTeX environment using a
coroutine, so that there is only a single function that yields after
\begin and is resumed by \end. That way, the \end code can access
local variables of \begin.
Example:
\directlua0{
function env()
% \begin:
local answer = 42
tex.sprint("Beginning the environment")
coroutine.yield()
% \end:
tex.sprint("Ending the environment with ", tostring(answer))
end
}
\def\env{%
\directlua0{currEnv = env()}%
}
\def\endenv{%
\directlua0{coroutine.resume(currEnv) currEnv = nil}%
}
\begin{env}
...
\end{env}
This results in (or at least should result in):
Beginning the environment ... Ending the environment with 42
> All the best,
> David
Jonathan
More information about the dev-luatex
mailing list