Syntax Highlighting for Maxima executable folds and plugin sessions

  1. Syntax highlighting in executable folds:
    Thanks to @jeroen great pigments-plugin we are finally able to properly highlight Maxima code blocks.

My questions relating to that plugin are

  • why is the colouring scheme displayed in TeXmacs so different from the one on the pygments home page? When I type in the following instruction

% maxima ; lovelace

I get code highlighted this way:

which looks different from the colours presented at

  • Is there a way to have brace/bracket matching implemented? Especially for (Lisp-(like (code))) with all its brackets that would be a nice feature to have.:wink:
  1. Syntax highlighting in a Maxima plugin session:
  • is possible to have that implemented?

  • is it possible to get brace/bracket matching in the Maxima plugin going? If so, how?

Any help/suggestions appreciated


I can answer this question only. There is a “program bracket matching” option in the Preferences, which I can find only when “Complex actions” is set to “Through popup windows”; then I find it in the “Other” tab. As far as I can see, it works for Scheme only; I tried it in the Executable folds for Lisp and Maxima and it does not work there, I can’t try it in sessions b/c in my TeXmacs under Ubuntu sessions do not work, perhaps I will try it under Windows later.

Hello. Sessions worked for me after I installed the generic binary, not the ubuntu specific one. Maybe this will help you too. @pireddag Here:

I needed to put the following in my-init-texmacs.scm to get it working in Julia. You can try adapting this.

;; Enable highlighting matching brackets in Julia
(tm-define (notify-cursor-moved status)
  (:require prog-highlight-brackets?)
  (:mode in-prog-julia?)
  (select-brackets-after-movement "([{" ")]}" "\\"))

The example on this page is for Python. If I copy the code in the lovelace example and render it in TeXmacs with % python ; lovelace, I get exactly the same highlighting as on the webpage.

Did you check what pygments gives you for the example code in the screenshot, so we can compare apples with apples?

I don’t see highlighting code for Maxima in the repository currently. A first step would be to look at examples of existing highlighting (in plugins/code/progs/, e.g. julia-lang.scm) and adapt it to maxima.

Replacing julia with maxima or Maxima and putting your code into my-init-texmacs.scm did not have any effect whatsoever.

I followed your suggestion and copied that into my-init-texmacs.scm:

(define (notify-maxima-syntax var val)
    (syntax-read-preferences "maxima")
    ("syntax:maxima:none" "red" notify-maxima-syntax)
    ("syntax:maxima:comment" "brown" notify-maxima-syntax)
    ("syntax:maxima:error" "dark red" notify-maxima-syntax)
    ("syntax:maxima:constant" "#4040c0" notify-maxima-syntax)
    ("syntax:maxima:constant_number" "#4040c0" notify-maxima-syntax)
    ("syntax:maxima:constant_string" "dark grey" notify-maxima-syntax)
    ("syntax:maxima:constant_char" "#333333" notify-maxima-syntax)
    ("syntax:maxima:declare_function" "#0000c0" notify-maxima-syntax)
    ("syntax:maxima:declare_module" "0000c0" notify-maxima-syntax)
    ("syntax:maxima:declare_type" "0000c0" notify-maxima-syntax)
    ("syntax:maxima:operator" "#8b008b" notify-maxima-syntax)
    ("syntax:maxima:operator_openclose" "#B02020" notify-maxima-syntax)
    ("syntax:maxima:operator_field" "#88888" notify-maxima-syntax)
    ("syntax:maxima:operator_special" "orange" notify-maxima-syntax)
    ("syntax:maxima:keyword" "#309090" notify-maxima-syntax)
    ("syntax:maxima:keyword_conditional" "#309090" notify-maxima-syntax)
    ("syntax:maxima:keyword_control" "#309090" notify-maxima-syntax)

Unfortunately to no avail.

I just did and with % python ; lovelace I too get the same results now. With % python ; solarized-light however I do not get the yellowish background colouring though.

What is a genetic binary? Would it work on macOS X 13.6/15.7 and can it be compiled with MacPorts?

Did you enable the global bracket matching in the settings?

Yes, I have, if Edit –> Preferences –> Keyboard –> Automatic brackets –> Enable is the same thing. That did work even before I put your code in my-init-texmacs.scm.

There’s some more code that needs adapting to define a new language for highlighting (see e.g. init-code.scm).

I put this into my-init-texmacs.scm

;; Maxima source files

(define-format maxima
(:name “Maxima Source Code”)
(:suffix “mac”))

(define (texmacs->maxima x . opts)
(texmacs->verbatim x (acons “texmacs->verbatim:encoding” “SourceCode” '())))

(define (maxima->texmacs x . opts)
(verbatim->texmacs x (acons “verbatim->texmacs:encoding” “SourceCode” '())))

(define (maxima-snippet->texmacs x . opts)
(verbatim-snippet->texmacs x
(acons “verbatim->texmacs:encoding” “SourceCode” '())))

(converter texmacs-tree maxima-document
(:function texmacs->maxima))

(converter maxima-document texmacs-tree
(:function maxima->texmacs))

(converter texmacs-tree maxima-snippet
(:function texmacs->maxima))

(converter maxima-snippet texmacs-tree
(:function maxima-snippet->texmacs))

No effect on syntax highlighting in a plugin session. But doesn’t that relate to reading in source files?

Perhaps some other (re)definitions are needed. Probably “in-maxima?” (see tm-modes.scm) and inline-code-tag and block-code-tag (text-drd.scm).

And where in the vast ocean of source files can I find them?

Search is your friend :wink:

ack or an IDE like Atom or VS Code are also useful for this.

Is Atom an IDE? I thought it’s yet another text editor that’s going to see its end of life pretty soon. What ever, I ran ack and found:

  • in TeXmacs/progs/text/text-drd.scm:

;; Code fragments

(define-group code-tag
(inline-code-tag) (block-code-tag))

(define-group inline-code-tag
verbatim scm cpp mmx r fortran octave
python julia java javascript json scala scilab shell)

(define-group block-code-tag
verbatim-code scm-code cpp-code dot-code mmx-code r-code fortran-code
octave-code python-code julia-code java-code javascript-code json-code scala-code
scilab-code shell-code)

It seems to me that this does’t relate to plugin sessions but inserting code as formatted text. Well, Maximia isn’t listed but that’s no big deal as we’ve got your payments plugin.

  • in TeXmacs/progs/kernel/texmacs/tm-modes.scm, under the section Mode related these lines:

(in-julia% (== (get-env “prog-language”) “julia”))
(in-prog-julia% #t in-prog% in-julia%)

  1. What exactly do these instructions mean/do!

  2. Would it suffice to replace julia with maxima?

  3. Can I place these changed lines into my-init-texmacs.scm? and what else from this section needs to go in there?

Replacing julia with maxima or Maxima and putting your code into my-init-texmacs.scm did not have any effect whatsoever.

in-maxima? is defined, but in-prog-maxima? isn’t. You only need to prepend its definition like:

(define (in-prog-maxima?)
  (and (in-maxima?) (in-prog?)))

The following Scheme code

  (in-maxima% (== (get-env "prog-language") "maxima"))
  (in-prog-maxima% #t in-prog% in-maxima%))

(tm-define (notify-cursor-moved status)
  (:require prog-highlight-brackets?)
  (:mode in-prog-maxima?)
  (select-brackets-after-movement "([{" ")]}" "\\"))

gives me bracket matching in Maxima sessions.

The code you have in the above post tells TeXmacs what colours you want code to be in, but not what the keywords are that you want to have highlighted. You’ll have to adapt the rest of julia-langs.scm as well.

Dear @jeroen, thanks for your ongoing efforts. I pasted your scheme code

  (in-maxima% (== (get-env "prog-language") "maxima"))
  (in-prog-maxima% #t in-prog% in-maxima%))

(tm-define (notify-cursor-moved status)
  (:require prog-highlight-brackets?)
  (:mode in-prog-maxima?)
  (select-brackets-after-movement "([{" ")]}" "\\"))

into my-init-texmacs.scm, but alas it didn’t give me bracket matching in Maxima sessions. What am I doing wrong here? Even prepending the definition

didn’t help. Is there a special place in the init file where the code has to go?

I missed this before, but there’s another setting: Edit –> Preferences –> Other -> Program bracket matching. Please try enabling that as well.