1
local tex = '\\authors{\\author[]{{Surname} {FirstName}\\textsuperscript{\\hyperref[{article-id-affiliationnumber1}]}{{\\textsuperscript{,{\\textcolor{blue}{article-id-affiliationnumber2}}}}}{{\\textsuperscript{,\\hyperref[{cqgab7bbaaf3}]{\\textcolor{blue}{article-id-affiliationnumber3}}}}}{{\\textsuperscript{,\\hyperref[{cqgab7bbaem1}]{\\textcolor{blue}{}}}}}}}'

local function commafix (text)
    local pattern = '%$}{%$'
    local count = 0
    for _ in tex:gmatch (pattern) do
        count = count + 1
    end
    return tex:gsub (pattern, ',$}\n{$', count - 1):gsub (pattern, '$}\n and \n{$')
end
    io.write(commafix (tex))

I would like to replace every \hyperref after , before end of \authors?

My replacement is required as:

\\authors{\\author[]{{Surname} {FirstName}\\textsuperscript{\\hyperref[{article-id-affiliationnumber1}]}{{\\textsuperscript{,{\\textcolor{blue}{article-id-affiliationnumber2}}}}}{{\\textsuperscript{ and \\hyperref[{cqgab7bbaaf3}]{\\textcolor{blue}{article-id-affiliationnumber3}}}}}{{\\textsuperscript{,\\hyperref[{cqgab7bbaem1}]{\\textcolor{blue}{}}}}}}}
Henri Menke
  • 109,596
Balaji
  • 127
  • as far as I understand this is a pure Lua question so only vaguely on topic here, you have ,\\hyperref[{cqgab7bbaaf3}] in your input string and you want to replace it, but what do you want to replace it by? – David Carlisle Nov 23 '20 at 10:01
  • @DavidCarlisle: I have modified the question. My replacement is required for and before last affiliation (like 1,2 and 3) or (like 1,2,3 and 4) etc... – Balaji Nov 23 '20 at 10:06

0 Answers0