How can I use bold text inside a code listing? I wanted to make some parts of the code bold.
|
As per Mico's answer, there is no boldfaced monospaced font in the Computer Modern font family, so you need to use a font that has bold monospaced font. Below is an example using
Alternate Solution:You could also use the the courier font form ttfamily with bfseries or how to enable bold in fixed width font:
|
|||
|
|
|
you need a typewriter font which supports bold characters, eg:
and inside the listing you can use the escape character. You'l lfind some examples in the documentation, run |
|||
|
As you must have already discovered, there is no boldfaced monospaced font in the Computer Modern font family. (Computer Modern is what's loaded by default.) To get the option of highlighting part of your code in a boldfaced font, you must switch to a different font family.
The following MWE serves to illustrate the effects of choosing among these options:
Courier mono generates this text:
Latin Modern mono looks like this (note the rather minor difference between non-bold and bold):
Both the
|
||||
|
|
|
The listings package might suffice. Start with:
The package allows you to define your own language definition ( |
|||||||||
|
|
I can't remember where I came across the following definition to use a boldface typewriter font with Computer Modern:
Then:
Result:
I'm not an expert in fonts in LaTeX so I'm not entirely sure what the |
|||
|
|





