I am using LyX to describe algorithms. A common scenario is that I have a snippet of pseudo code (in a float, for example) and a block of text which makes references to keywords in that pseudo code. The listings package can do this, I think, but I recall having trouble using math notation, like subscripts, with listings. On the other hand, I have not been able to find how to use the algorithms package inline.
Not really what you asked for, but did you try the
mathescape option in listings? (as in this StackOverflow answer)
It seems to do what you want for sub/superscripts (but a more precise example might lead to a different answer).