## WeBWorK Main Forum

### Inline Lua: proof of concept

by Andrew Dabrowski -
Number of replies: 2
Here's a working example of using Inline::Lua to define webwork problems. The Lua files are based on code I wrote for use with lualatex in a Finite Math class with a module on voting. (My complete lualatex repository is here.) After two weeks of work and much help from the kind people of this forum I have got three problems working.

(0 pts) Problems/Voting/v01.pg
Three candidates, Abner, Barbara, and Chris, are running for mayor, and the voters have the following profile.
Determine the social choice ordering under the Plurality system.
Three candidates, Althea, Barney, and Caspar, are running for D.A., and the voters have the following profile. Determine the social choice ordering under the Agenda system, with the specific agenda given below.
Three candidates , , and are running for office, and there is one block of voters, the Werdna block, who all favor the ranking . If the election were held today under the Iksworbad Voting System the result would be the social ranking . Now suppose that some of the Werdna block of voters are thinking about changing their preferred ranking to .
If the vote were held under the Iksworbad system with only those changes in the voters' profile, then the resulting social ranking would be . Based on only these two examples, does the Iksworbad system necessarily violate Monotonicity, Independence of Irrelevant Alternatives, both, or neither? Give your answer as “Mono”, “IIA”, “Both”, or “Neither”.
The attached tgz file has all the necessary files (I think).

Part of the Lua code is structured something like MathObjects but less extensive and sophisticated: matrix, vector, and fraction objects are defined in the Lua folder in pg/lib. The file voting.lua contains the problem definitions and associated auxiliary functions. Note that the first argument is a template of the text, and the second argument is a function that generates replacement values and the correct answer. The file PGMLproblem.lua does the interpretation of voting.lua to produce problem generating objects.

1. Lua is at version 5.3, lualatex requires 5.2, and Inline::Lua requires 5.1. This necessitated some rewriting and means the goal of "write once (Lua), run twice (webwork and lualatex)" (w1r2) is not yet quite attainable.

2. Another problem with Inline::Lua is that is does not now and may never support metatables, so I had to remove the nice overloading of arithmetic operators that metatables allow.

3. Another obstacle to w1r2 is that I couldn't find a good way to run latex text mode code inside PGML: [ ] calls math mode, so I save that for things like tabular that require the latex interpreter. The result is that I have to modify the problem definition functions in order to produce PGML. Maybe I could just put all my latex code inside an \mbox?

### Re: Inline Lua: proof of concept

by Andrew Dabrowski -
Two things I forgot to mention: