0

I use Emacs with Tuareg for writing code in OCaml. Also, I write code in documents out of Emacs (not for compilation) and found that some fixed-pitch fonts are pretty good in visualization for some operators. The following image shows how Fragment Mono font renders character pairs to single characters with two symbols width.

enter image description here

I have added Fragment Mono as default to my init file, but it doesn't work as expected.

(set-face-attribute 'default nil :font "Fragment Mono")

The font was applied without the merging feature. Is it possible to do something to fix this problem?

1
  • 1
    "ligatures" would be a good search term here. Nov 15, 2023 at 21:04

1 Answer 1

2

Emacs has support for this kind of "merging", but calls it "composition". You need to explicitly configure it for this kind of situation.

The following code somewhere in your init file should do the trick for the compositions you mentioned.

(let ((al '((?- . "->")
            (?< . "<[=-]")
            (?! . "!=")
            (?> . ">=")
            (?= . "==")
            (?| . "|>"))))
  (dolist (elt al)
    (aset composition-function-table
      (car elt)
      `([,(cdr elt) 0 compose-gstring-for-graphic]))))
1
  • It's so easy, and it works. My investigation of ligatures got me much more complicated solutions. Nov 16, 2023 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.