Does a LaTeX3 version of the following code could be simpler? I understand the logic, but I dislike the code...
\documentclass[12pt]{article}
\usepackage{color}
% Source: https://tex.stackexchange.com/a/33478/6880
\def\test{%
\begingroup
\catcode`_=12\relax
\ttest}
\def\ttest#1{%
\color{red}\fbox{#1}%
\endgroup}
\begin{document}
The smallest \test{txt_example} in the world.
\end{document}
Another question. Is there a way to see an underscore because I have the following output?



_is taken by the dot accent (unless you use\ttfamily). – egreg Dec 03 '22 at 23:23\ttfamily. – projetmbc Dec 03 '22 at 23:26