add tag
निरंजन
With the help of [this](https://tex.stackexchange.com/a/563447/174620) amazing answer I have formed the following code. What I am trying to achieve here is to pass the argument of `\textbf` command to `\textit` command before processing the document. It seems that it works for single characters (like in `\textbf{a}`), but not for LaTeX control sequences (like in `\textbf{\oe}`). What shall I do to pass the entire argument of a command to another one in this setup?

PS - If anybody knows a way in l3programming to achieve what I am trying to get, I would love to hear about it. I don't have any preference for Lua per se, it's just that I found a solution for my purpose and hence I am using it.

```
\documentclass{article}
\usepackage{luacode}
\begin{luacode}
  function testlua ( s )
  s = unicode.utf8.gsub
  (s,'\\textbf{(%a)}','\\textit{%1}')
  return s
  end
\end{luacode}
\directlua{%
  luatexbase.add_to_callback("process_input_buffer",
  testlua, "testlua")
}%

\begin{document}
\textbf{a}

\textbf{\oe}
\end{document}
```
Top Answer
samcarter
I'm by no means a pattern matching expert, so please correct me if this is wrong, but I think there are two problems:

- with `%a` you only catch normal letters and not special characters like `\`. Try with `.` for all characters instead 

- to capture a multi-character string, add a `*`

(I found https://www.lua.org/manual/5.3/manual.html#6.4.1 useful to look up character classes)

```
% !TeX TS-program = lualatex

\documentclass{article}
\usepackage{luacode}
\begin{luacode}
  function testlua ( s )
  s = unicode.utf8.gsub
  (s,'\\textbf{(.*)}','\\textit{%1}')
  return s
  end
\end{luacode}
\directlua{%
  luatexbase.add_to_callback("process_input_buffer",
  testlua, "testlua")
}%


\begin{document}
\Huge

\textbf{a}

\textbf{\oe}

\textbf{abc}
\end{document}
```

![Screen Shot 2021-03-26 at 21.57.12.png](/image?hash=692a88fbb2bd804f7926152fb90e1e088a9b09e93ffc804af974cbbb0c4c0eeb)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.