I am writing files with the extension ".tid" for a piece of software called TiddlyWiki whose syntax is pretty similar to that of markdown. In these files, I want to be able to write down latex and I used to use UltiSnips and vimtex for this; the problem is that I can't seem to get the traditional context "math()" to work.

I have read this page and while it gives some example code that supposedly worked, I have tried exactly that and it hasn't worked. I also read this page but I want to not have to declare the filetype as tex because I want to have separate snippets files for .tid and .tex files.

Here is a minimal working example:

I have a file called "tid.snippets" with the contents:

global !p
def math():
    return vim.eval('vimtex#syntax#in_mathzone()') == '1'

context "math()"
snippet vec "Vector" iA

snippet happy "Happy" iA
$1 is such a happy person!

In addition, I have added the following line to my .vimrc in order to make it recognise .tid files:

autocmd BufRead,BufNewFile *.tid setfiletype tid

When I create a new file example.tid, I type happy and it expands the snippet as expected. When I type $ $ and put my cursor inside the $s and type vec, nothing happens. If I change the filetype to tex by giving Vim the command :set filetype=tex then it all works...

Can someone help?

  • IIRC the math zone detection is based on the syntax. You would probably need to port the correct syntax definitions for tiddlywiki files
    – D. Ben Knoble
    Aug 13 at 17:05
  • @D.BenKnoble Could you elaborate at all? Why is it that people say it can "just work" using Markdown files but not in this case? They don't have similar syntax... How would I "port" the syntax definitions in the way you suggest? Aug 13 at 17:10
  • I dont know about all the markdown stuff. The thing is that typically that math context relies on detecting the presence of specific syntax groups which won’t exist without loading the tex syntax. If you could discover the relevant ones, you could add rules to ~/.vim/syntax/tid.vim to include tex syntax in the right places, and that might help… honestly, you’re better off asking the vimtex folks (the maintainer drops by here occasionally, perhaps they can help).
    – D. Ben Knoble
    Aug 13 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.