How to get correct scope of LaTeX tags in Tagbar


Tagbar is a useful plugin for Vim that displays tags of a source file ordered by their scope in a split window. However, if you open a LaTeX file in Vim, the Tagbar shows its chapters, sections and paragraphs correctly but they are not ordered by scope. Instead, all the chapters appear together, all the sections together and so on.


This is not a problem with Tagbar, but with the ctags program which is used by Tagbar to generate the tags. As of this writing, the ctags that ships with Ubuntu 12.04 LTS is a really old version that does not generate scope information for the tags of a LaTeX file. Thankfully, the tag scope feature for LaTeX files has been added to the main branch of ctags in 2012. Getting Tagbar to use the new version of ctags is easy:

  1. Uninstall the exuberant-ctags package from your Ubuntu system.

  2. Get the latest source code of ctags from either their SVN repository or this Github mirror. (The other Github clones of ctags source code do not seem to have this LaTeX fix.)

  3. Compile ctags by using these commands:

$ autoheader
$ autoconf
$ ./configure
$ make
$ sudo make install

Now open the LaTeX file in Ubuntu and its tags should be displayed with correct scoping in Tagbar.

Tried with: Ubuntu 12.04 LTS

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.