Create tags file for latex for labels and bib items
Asked Answered
R

1

14

I'm using ctags to create a tags file for use in Vim, so that I can jump to definitions of labels and citations. However, I have two problems:

  1. ctags includes \ref in the tags file, so when I hit jump on a \ref label, I don't necessarily jump to the definition of the label, but might end up on another reference to that label.
  2. I'd like to be able to jump to the corresponding entry in a .bib file from a \cite command, but ctags doesn't generate entries for that (I'm using ctags *.tex *.bib).

I wanted to redefine ctags's definition for tex files, so that I could remove \ref entries, but that didn't work.

My ~/.ctags file:

--langdef=tex2
--langmap=tex2:.tex
--regex-tex2=/\\label[ \t]*\*?\{[ \t]*([^}]*)\}/\1/l,label/
Rois answered 14/11, 2011 at 9:18 Comment(0)
R
16

I realized that I didn't use exuberant ctags, but another ctags program, so the content in ~/.ctags was never used.

I also managed to add another entry in ~/.ctags for bib entries:

--langdef=tex2
--langmap=tex2:.tex
--regex-tex2=/\\label[ \t]*\*?\{[ \t]*([^}]*)\}/\1/l,label/

--langdef=bib
--langmap=bib:.bib
--regex-bib=/^@[A-Za-z]+\{([^,]*)/\1/b,bib/

ctags *.tex *.bib works now as I want it.

You can put a regex into an online regex explainer to understand what it is doing, like https://regexr.com/.

Rois answered 14/11, 2011 at 9:39 Comment(6)
I know this is an answer from a long time ago, but could you please explain how the regex works? I am unable to have the above correctly pick some citations that have a bibkey with an & in it.Uppercase
@Uppercase I have added an explanation.Rois
@Uppercase Which regex do you need an explanation for? The regexes should accept anything but comma and closing brace "}" in the name.Rois
Yes thanks. I think I have been able to figure it out.Uppercase
Could you clarify the /\1/b,bib/ part? I am aware that b,bib are ctags labels. What is the role played by /\1/ ?Uppercase
\1 is replaced by the content of the first capture group in the regex, which are the parts of the regex surrounded by parentheses (). So the regex is ^@[A-Za-z]+\{([^,]*), which means you have an @ then some name using a-z, then an opening brace {, and then everything up to the next comma is captured. So for @BibEntry{nameoftheentry,, the \1 would be nameoftheentry.Rois

© 2022 - 2024 — McMap. All rights reserved.