I am currently trying to make vim's tagbar plugin to work with latex files on Mac OS X.
This is my ~/.ctags file:
--langdef=latex
--langmap=latex:.tex
--regex-latex=/^\\tableofcontents/TABLE OF CONTENTS/s,toc/
--regex-latex=/^\\frontmatter/FRONTMATTER/s,frontmatter/
--regex-latex=/^\\mainmatter/MAINMATTER/s,mainmatter/
--regex-latex=/^\\backmatter/BACKMATTER/s,backmatter/
--regex-latex=/^\\bibliography\{/BIBLIOGRAPHY/s,bibliography/
--regex-latex=/^\\part[[:space:]]*(\[[^]]*\])?[[:space:]]*\{([^}]+)\}/PART \2/s,part/
--regex-latex=/^\\part[[:space:]]*\*[[:space:]]*\{([^}]+)\}/PART \1/s,part/
--regex-latex=/^\\chapter[[:space:]]*(\[[^]]*\])?[[:space:]]*\{([^}]+)\}/CHAP \2/s,chapter/
--regex-latex=/^\\chapter[[:space:]]*\*[[:space:]]*\{([^}]+)\}/CHAP \1/s,chapter/
--regex-latex=/^\\section[[:space:]]*(\[[^]]*\])?[[:space:]]*\{([^}]+)\}/\. \2/s,section/
--regex-latex=/^\\section[[:space:]]*\*[[:space:]]*\{([^}]+)\}/\. \1/s,section/
--regex-latex=/^\\subsection[[:space:]]*(\[[^]]*\])?[[:space:]]*\{([^}]+)\}/\.\. \2/s,subsection/
--regex-latex=/^\\subsection[[:space:]]*\*[[:space:]]*\{([^}]+)\}/\.\. \1/s,subsection/
--regex-latex=/^\\subsubsection[[:space:]]*(\[[^]]*\])?[[:space:]]*\{([^}]+)\}/\.\.\. \2/s,subsubsection/
--regex-latex=/^\\subsubsection[[:space:]]*\*[[:space:]]*\{([^}]+)\}/\.\.\. \1/s,subsubsection/
--regex-latex=/^\\includegraphics[[:space:]]*(\[[^]]*\])?[[:space:]]*(\[[^]]*\])?[[:space:]]*\{([^}]+)\}/\3/g,graphic+listing/
--regex-latex=/^\\lstinputlisting[[:space:]]*(\[[^]]*\])?[[:space:]]*(\[[^]]*\])?[[:space:]]*\{([^}]+)\}/\3/g,graphic+listing/
--regex-latex=/\\label[[:space:]]*\{([^}]+)\}/\1/l,label/
--regex-latex=/\\ref[[:space:]]*\{([^}]+)\}/\1/r,ref/
--regex-latex=/\\pageref[[:space:]]*\{([^}]+)\}/\1/p,pageref/
and this is the corresponding part in my ~/.vimrc:
let g:tagbar_type_tex = {
\ 'ctagstype' : 'latex',
\ 'kinds' : [
\ 's:sections',
\ 'g:graphics:0:0',
\ 'l:labels',
\ 'r:refs:1:0',
\ 'p:pagerefs:1:0'
\ ],
\ 'sort' : 0,
\ }
I basically got all this from this link: https://github.com/vim-scripts/Tagbar/blob/master/doc/tagbar.txt
Unfortunately, when I start the tagbar, nothing happens and when I execute :UpdateTags I get the following error:
easytags.vim 3.7: Exuberant Ctags doesn't support the 'plaintex' file type! (at function xolox#easytags#update..<SNR>20_check_cfile, line 22)
ctags --version results in:
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
Compiled: Oct 1 2014, 16:18:15
Addresses: <dhiebert@users.sourceforge.net>, http://ctags.sourceforge.net
Optional compiled features: +wildcards, +regex
and "which ctags" in:
/usr/local/bin/ctags
When I execute ctags --verbose abstract.tex it finds the ~/.ctags file and generates this tag file:
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
!_TAG_PROGRAM_NAME Exuberant Ctags //
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
!_TAG_PROGRAM_VERSION 5.8 //
. Abstract abstract.tex /^\\section*{Abstract}$/;" s
The file itself looks like this:
\section*{Abstract}
Let's see what we can do here...
What am I missing? :(
Kind regards and thanks for your help :)
EasyTags uses the filetype of the current buffer to determine what arguments it should pass to ctags
.
The filetype
of your file is set to plaintex
by Vim, the default for *.tex
files. So… you get that error because plaintex
is not recognized by ctags
.
As per the documentation, you are supposed to use the filetype
in your custom configuration:
g:tagbar_type_{vim filetype}
Since your *.tex
file is recognized as plaintex
, your g:tagbar_type_tex
will never be used.
Add these lines to your ~/.vimrc
to force Vim to recognize *.tex
files as latex
:
augroup latex
autocmd!
autocmd BufRead,BufNewFile *.tex set filetype=latex
augroup END
Change your custom Tagbar config from:
g:tagbar_type_tex
to:
g:tagbar_type_latex
This solution will work only if Vim is configured to work well with the latex
filetype (ftplugin, syntax, indent…), which is dubious at best.
Use plaintex
instead of latex
in your ~/.ctags
configuration:
--langdef=plaintex
--langmap=plaintex:.tex
--regex-plaintex=/^\\tableofcontents/TABLE OF CONTENTS/s,toc/
...
Change your custom Tagbar config from:
let g:tagbar_type_tex = {
\ 'ctagstype' : 'latex',
...
to:
let g:tagbar_type_plaintex = {
\ 'ctagstype' : 'plaintex',
...