Here is what I'm trying to achieve:

To this purpose I've written the following commands:
\documentclass[11pt]{article}
\usepackage[utf8]{luainputenc}
\setdefaultlanguage[variant=us]{english}
\setmainfont{CMU Concrete}
\setsansfont{CMU Sans Serif}
\setmonofont{CMU Typewriter Text}
\usepackage{xspace}
\usepackage{xparse}
\usepackage[dvipsnames]{xcolor}
\definecolor{keywdcolor}{HTML}{bf616a}
\DeclareDocumentCommand{\keywd}{m}{
\ttfamily\bfseries
\textcolor{keywdcolor}{#1}
}
\DeclareDocumentCommand{\apicmd}{m}{
\keywd{\textbackslash#1\xspace}
}
\DeclareDocumentCommand{\apienv}{m}{
\keywd{{#1}\xspace}
}
\definecolor{argscolor}{HTML}{a3be8c}
\DeclareDocumentCommand{\argcontent}{m}{
\ttfamily\bfseries
\textcolor{argscolor}{\xspace\ensuremath{\langle}\textit{#1}\ensuremath{\rangle}\xspace}
}
but when I try to implement it like this:
\begin{document}
\apicmd{path}\apiopt{shape}
\end{document}
this is the result:
Any idea why this happens and how I could correct it?
%) at the end of lines? (Why is my macro creating extra space?) Also\xspacedoes nothing at all in those cases. – egreg Jan 24 '21 at 15:27luainputenc(it has its uses but it is a tricky thing and disables most of luatex font support) – David Carlisle Jan 24 '21 at 15:42