emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: Ihor Radchenko <yantar92@gmail.com>
Cc: orgmode <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] ox-latex.el: Unify in one single list Babel and Polyglossia languages alists
Date: Tue, 19 Jul 2022 15:01:56 +0000	[thread overview]
Message-ID: <87v8rtno2j.fsf@posteo.net> (raw)
In-Reply-To: <87bkto83n7.fsf@localhost> (Ihor Radchenko's message of "Sun, 17 Jul 2022 17:55:24 +0800")

[-- Attachment #1: Type: text/plain, Size: 1209 bytes --]

Here is a new version of the patch, with the fixes added.

Important: I have modified in this patch org-latex-guess-babel-language
so that it recognizes the new Babel syntax alongside the old syntax.
That is, it is now possible to put:

#+LaTeX_Header: \usepackage[arguments,AUTO]{babel}
#+LaTeX_Header: \babelprovide[arguments]{AUTO}

Languages that are served in Babel *exclusively* via ini files (ie those
with an asterisk in the new list) are not added to the Babel argument
(they must be loaded via babelprovide).

However, the following situation may also occur. A user wants to load
the secondary languages via ldf files and the main language via ini
file (babelprovide):

#+LaTeX_Header: \usepackage[french,english]{babel}
#+LaTeX_Header: \babelprovide[main, import]{AUTO}
#+language: ru

This would produce in LaTeX:

\usepackage[french, english, russian]{babel}
\babelprovide[main, import]{russian}

I have not prevented this behavior as it is correct in Babel: you can
load the main language using the 'old style' and then redefine it using
babelprovide, which is a complement. Besides, maintaining this behavior
is also necessary to preserve backwards compatibility.

Best regards,

Juan Manuel 


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-ox-latex.el-New-variable-org-latex-language-ali.patch --]
[-- Type: text/x-patch, Size: 12780 bytes --]

From 2f78d6a75849819f1d3aececff70b7ffa4f36c7c Mon Sep 17 00:00:00 2001
From: Juan Manuel Macias <maciaschain@posteo.net>
Date: Tue, 19 Jul 2022 16:51:55 +0200
Subject: [PATCH] * lisp/ox-latex.el: New variable `org-latex-language-alist'

(org-latex-language-alist): Unify in a single list
`org-latex-polyglossia-language-alist' and
`org-latex-babel-language-alist', and make the two variables
obsolete. However, it may be convenient in the future to replace this
list with a more robust one. (see:
`https://list.orgmode.org/taeb0a$r62$1@ciao.gmane.io')

(org-latex-guess-babel-language): This function has been modified so
that the new Babel command `babelprovide' is also recognized. This
command is necessary to load the languages served by Babel exclusively
through an ini file. Therefore, the new Babel syntax is supported
alongside the old one.  Note that languages that are served
exclusively via an ini file are not added to the Babel argument.
---
 lisp/org-compat.el |   8 ++
 lisp/ox-latex.el   | 236 ++++++++++++++++++++++-----------------------
 2 files changed, 125 insertions(+), 119 deletions(-)

diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index 6f663cc24..835ec2828 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -880,6 +880,12 @@ context.  See the individual commands for more information."
   'org-truly-invisible-p "9.6"
   "Compatibility alias for legacy misspelling of `org-truly-invisible-p'.")
 
+(make-obsolete-variable 'org-latex-babel-language-alist
+                        "set `org-latex-language-alist' instead." "9.6")
+
+(make-obsolete-variable 'org-latex-polyglossia-language-alist
+                        "set `org-latex-language-alist' instead." "9.6")
+
 ;;;; Obsolete link types
 
 (eval-after-load 'ol
@@ -888,6 +894,8 @@ context.  See the individual commands for more information."
      (org-link-set-parameters "file+sys"))) ;since Org 9.0
 
 
+
+
 \f
 ;;; Miscellaneous functions
 
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 1aab8ffd5..2eed44b62 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -172,144 +172,111 @@
 \f
 ;;; Internal Variables
 
-(defconst org-latex-babel-language-alist
-  '(("af" . "afrikaans")
-    ("bg" . "bulgarian")
-    ("ca" . "catalan")
-    ("cs" . "czech")
-    ("cy" . "welsh")
-    ("da" . "danish")
-    ("de" . "germanb")
-    ("de-at" . "naustrian")
-    ("de-de" . "ngerman")
-    ("el" . "greek")
-    ("en" . "english")
-    ("en-au" . "australian")
-    ("en-ca" . "canadian")
-    ("en-gb" . "british")
-    ("en-ie" . "irish")
-    ("en-nz" . "newzealand")
-    ("en-us" . "american")
-    ("es" . "spanish")
-    ("et" . "estonian")
-    ("eu" . "basque")
-    ("fi" . "finnish")
-    ("fr" . "french")
-    ("fr-ca" . "canadien")
-    ("gl" . "galician")
-    ("hr" . "croatian")
-    ("hu" . "hungarian")
-    ("id" . "indonesian")
-    ("is" . "icelandic")
-    ("it" . "italian")
-    ("la" . "latin")
-    ("ms" . "malay")
-    ("nl" . "dutch")
-    ("nb" . "norsk")
-    ("nn" . "nynorsk")
-    ("no" . "norsk")
-    ("pl" . "polish")
-    ("pt" . "portuguese")
-    ("pt-br" . "brazilian")
-    ("ro" . "romanian")
-    ("ru" . "russian")
-    ("sa" . "sanskrit")
-    ("sb" . "uppersorbian")
-    ("sk" . "slovak")
-    ("sl" . "slovene")
-    ("sq" . "albanian")
-    ("sr" . "serbian")
-    ("sv" . "swedish")
-    ("ta" . "tamil")
-    ("tr" . "turkish")
-    ("uk" . "ukrainian"))
-  "Alist between language code and corresponding Babel option.")
-
-(defconst org-latex-polyglossia-language-alist
-  '(("am" "amharic")
+(defconst org-latex-language-alist
+  ;; TODO: replace this list with a property list (the actual
+  ;; implementation is not very robust).
+  '(("am" "amharic" "*")
     ("ar" "arabic")
-    ("ast" "asturian")
+    ("ast" "asturian" "*")
     ("bg" "bulgarian")
-    ("bn" "bengali")
-    ("bo" "tibetan")
+    ("bn" "bengali" "*")
+    ("bo" "tibetan" "*")
     ("br" "breton")
     ("ca" "catalan")
-    ("cop" "coptic")
+    ("cop" "coptic" "*")
     ("cs" "czech")
     ("cy" "welsh")
     ("da" "danish")
-    ("de" "german" "german")
-    ("de-at" "german" "austrian")
-    ("de-de" "german" "german")
-    ("dsb" "lsorbian")
-    ("dv" "divehi")
+    ("de" "ngerman" "german" "german")
+    ("de-at" "naustrian" "german" "austrian")
+    ("dsb" "lsorbian" "*")
+    ("dv" "divehi" "*")
     ("el" "greek")
-    ("en" "english" "usmax")
-    ("en-au" "english" "australian")
-    ("en-gb" "english" "uk")
-    ("en-nz" "english" "newzealand")
-    ("en-us" "english" "usmax")
+    ("el-polyton" "polutonikogreek" "greek" "polytonic")
+    ("en" "american" "english" "usmax")
+    ("en-au" "australian" "english" "australian")
+    ("en-gb" "british" "english" "uk")
+    ("en-nz" "newzealand" "english" "newzealand")
+    ("en-us" "american" "english" "usmax")
     ("eo" "esperanto")
     ("es" "spanish")
+    ("es-mx" "spanishmx" "spanish" "mexican")
     ("et" "estonian")
     ("eu" "basque")
     ("fa" "farsi")
     ("fi" "finnish")
     ("fr" "french")
-    ("fu" "friulan")
+    ("fr-ca" "canadien" "french" "canadian")
+    ("fur" "friulan")
     ("ga" "irish")
     ("gd" "scottish")
     ("gl" "galician")
     ("he" "hebrew")
     ("hi" "hindi")
     ("hr" "croatian")
-    ("hsb" "usorbian")
+    ("hsb" "uppersorbian" "sorbian" "upper")
     ("hu" "magyar")
-    ("hy" "armenian")
+    ("hy" "armenian" "*")
     ("ia" "interlingua")
-    ("id" "bahasai")
+    ("id" "bahasai" "*")
     ("is" "icelandic")
     ("it" "italian")
-    ("kn" "kannada")
-    ("la" "latin" "modern")
-    ("la-classic" "latin" "classic")
-    ("la-medieval" "latin" "medieval")
-    ("la-modern" "latin" "modern")
-    ("lo" "lao")
+    ("kn" "kannada" "*")
+    ("la" "latin")
+    ("la-classic" "classiclatin" "latin" "classic")
+    ("la-medieval" "medievallatin" "latin" "medieval")
+    ("la-ecclesiastic" "ecclesiasticlatin" "latin" "ecclesiastic")
+    ("lo" "lao" "*")
     ("lt" "lithuanian")
     ("lv" "latvian")
-    ("ml" "malayalam")
-    ("mr" "maranthi")
-    ("nb" "norsk")
-    ("nko" "nko")
+    ("ml" "malayalam" "*")
+    ("mr" "maranthi" "*")
+    ("nb" "norsk" "norwegian" "bokmal")
     ("nl" "dutch")
-    ("nn" "nynorsk")
+    ("nn" "nynorsk" "norwegian" "nynorsk")
     ("no" "norsk")
     ("oc" "occitan")
     ("pl" "polish")
     ("pms" "piedmontese")
     ("pt" "portuges")
     ("pt-br" "brazilian")
-    ("rm" "romansh")
+    ("rm" "romansh" "*")
     ("ro" "romanian")
     ("ru" "russian")
-    ("sa" "sanskrit")
-    ("se" "samin")
+    ("sa" "sanskrit" "*")
     ("sk" "slovak")
-    ("sl" "slovenian")
+    ("sl" "slovene")
     ("sq" "albanian")
     ("sr" "serbian")
     ("sv" "swedish")
-    ("syr" "syriac")
-    ("ta" "tamil")
-    ("te" "telugu")
+    ("syr" "syriac" "*")
+    ("ta" "tamil" "*")
+    ("te" "telugu" "*")
     ("th" "thai")
     ("tk" "turkmen")
     ("tr" "turkish")
     ("uk" "ukrainian")
-    ("ur" "urdu")
+    ("ur" "urdu" "*")
     ("vi" "vietnamese"))
-  "Alist between language code and corresponding Polyglossia option.")
+  "Alist between language code and corresponding Babel/Polyglossia option.
+
+For the names of the languages, the Babel nomenclature is
+preferred to that of Polyglossia, in those cases where both
+coincide.
+
+The alist supports three types of members:
+
+- Members with two elements: CODE BABEL/POLYGLOSSIA OPTION.
+
+- Members with three elements: CODE BABEL/POLYGLOSSIA OPTION
+ASTERISK (the presence of the asterisk indicates that this
+language is not loaded in Babel using the old method of ldf
+files but using ini files. If Babel is loaded in an Org
+document with these languages, the \"AUTO \" argument is just
+removed, to avoid compilation errors).
+
+- Members with four elements (for variants of languages): CODE
+BABEL-OPTION POLYGLOSSIA-OPTION POLYGLOSSIA-VARIANT")
 
 (defconst org-latex-table-matrix-macros '(("bordermatrix" . "\\cr")
 					  ("qbordermatrix" . "\\cr")
@@ -1644,31 +1611,54 @@ Insertion of guessed language only happens when Babel package has
 explicitly been loaded.  Then it is added to the rest of
 package's options.
 
-The argument to Babel may be \"AUTO\" which is then replaced with
-the language of the document or `org-export-default-language'
-unless language in question is already loaded.
+The optional argument to Babel or the mandatory argument to
+`\babelprovide' command may be \"AUTO\" which is then replaced
+with the language of the document or
+`org-export-default-language' unless language in question is
+already loaded.
 
 Return the new header."
-  (let ((language-code (plist-get info :language)))
-    ;; If no language is set or Babel package is not loaded, return
-    ;; HEADER as-is.
-    (if (or (not (stringp language-code))
-	    (not (string-match "\\\\usepackage\\[\\(.*\\)\\]{babel}" header)))
+  (let* ((language-code (plist-get info :language))
+	 (language (nth 1 (assoc language-code
+				 org-latex-language-alist)))
+	 ;; If no language is set or Babel package is not loaded, return
+ 	 ;; HEADER as-is.
+	 (header (if (or (not (stringp language-code))
+			 (not (string-match "\\\\usepackage\\[\\(.*\\)\\]{babel}" header)))
+		     header
+		   (let ((options (save-match-data
+				    (org-split-string (match-string 1 header) ",[ \t]*"))))
+		     ;; If LANGUAGE is already loaded, return header
+		     ;; without AUTO.  Otherwise, replace AUTO with language or
+		     ;; append language if AUTO is not present.  Languages that are
+		     ;; served in Babel exclusively through ini files are not added
+		     ;; to the babel argument, and must be loaded using
+		     ;; `\babelprovide'.
+		     (let ((l (assoc language-code org-latex-language-alist)))
+                       ;; Three elements imply that LANGUAGE is served
+                       ;; in Babel only by means of an ini file.
+                       ;; Therefore it will not be added to the Babel
+                       ;; argument.  TODO: this should be improved
+                       ;; when `org-latex-language-alist' is replaced
+                       ;; by a more robust list.
+		       (if (and (consp l) (= (length l) 3))
+                           header
+			 (replace-match
+			  (mapconcat (lambda (option) (if (equal "AUTO" option) language option))
+				     (cond ((member language options) (delete "AUTO" options))
+					   ((member "AUTO" options) options)
+					   (t (append options (list language))))
+				     ", ")
+			  t nil header 1)))))))
+    ;; if `\babelprovide[args]{AUTO}' is present, AUTO is
+    ;; replaced by LANGUAGE.
+    (if (not (string-match "\\\\babelprovide\\[.*\\]{\\(.+\\)}" header))
 	header
-      (let ((options (save-match-data
-		       (org-split-string (match-string 1 header) ",[ \t]*")))
-	    (language (cdr (assoc-string language-code
-					 org-latex-babel-language-alist t))))
-	;; If LANGUAGE is already loaded, return header without AUTO.
-	;; Otherwise, replace AUTO with language or append language if
-	;; AUTO is not present.
-	(replace-match
-	 (mapconcat (lambda (option) (if (equal "AUTO" option) language option))
-		    (cond ((member language options) (delete "AUTO" options))
-			  ((member "AUTO" options) options)
-			  (t (append options (list language))))
-		    ", ")
-	 t nil header 1)))))
+      (let ((prov (match-string 1 header)))
+	(when (equal "AUTO" prov)
+	  (replace-regexp-in-string (format
+				     "\\(\\\\babelprovide\\[.*\\]\\)\\({\\)%s}" prov)
+				    (format "\\1\\2%s}" language) header t))))))
 
 (defun org-latex-guess-polyglossia-language (header info)
   "Set the Polyglossia language according to the LANGUAGE keyword.
@@ -1710,15 +1700,23 @@ Return the new header."
 	 (concat "\\usepackage{polyglossia}\n"
 		 (mapconcat
 		  (lambda (l)
-		    (let ((l (or (assoc l org-latex-polyglossia-language-alist)
+		    (let ((l (or (assoc l org-latex-language-alist)
 				 l)))
 		      (format (if main-language-set "\\setotherlanguage%s{%s}\n"
 				(setq main-language-set t)
 				"\\setmainlanguage%s{%s}\n")
-			      (if (and (consp l) (= (length l) 3))
-				  (format "[variant=%s]" (nth 2 l))
+                              ;; Four elements implies that there is a
+                              ;; variant (4) for LANGUAGE when
+                              ;; declared by Polyglossia (3). TODO:
+                              ;; this should be improved when
+                              ;; `org-latex-language-alist' is
+                              ;; replaced by a more robust list.
+                              (if (and (consp l) (= (length l) 4))
+				  (format "[variant=%s]" (nth 3 l))
 				"")
-			      (nth 1 l))))
+			      (if (and (consp l) (= (length l) 4))
+				  (nth 2 l)
+				(nth 1 l)))))
 		  languages
 		  ""))
 	 t t header 0)))))
-- 
2.37.1


  parent reply	other threads:[~2022-07-19 16:09 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-03 15:28 [PATCH] ox-latex.el: Unify in one single list Babel and Polyglossia languages alists Juan Manuel Macías
2022-07-10  9:25 ` Ihor Radchenko
2022-07-14 12:34   ` Juan Manuel Macías
2022-07-14 15:12     ` Max Nikulin
2022-07-14 15:53       ` Juan Manuel Macías
2022-07-14 18:17         ` Juan Manuel Macías
2022-07-15 12:18           ` Max Nikulin
2022-07-15 14:36             ` Juan Manuel Macías
2022-07-17  9:55     ` Ihor Radchenko
2022-07-17 14:48       ` Juan Manuel Macías
2022-07-18  6:44         ` Ihor Radchenko
2022-07-18 10:32           ` Juan Manuel Macías
2022-07-18 11:01             ` Juan Manuel Macías
2022-07-18 15:37             ` Max Nikulin
2022-07-18 16:21               ` Juan Manuel Macías
2022-07-19 15:01       ` Juan Manuel Macías [this message]
2022-07-19 17:01         ` Max Nikulin
2022-07-19 19:31           ` Juan Manuel Macías
2022-07-20 16:12             ` Max Nikulin
2022-07-20 21:30               ` Juan Manuel Macías
2022-07-21 14:36                 ` Max Nikulin
2022-07-21 15:39                   ` Juan Manuel Macías
2022-07-22 12:16                     ` Max Nikulin
2022-07-22 12:49                       ` Juan Manuel Macías
2022-07-22 14:07                         ` Juan Manuel Macías
2022-07-23 15:19                           ` Max Nikulin
2022-07-23 17:15                             ` Improvements in the default LaTeX preamble (was: [PATCH] ox-latex.el: Unify in one single list Babel and Polyglossia languages alists) Juan Manuel Macías
2022-07-24 12:06                               ` Improvements in the default LaTeX preamble: templates? " Juan Manuel Macías
2022-07-25  9:31                                 ` Ihor Radchenko
2022-07-25 10:45                                   ` Improvements in the default LaTeX preamble: templates? Juan Manuel Macías
2022-07-23  5:01         ` [PATCH] ox-latex.el: Unify in one single list Babel and Polyglossia languages alists Ihor Radchenko
2022-07-23 13:44           ` BUG " Kai von Fintel
2022-07-23 13:59             ` Ihor Radchenko
2022-07-23 14:07               ` Kai von Fintel
2022-07-23 14:22                 ` Ihor Radchenko
2022-07-23 14:39                   ` Kai von Fintel
2022-07-23 14:50                     ` Ihor Radchenko
2022-07-23 15:53                       ` Juan Manuel Macías
2022-07-24  7:15                         ` Ihor Radchenko
2022-07-24 11:29                           ` Juan Manuel Macías
2022-07-26 11:58                             ` Ihor Radchenko
2022-07-26 16:19                               ` Juan Manuel Macías
2022-07-28 12:36                                 ` Ihor Radchenko
2022-07-23 14:53                     ` Juan Manuel Macías
2022-07-23 14:11           ` Juan Manuel Macías
2022-07-23 14:25             ` Ihor Radchenko
2022-07-23 15:29           ` Max Nikulin
2022-07-24  7:23             ` Ihor Radchenko
2022-07-10 10:51 ` Max Nikulin
2022-07-15 15:38   ` Juan Manuel Macías

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87v8rtno2j.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=yantar92@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).