Code Yarns β€πŸ‘¨β€πŸ’»
Tech Blog ❖ Personal Blog

How to get correct scope of LaTeX tags in Tagbar

πŸ“… 2013-Mar-14 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ ctags, latex, tagbar, vim ⬩ πŸ“š Archive

Problem

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.

Solution

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


Β© 2022 Ashwin Nanjappa β€’ All writing under CC BY-SA license β€’ 🐘 @codeyarns@hachyderm.io β€’ πŸ“§