this post was submitted on 12 Nov 2023
1 points (100.0% liked)

Emacs

312 readers
1 users here now

A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!

Get Emacs

Rules

  1. Posts should be emacs related
  2. Be kind please
  3. Yes, we already know: Google results for "emacs" and "vi" link to each other. We good.

Emacs Resources

Emacs Tutorials

Useful Emacs configuration files and distributions

Quick pain-saver tip

founded 1 year ago
MODERATORS
 

How do I use the fixed-pitch font for math fragments in org-mode buffers? I.e., I want to use a monospace font for all strings of the form \(...\) or \[...\], where ... may include newline characters as well, as is common for equations written in math display mode.

I'm an Emacs newb, so the best I could come up with was a regex-based font-lock:

(progn
  (setq-local font-lock-keywords
              `((,(rx (group
                       (or "\\[" "\\(")
                       (zero-or-more anything)
                       (or "\\]" "\\)"))) (1 'fixed-pitch))))
  (font-lock-fontify-buffer))

And then running this on an org-mode-hook.

But this is definitely wrong. Not only does it remove all the nice org-mode styling applied to things like section headers, but it's also applying the fixed-pitch font to more than just the intended math fragments, suggesting issues with the regex at least.

you are viewing a single comment's thread
view the rest of the comments
[–] nonreligious@alien.top 1 points 1 year ago

If you have the name of the font you want to use in the LaTeX fragments, have you tried using a LaTeX header at the top of the file, e.g.

#+LaTeX_HEADER:\usepackage{mlmodern}

(Replace mlmodern with whatever typeface you prefer)

If you don't want your .org file to become too cluttered at the start, you could alternatively use a setup file via #+SETUPFILE: /path/to/setup-file.org -- create an org file e.g. setup-file.org, and include a line like

#+LaTeX_HEADER:\usepackage{mlmodern}

or whatever your fixed-pitch/monospace font is supposed to be, as well as all the other options you want to use for LaTeX (like other \usepackage declarations, \newcommand definitions etc.).