TransWikia.com

How to prevent texttt from making the text bold

TeX - LaTeX Asked on May 29, 2021

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}

Thank you in advance.

One Answer

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}

New Computer Modern sample

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.

Answered by Davislor on May 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP