올리고 나서 공유할 만한 정도의 것은 아니라 생각해서 삭제했는데, 죄송합니다. 강조할 단어가 동시에 매크로 이름으로 사용되는 문제에 대해서는---그런 매크로를 만들지 않는 것이 가장 편하고 실행 가능한 방법이라 생각합니다만--- 백슬래시로 시작하는 단어는 배제해야 하니, 정규식에 ([^\\])를 추가했습니다.
\begin{luacode*}
function highword(dict)
local dict = dict
return function (line)
for _, w in ipairs(dict) do
line = string.gsub(line, "([^\\])(%f[%a]"..w.."%f[%A])", "%1\\texthi{%2}")
end
return line
end
end
function enableHighword()
local dict = {"freedom", "justice", "dream"}
luatexbase.add_to_callback("process_input_buffer", highword(dict), "highword")
end
function disableHighword()
luatexbase.remove_from_callback("process_input_buffer", "highword")
end
\end{luacode*}
올리고 나서 공유할 만한 정도의 것은 아니라 생각해서 삭제했는데, 죄송합니다. 강조할 단어가 동시에 매크로 이름으로 사용되는 문제에 대해서는---그런 매크로를 만들지 않는 것이 가장 편하고 실행 가능한 방법이라 생각합니다만--- 백슬래시로 시작하는 단어는 배제해야 하니, 정규식에 ([^\\])를 추가했습니다.
\NewDocumentCommand{\dream}{m}{\textcolor{green}{#1}}
\NewDocumentCommand{\texthi}{m}{\textcolor{blue}{\itshape #1}}
\begin{luacode*}
function highword(dict)
local dict = dict
return function (line)
for _, w in ipairs(dict) do
line = string.gsub(line, "([^\\])(%f[%a]"..w.."%f[%A])", "%1\\texthi{%2}")
end
return line
end
end
function enableHighword()
local dict = {"freedom", "justice", "dream"}
luatexbase.add_to_callback("process_input_buffer", highword(dict), "highword")
end
function disableHighword()
luatexbase.remove_from_callback("process_input_buffer", "highword")
end
\end{luacode*}