Syntax highlighting and diagrams-latex

Skip to first unread message

Sam Tay

Feb 9, 2020, 4:08:58 PM2/9/20
to diagrams-discuss

Just wanted to stick this out into the ether to save time for those in the future. If you use vim / nvim and love writing diagrams code within latex but hate the screwed up syntax highlighting that results, here is a fix for you!

You can probably see the solution by just looking at this small commit:

Github user @inkarkat has a plugin for specifying different filetype syntax highlighting within regions of other filetypes. Once you install his plugin(s), you can create the after/tex/syntaxfile.vim as seen in the commit above to automatically have latex files highlight "\begin{diagram} .. \end{diagram}" code blocks as Haskell code.


Brent Yorgey

Feb 10, 2020, 5:31:53 PM2/10/20
to Sam Tay, diagrams-discuss
Thanks so much for posting this!  You inspired me to figure out how to do the same thing with emacs.  The below elisp code defines a mode for Haskell chunks embedded in LaTeX files, delimited by \begin{code} ... \end{code} or \begin{diagram} ... \end{diagram}.

(require 'polymode)   % install from MELPA

(define-innermode poly-haskell-latex-innermode
  :mode 'haskell-mode
  :head-matcher "\\\\begin{\\(diagram\\|code\\)}"
  :tail-matcher "\\\\end{\\(diagram\\|code\\)}"
  :head-mode 'host
  :tail-mode 'host)

(define-polymode poly-latex-haskell-mode
  :hostmode 'pm-host/latex
  :innermodes '(poly-haskell-latex-innermode))

(add-to-list 'auto-mode-alist '("\\.tex\\'" . poly-latex-haskell-mode))

You received this message because you are subscribed to the Google Groups "diagrams-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages