Syntax highlighting and diagrams-latex

26 views
Skip to first unread message

Sam Tay

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

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: https://github.com/samtay/dotfiles/commit/5c0fe2899c46a04056eba0bb0d99aa9221427614

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.

Cheers,
Sam

Brent Yorgey

unread,
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 diagrams-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/diagrams-discuss/CAJtde5MZKfAh0eXvSobxHUo2XY_WkCn2KAFXKb6zkBtGup%3D0Lg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages