'Insert inline code block in Latex document [duplicate]

Hi I am trying to add an inline code block in a Latex document. I know how to add a separate code block using lstlisting but i want to instead add an inline code block. I am attaching the screenshot of output that i am expecting .

enter image description here

As you can see in the same line a code block is added which contains the expression print(g). I want something like that. So that it should be customizable, that is., the background color of the box, width and height of the box, border width etc .Also the text of the code inside that inline code block should be customizable as well .Is there a way to achieve this in Latex?



Solution 1:[1]

A very simple way may be:

\documentclass{article}

\begin{document}

The command \verb|print(g)| prints something.

\end{document}

And you can take some more sophisticated style from this TeX SE thread.

Do not forget that, as in the page linked above, listings package itself also allow to style inline code.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1