I have created a custom fancyvrb command via \CustomVerbatimCommand{\afun}{Verb}{} to use for writing programming language functions, say \afun|object.method.blah|, etc.

I would like to automatically build an index of all mentions of function names.

I know I could try to do that with ordinary LaTeX commands, e.g. with something like:


That will create an index entry with a function name.

Is there any way to achieve that, but with custom verbatim commands of fancyvrb?

  • Could you please be more specific with some typical examples? Do you really need verbatim mode?
    – egreg
    Apr 11, 2014 at 16:37
  • @egreg, I'll put an example shortly. I think I need verbatim because of underscores in function names.
    – Michał
    Apr 11, 2014 at 16:47

1 Answer 1


I'd suggest using xparse:









If you only need the underscore, among the special characters, this seems the cleanest approach.

enter image description here

  • Looks good. I guess you meant package makeidx. However, when I tried to compile your example, I'm getting (xparse) Unknown argument type 'v' replaced by 'm'. Fingers crossed ... Any clues?
    – Michał
    Apr 11, 2014 at 17:10
  • @Michal You have an outdated distribution. Upgrade it. For imakeidx I suggest you to look at its documentation. ;-)
    – egreg
    Apr 11, 2014 at 17:15
  • indeed... even though it is texlive up to date with Ubuntu repositories. I will get back here as soon as I update. Thanks so far anyway! Your solution looks very promising.
    – Michał
    Apr 11, 2014 at 17:19
  • I finally was able to update my texlive. Your solution works perfectly so far. Thanks!
    – Michał
    Apr 22, 2014 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.