From 219c1b19823cd8364c2bdbf8becca0b320894a7d Mon Sep 17 00:00:00 2001
From: Derek Chen-Becker <oss@chen-becker.org>
Date: Mon, 24 Nov 2025 08:05:24 -0700
Subject: [PATCH 2/2] lisp/ox-latex.el: Properly format priority values

Fix LaTeX export so that it properly handles numeric priority values in
addition to characters.

* lisp/ox-latex.el (org-latex-format-headline-default-function): Change
format of priorities to use the `org-priority-to-string' function instead
of assuming a character value.
* testing/lisp/test-ox-latex.el: Fix a typo in the
`test-ox-latex/protect-square-brackets' test so that its name matches the
rest of the tests.  Add unit tests for LaTeX export of headlines with
priorities for both numeric and character values.
---
 lisp/ox-latex.el              |  2 +-
 testing/lisp/test-ox-latex.el | 29 ++++++++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index cf4f10f2a..af4196e09 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2525,7 +2525,7 @@ holding contextual information."
 See `org-latex-format-headline-function' for details."
   (concat
    (and todo (format "{\\bfseries\\sffamily %s} " todo))
-   (and priority (format "\\framebox{\\#%c} " priority))
+   (and priority (format "\\framebox{\\#%s} " (org-priority-to-string priority)))
    text
    (and tags
 	(format "\\hfill{}\\textsc{%s}"
diff --git a/testing/lisp/test-ox-latex.el b/testing/lisp/test-ox-latex.el
index 35088deee..64ab7d467 100644
--- a/testing/lisp/test-ox-latex.el
+++ b/testing/lisp/test-ox-latex.el
@@ -29,7 +29,7 @@
 
 
 
-(ert-deftest text-ox-latex/protect-square-brackets ()
+(ert-deftest test-ox-latex/protect-square-brackets ()
   "Test [foo] being interpreted as plain text even after LaTeX commands."
   (org-test-with-exported-text
       'latex
@@ -284,5 +284,32 @@ is suppressed
     (should (search-forward
              "\\section[\\(\\psi\\) wraps too]{\\(\\phi\\) wraps}"))))
 
+(ert-deftest test-ox-latex/numeric-priority-headline ()
+  "Test numeric priorities in headlines."
+  (org-test-with-exported-text
+   'latex
+   "#+OPTIONS: pri:t
+* [#3] Test
+"
+   (goto-char (point-min))
+   (should (search-forward "\\framebox{\\#3}")))
+  (org-test-with-exported-text
+   'latex
+   "#+OPTIONS: pri:t
+* [#42] Test
+"
+   (goto-char (point-min))
+   (should (search-forward "\\framebox{\\#42}"))))
+
+(ert-deftest test-ox-latex/alphabetical-priority-headline ()
+  "Test numeric priorities in headlines."
+  (org-test-with-exported-text
+   'latex
+   "#+OPTIONS: pri:t
+* [#C] Test
+"
+   (goto-char (point-min))
+   (should (search-forward "\\framebox{\\#C}"))))
+
 (provide 'test-ox-latex)
 ;;; test-ox-latex.el ends here
-- 
2.43.0

