Thanks Albert,
I changed it as you've indicated:
function Span(el)
if FORMAT == "latex" and el.attributes.color then
return { pandoc.RawInline("latex", "\\textcolor{" ..
el.attributes.color .. "}"), el }
elseif FORMAT == "latex" and el.attributes.['text-decoration'] then
return { pandoc.RawInline("latex", "\\underline{" ..
el.attributes.['text-decoration'] .. "}"), el }
end
end
That gave another error:
my_luafilter.lua:5: <name> expected near '['
On Wednesday, May 6, 2020 at 11:48:41 AM UTC+2, Albert Krewinkel wrote:
R. Wils writes:
> I tried to add text underline to the same lua function;
>
> function Span(el)
> if FORMAT == "latex" and el.attributes.color then
> return { pandoc.RawInline("latex", "\\textcolor{" ..
> el.attributes.color .. "}"), el }
> elseif FORMAT == "latex" and el.attributes.text-decoration then
> return { pandoc.RawInline("latex", "\\underline{" ..
> el.attributes.text-decoration .. "}"), el }
> end
> end
>
> with input
> [this is my text]{text-decoration=underline}
>
> This gives an error `my_luafilter.lua:5: attempt to perform arithmetic on a
> nil value (field 'text')`
> What did I wrong?
The issue is with `el.attributes.text-decoration`. Minus/hyphens are
special in Lua, so Lua treats this as "substract `decoration` from
`el.attributes.text`. The solution is to use more explicit table-access
syntax: `el.attributes['text-decoration']`.
--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124