# How to prevent \texttt from making the text bold

I tried to escape the underscore character but the resultant "_" did not look perfect. Then I came across another answer suggesting to use \texttt. However, I see that \texttt is also boldening the text. Is there a way to circumvent this problem? Here is a minimal example to explain what I mean.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tcolorbox}
\begin{document}
\texttt{This\_is\_a\_}test
%There is a clear difference between the fonts of the contents inside \texttt and outside.
\end{document}


• You say the resultant "_" did not look perfect. What output are you trying to achieve? – campa Oct 13 at 10:38
• \texttt switches to a different (typewriter) font. – Ulrike Fischer Oct 13 at 10:46

That’s how the default serif and monospace fonts look. You can change either of them.

For example, New Computer Modern Roman comes in a slightly-heavier Book weight. This MWE pairs the Book weight of New Computer Modern Roman with the Regular weight of New Computer Modern Mono.

\documentclass{article}
\usepackage{fontspec}
\usepackage{amsmath}
\usepackage{tcolorbox}

\setmainfont{NewComputerModernBook}
\setmonofont{NewComputerModernMono}

\begin{document}
\texttt{This\_is\_a\_}test
%There is a clear difference between the fonts of the contents inside \texttt and outside.
\end{document}


Maybe those specific fonts are not enough of a correction for your liking, but many font families come in multiple weights that you could try.