Trigger export to latex by a keyboard shortcut

When writing latex math I like to write it in texmacs and copy the exported latex code. This requires me to click File - Export - Latex frequently. Is there a way to trigger the export by a keyboard shortcut?

I’m also wondering, more generally, can we set a keyboard shortcut for any menu item? This was mentioned in

Please see if this blog post helps: https://texmacs.github.io/notes/docs/menu-shortcuts.html
It starts also from a forum post.

I did find some suspicious-looking ones in the progs folder, but none of them worked…

Hi @toshiki, please take a look at this mailing list thread

https://lists.texmacs.org/wws/arc/texmacs-users/2021-11/msg00056.html

I would try the function in the follow-up of @jeroen, substituting “html” with “latex” (all lowercase letters) everywhere. I did not try it.

I tested

(choose-file (buffer-exporter "latex") "save" "latex")

which I got out of progs/texmacs/menus/file-menu.scm with a little bit (just a little bit) of code interpretation and it worked, but I still would prefer @jeroen 's code (I think it warns the user before overwriting files).

2 Likes

Just do (export-buffer (string->url "/tmp/A.tex")).

Thank you for the reply! I actually don’t want any confirmation, just generate a tex file with the same name and overwrite.

The one original one (html) by @jeroen gives error when running on C:/Users/Me/Downloads/Formula.tm:

Warning: Couldn’t concretize tuple (concat, etc, papersize)
Warning: Couldn’t concretize tuple (concat, C, tuple (concat, Users, tuple (concat, Me, tuple (concat, Downloads, Formula.html))))
Warning: Save error for C:\Users\Me\Downloads\C\Users\Me\Downloads\Formula.html, No error

I want to disable the overwrite check and wrote:

(define (propose-latex-name)
  (with name (propose-name-buffer)
    (if (string-ends? name ".tm")
      (string-append (string-drop-right name 3) ".tex"))))


(define (export-to-proposed-latex)
  (let ((latex-name (propose-latex-name)))
    ((buffer-exporter "latex") latex-name)))

(kbd-map
  ("C-4" (export-to-proposed-latex)))

When I run it I get error:

Warning: Couldn’t concretize tuple (concat, etc, papersize)
Warning: Save error for C:\Users\Me\Downloads\C\Users\Me\Downloads\Formula.tex, No error

I saw a post in the forum about a similar error, which was solved by updating the app. I tried reinstalling Texmacs (2.1.4) with deletion of C:\Users\Me\AppData\Roaming\TeXmacs, but it still doesn’t work. I can open source.ts.

The code by you works. I only found one mention of buffer-exporter in the codebase, haha. It’s just that it opens a file picker window each time and I need to then click export. But it’s definitely much easier than before.

This gives error

Warning: Couldn’t concretize tuple (concat, etc, papersize)
Warning: Couldn’t concretize tuple (concat, tmp, A.tex)
Warning: Couldn’t concretize tuple (concat, tmp, A.tex)
Warning: Couldn’t concretize tuple (concat, tmp, A.tex)
Warning: Couldn’t concretize tuple (concat, tmp, A.tex)
Warning: Save error for C:\Users\Me\temp\A.tex, No error

You should check if they throw out the same latex file. Deep down they are tracing to export-buffer-main in the same way.