I have lots of C++ code snippets in my article. Just see the following tex content and you'll get what I mean.
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{xspace}
\NewDocumentCommand{\code}{m}{\texttt{{#1}}}
\begin{document}
My code is \code{cout << hello << world;}\
But I wish it looks like \verb|cout << hello << world;|
\end{document}
The different is « and <<.
How can I avoid ligatures in my \code macro.


fontenc, but\usepackage{fontspec}and you'll see that there are no ligatures by default. – egreg Nov 23 '20 at 11:18\verbor\lstinlineand adjust the style (font, color, etc.) instead of implementing the commands yourself – DG' Nov 23 '20 at 11:40\code.\verbgives me no control. – Qiang Nov 23 '20 at 11:50{\lstinline[language=,basicstyle=balabala]{#1}}.lstsetis used for other big code blocks instead of inline ones. – Qiang Nov 23 '20 at 12:09\lstinline, I underestimated the power of lstlisting. In fact, I tried it, but used it in a wrong way – Qiang Nov 24 '20 at 03:25