lualatex-tools / luaformatters

Creating macros for LuaLaTeX packages
GNU General Public License v3.0
0 stars 0 forks source link

One-template-one-function pattern #33

Open uliska opened 5 years ago

uliska commented 5 years ago

I realized that in my thesis templates file (now also in the manual's examples) I have a really recurring pattern: macros with one argument that involve one template and one function. In essence these are templates with one field and a function that prepares the data for that replacement field. For example:

\opus has a template (e.g. op.\,<<<number>>>) and a function that replaces that field with the result of a preprocessor function (in this case ensuring consistency in the formatting of the number):

function SCHUBERT.formatters.musik:opus(text)
    return self:_format('opus', self:_format('musik.werknummer', text))
end

In the function _format is first called to format opus (the template), and then it is called again on musik.werknummer to preprocess the input argument before using it in the template replacement.

In this situation: template with one field, function with one argument, it would be possible to integrate this into one formatter instead of requiring to declare two, one public and one local. Maybe on the declaration side it would be enough to provide a Formatter Entry Table with instead of a f field both a template and a formatter field. In that case a generic function could then be called in Formatter:apply that makes use of the two fields.

However, it should be thought through if that can be made work in a more generic way, to cover more than this specific one-one situation