How can I find characters that are not curly braces? If I use this pattern "[^}]"
in string.gsub
I get an error.
EDIT: This is the part of the code that doesn't work:
\usepackage{luacode}
\begin{luacode}
function colorize ( s )
s = string.gsub ( s , "K_%w" , "\\textcolor[HTML]{00804d}{%0}" )
s = string.gsub ( s , "(A)([^}])" , "\\textcolor[HTML]{005ce6}{%1}%2"))
return s
end
\end{luacode}
\newcommand{\colorizeOn}{\directlua{luatexbase.add_to_callback("process_input_buffer", colorize , "colorize" )}}
\newcommand{\colorizeOff}{\directlua{luatexbase.remove_from_callback("process_input_buffer", "colorize" )}}
The first part of the script is ok (it substitutes all "K_" followed by an alphanumeric characters with the same thing but with a color code) while adding the second part (that should replace all "A" that are not followed by a "}" with "A" with its color code) it returns this errors:
Argument of \luacode@grab@lines has an extra }. s = string.gsub ( s , "(A)([^}
Paragraph ended before \luacode@grab@lines was complete. s = string.gsub ( s , "(A)([^}
Extra }, or forgotten \endgroup. s = string.gsub ( s , "(A)([^}
Missing \begin{document}. s = string.gsub ( s , "(A)([^}]
Missing \begin{document}. s = string.gsub ( s , "(A)([^}])" , "\\t
The main problem is the hat character in fact if I use this pattern "[}]"
I get similar errors (the compiler expects to find a corresponding "{" before) and in my case I can easily fix that using this pattern instead "[{}]"
. The problem is that I want the negation of this pattern that should be written as "[^{}]"
that doesn't work.
EDIT 2: this is what I expect.
\textcolor[HTML]{005ce6}{A}BA}
(from the external file you provided a link to) features an unbalanced curly brace and thus cannot be handled properly by LaTeX. – Mico Jul 14 '19 at 16:15