# Wrong index order when using \lstinline in \index

A stub of my document:

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\usepackage{makeidx}
\makeindex

\begin{document}

\chapter{MyChapter}
This is a\index{A} test\index{\lstinline{TEST}}.

\printindex

\end{document}


I am compiling with pdflatex and makeindex.

I would like to use \lstinline{} for formatting some keywords at the index. My problem is that there is a wrong order at the index. TEST is ordered before A.

Is there a way to achieve that TEST would be ordered the right way?

That's the wrong way to apply special formatting to an index. You need to use the key@visual syntax:

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\usepackage{imakeidx,listings}
\lstset{basicstyle=\ttfamily}
\makeindex

\begin{document}

\chapter{MyChapter}
This is a\index{A} test\index{TEST@\lstinline{TEST}}.

\printindex

\end{document}