Hi,

Attached is a _proof of concept_ for supporting AUTO in
\usepackage{fontenc}. Just an idea of how things could evolve.
This only uses a variable you can define as directory or file local to
control what is generated in the LaTeX file.
Could be expanded in the future to check #+language:

Best, /PA

On Mon, 22 Jan 2024 at 14:40, Juan Manuel Macías <maciasch...@posteo.net>
wrote:

> Ihor Radchenko writes:
>
> > Juan Manuel Macías <maciasch...@posteo.net> writes:
> >
> >> Pedro Andres Aranda Gutierrez writes:
> >>
> >>> +#+begin_example
> >>> +,#+latex_class_options: [greek,spanish,oneside]
> >>> +,#+language: es
> >>> +,#+latex_header: \PassOptionsToPackage{main=spanish}{babel}
> >>> +,#+latex_header: \usepackage{alphabeta} % to support greek script
> >>> +#+end_example
> >>
> >> I think this example doesn't take advantage of the AUTO facility, which
> >> is what the section is about.
>
> > Do you have any suggestions how to improve the patch?
>
> I would give an example that did include the AUTO 'facility', to unify
> with the rest of the examples in the section:
>
> #+language: es
> #+latex_header: \usepackage[greek,ngerman,AUTO]{babel}
> #+latex_header: \usepackage{alphabeta} % to support greek script
>
> It is also said in the patch that this example is for pdfTeX, but it
> works equally well for LuaTeX and XeTeX, since Babel and alphabeta
> packages support both engines. However, the alphabeta package is not a
> specific package for writing texts in Greek. Rather, according to the
> package documentation: "The alphabeta package makes the standard macros
> for Greek letters in mathematical mode also available in text mode." In
> pdfTeX it is useful because you can enter the Greek input directly in
> Unicode. But in LuaTeX or XeTeX it would be unnecessary, since Greek can
> be written directly, without the help of additional packages.
>
> >> ... Btw, maybe it would be nice to extend ''AUTO'' to
> >> latex_class_options and \PassOptionsToPackage? Something like:
> >
> > It would really be nice to have an ox-latex maintainer who is deeply
> > familiar with LaTeX :)
>
> My knowledge of LaTeX (and Elisp) has huge gaps :-). Of course, I am
> willing to learn everything I can. And, naturally, I would like to help
> in any way I can. But my main problem (currently) is the lack of time to
> dedicate myself to it. My presence on this list is intermittent, and
> that for a maintainer is horrible. Maybe in a few months (spring
> perhaps), when my personal situation stabilizes a little, I could
> consider it...
>
> Best regards,
>
> Juan Manuel
>
>

-- 
Fragen sind nicht da, um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler

Headaches with a Juju log:
unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should run
a leader-deposed hook here, but we can't yet
From 66634498275a4dbea4cb8dc225db28bdea1bdf1a Mon Sep 17 00:00:00 2001
From: "Pedro A. Aranda" <paag...@gmail.com>
Date: Tue, 23 Jan 2024 08:31:46 +0100
Subject: [PATCH] PoC: support AUTO for the fontenc package in LaTeX exports

* lisp/org.el: Add `org-latex-fontenc' to support translation for
  \usepackage[AUTO]{fontenc}

* lisp/ox-latex.el: Implement rudimentary translation for the above

---
 lisp/org.el      | 17 ++++++++++++-----
 lisp/ox-latex.el | 36 ++++++++++++++++++++++++------------
 2 files changed, 36 insertions(+), 17 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index cf9abafac..d4356e15d 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -3401,9 +3401,16 @@ header, or they will be appended."
 	      x))
 	  (default-value var)))
 
+(defcustom org-latex-fontenc "T1"
+  "The fontenc for the file. Customise to LGR,T1 when including
+Greek, etc."
+  :group 'org-export-latex
+  :type 'string
+  :safe #'stringp)
+
 (defcustom org-latex-default-packages-alist
   '(("AUTO" "inputenc"  t ("pdflatex"))
-    ("T1"   "fontenc"   t ("pdflatex"))
+    ("AUTO" "fontenc"   t ("pdflatex"))
     (""     "graphicx"  t)
     (""     "longtable" nil)
     (""     "wrapfig"   nil)
@@ -15159,20 +15166,20 @@ INCREMENT-STEP divisor."
 	(setq hour (mod hour 24))
 	(setq pos-match-group 1
               new (format "-%02d:%02d" hour minute)))
-       
+
        ((org-pos-in-match-range pos 6) ;; POS on "dmwy" repeater char.
 	(setq pos-match-group 6
               new (car (rassoc (+ nincrements (cdr (assoc (match-string 6 ts-string) idx))) idx))))
-       
+
        ((org-pos-in-match-range pos 5) ;; POS on X in "Xd" repeater.
 	(setq pos-match-group 5
               ;; Never drop below X=1.
               new (format "%d" (max 1 (+ nincrements (string-to-number (match-string 5 ts-string)))))))
-       
+
        ((org-pos-in-match-range pos 9) ;; POS on "dmwy" repeater in warning interval.
 	(setq pos-match-group 9
               new (car (rassoc (+ nincrements (cdr (assoc (match-string 9 ts-string) idx))) idx))))
-       
+
        ((org-pos-in-match-range pos 8) ;; POS on X in "Xd" in warning interval.
 	(setq pos-match-group 8
               ;; Never drop below X=0.
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 57ea66ef1..6da8b8e53 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1639,6 +1639,17 @@ For non-floats, see `org-latex--wrap-label'."
 	      (org-trim label)
 	      (org-export-data main info))))))
 
+(defun org-latex-guess-fontenc (header)
+  "Set the fontenc.
+
+This is currently a copy of `org-latex-guess-inputenc'.
+Currently only goes for `org-latex-fontenc', but can be extended.
+Replaces AUTO for the font encoding string."
+  (let ((fenc org-latex-fontenc))
+    (if (not fenc) header
+      (replace-regexp-in-string "\\\\usepackage\\[\\(AUTO\\)\\]{fontenc}"
+                                fenc header t nil 1))))
+
 (defun org-latex-guess-inputenc (header)
   "Set the coding system in inputenc to what the buffer is.
 
@@ -1989,18 +2000,19 @@ specified in `org-latex-default-packages-alist' or
 	      (user-error "Unknown LaTeX class `%s'" class))))
     (org-latex-guess-polyglossia-language
      (org-latex-guess-babel-language
-      (org-latex-guess-inputenc
-       (org-element-normalize-string
-	(org-splice-latex-header
-	 class-template
-	 (org-latex--remove-packages org-latex-default-packages-alist info)
-	 (org-latex--remove-packages org-latex-packages-alist info)
-	 snippet?
-	 (mapconcat #'org-element-normalize-string
-		    (list (plist-get info :latex-header)
-			  (and (not snippet?)
-			       (plist-get info :latex-header-extra)))
-		    ""))))
+      (org-latex-guess-fontenc
+       (org-latex-guess-inputenc
+        (org-element-normalize-string
+	 (org-splice-latex-header
+	  class-template
+	  (org-latex--remove-packages org-latex-default-packages-alist info)
+	  (org-latex--remove-packages org-latex-packages-alist info)
+	  snippet?
+	  (mapconcat #'org-element-normalize-string
+		     (list (plist-get info :latex-header)
+			   (and (not snippet?)
+			        (plist-get info :latex-header-extra)))
+		     "")))))
       info)
      info)))
 
-- 
2.34.1

Reply via email to