2

I'm using vim and tagbar to write my latex files. In the latex source, the input for a graphic look like this:

\includegraphics[width=0.70\textwidth]{../../figures/mechanical_diffusion/plate_hole/plate_hole_fem_elas_cd_map}

I would like to get in tagbar only the filename, in this case, "plate_hole_fem_elas_cd_map". I created a .ctags in my home, which has the following line (modified from the original line found in tagbar documentation):

--regex-latex=/^[\t]*\\includegraphics[[:space:]]*(\[[^]]*\])?[[:space:]]*(\[[^]]*\])?[[:space:]]*\{[\.{2}\/]*[[a-zA-Z0-9_]+\/]*([^}]+)\}/\3/g,graphic+listing/

But I cannot get only the file name. I tried other things, but sometimes I only remove the "../", sometimes I get only "plate_hole".. What did I do wrong ?

Thanks

Napseis
  • 833
  • 2
  • 10
  • 24

1 Answers1

1

Your regular expression is incorrect, you can't use character classes like that. This one worked for me:

--regex-latex=/^[\t]*\\includegraphics[[:space:]]*(\[[^]]*\])?[[:space:]]*(\[[^]]*\])?[[:space:]]*\{([^}]+\/)?([^}\/]+)\}/\4/g,graphic+listing/
Jan Larres
  • 895
  • 8
  • 10
  • It works for me too, thanks.Could you explain this part please ? \{([^}]+\/)?([^}\/]+)\}/\4 – Napseis May 27 '13 at 13:26
  • The first group looks for for as many characters that are non-closing braces as possible and then a `/` at the end, and the second group looks for as many characters that are neither a closing brace nor a slash as possible. This way all slashes (i.e. directories) will end up in the first group, and since that group is optional it also works with files that are in the current directory. – Jan Larres May 28 '13 at 07:50