Skip to content

Instantly share code, notes, and snippets.

@yt-siden
Last active November 9, 2018 12:29
Show Gist options
  • Save yt-siden/af97314afe9b400e4b03dabbfd3e146c to your computer and use it in GitHub Desktop.
Save yt-siden/af97314afe9b400e4b03dabbfd3e146c to your computer and use it in GitHub Desktop.

概要

  • Universal Ctagsを導入して(La)TeX文書で:Denite outlineを使いたい
  • 候補は表示されるが,ジャンプが働かない
  • Universal Ctagsの出力する正規表現に問題があるっぽい?
  • --excmd=number で行番号の出力にすればOK

調査

以下のような(よくある)TeX文書を用意する.

\documentclass{article}

\begin{document}

\section{Introduction}

\section{Related works}

\section{Proposed method}

\section{Numerical experiments}

\section{Conclusion}

\end{document}

Universal Ctagsを導入した上で, NeoVIM上で :Denite outlineして,適当にsectionを選択してreturnするが該当箇所にジャンプしない.

Universal Ctagsの出力するtagsを見てみる

上記のTeXソースに対してctags hoge.texした結果が以下である.

!_TAG_FILE_FORMAT       2       /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED       1       /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_OUTPUT_MODE       u-ctags /u-ctags or e-ctags/
!_TAG_PROGRAM_AUTHOR    Universal Ctags Team    //
!_TAG_PROGRAM_NAME      Universal Ctags /Derived from Exuberant Ctags/
!_TAG_PROGRAM_URL       https://ctags.io/       /official site/
!_TAG_PROGRAM_VERSION   0.0.0   /3480c6d/
Conclusion      test.tex        /^\\section{Conclusion}$/;"     s
Introduction    test.tex        /^\\section{Introduction}$/;"   s
Numerical experiments   test.tex        /^\\section{Numerical experiments}$/;"  s
Proposed method test.tex        /^\\section{Proposed method}$/;"        s
Related works   test.tex        /^\\section{Related works}$/;"  s

\section{****}\がエスケープされて\\section{****}になっている.

エスケープ消してみる

tagsを手動で編集し,\\\にしてみる. すると, :Denite tagでは該当箇所にジャンプするようになった.

Universal Ctagsがtagsに出力する正規表現をエスケープしないようにできれば一番手っ取り早くこの問題を解決できそうだが, Universal Ctagsにそのようなオプションはあるのだろうか.

2018-11-09 追記

Universal-ctagsのIssueに以下のようなものがあった.

tags-file generated by TeX parser uses patterns in EX command instead of line numbers · Issue #883 · universal-ctags/ctags

曰く, --excmd=number を使えばいいと思うよ,と.

% ctags --excmd=number foo.tex

% cat tags
!_TAG_FILE_FORMAT       2       /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED       1       /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_OUTPUT_MODE       u-ctags /u-ctags or e-ctags/
!_TAG_PROGRAM_AUTHOR    Universal Ctags Team    //
!_TAG_PROGRAM_NAME      Universal Ctags /Derived from Exuberant Ctags/
!_TAG_PROGRAM_URL       https://ctags.io/       /official site/
!_TAG_PROGRAM_VERSION   0.0.0   /befcb888/
Conclusion      foo.tex 13;"    s
Introduction    foo.tex 5;"     s
Numerical experiments   foo.tex 11;"    s
Proposed method foo.tex 9;"     s
Related works   foo.tex 7;"     s

Deniteのoutline sourceに突っ込んでみる. デフォルトではオプションは空になっているので,あらかじめ

call denite#custom#var('outline', 'options', ['--excmd=number'])

でオプションを登録しておく.

結果は省略するが,当初の目的を達成することができた.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment