From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id KIPMBTvX1mL+UAEAbAwnHQ (envelope-from ) for ; Tue, 19 Jul 2022 18:09:31 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id yP7ABDvX1mJTpgAAG6o9tA (envelope-from ) for ; Tue, 19 Jul 2022 18:09:31 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id C025B384A7 for ; Tue, 19 Jul 2022 18:03:24 +0200 (CEST) Received: from localhost ([::1]:40264 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDolQ-0003Vu-1i for larch@yhetil.org; Tue, 19 Jul 2022 11:03:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39274) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDojq-0003UE-OJ for emacs-orgmode@gnu.org; Tue, 19 Jul 2022 11:02:18 -0400 Received: from mout02.posteo.de ([185.67.36.66]:40663) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDoja-0006c9-Kq for emacs-orgmode@gnu.org; Tue, 19 Jul 2022 11:02:18 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 5964B24010A for ; Tue, 19 Jul 2022 17:01:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1658242920; bh=V3oVRmn28Ksbea7KuFtlOBbCopJDLtjkCXVk8D5Mc+Q=; h=From:To:Subject:CC:Date:From; b=QZygEVxG6BBjjHz5oZK1TOkwwoWuhx3AuQ4EBGE0W7UjQ4iWvcwxcLYOGnh/0KPrr hTqfGb44whxKO+68xOlnlMjvtnxdTaMkyvqnQhxBYjibEsiKzOsGyeeTNdKh0MW+7z zzQVmORVv54hq5olaU+ATCvDDUzb8JW31NRyma9aGZvqMvTz0VPIPloN0s9uir70FB +S9RnCW9fdPQqlKx7qSQ69mbEve5UhXMjhbf/syLe9pQSBtw9HjqDwasv/9hPzKHDF jIy22o6XGOjQ9DnDAMaV1n7H1uwbfgWN8h683CeyebUdFm949VNRfv2KxcdjQQREh0 DFs7fuPi9reRA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4LnMVt338gz9rxB; Tue, 19 Jul 2022 17:01:58 +0200 (CEST) From: =?utf-8?Q?Juan_Manuel_Mac=C3=ADas?= To: Ihor Radchenko Subject: Re: [PATCH] ox-latex.el: Unify in one single list Babel and Polyglossia languages alists References: <87sfxiw2jp.fsf@posteo.net> <87czeduxnz.fsf@localhost> <87lesvlvos.fsf@posteo.net> <87bkto83n7.fsf@localhost> CC: orgmode Date: Tue, 19 Jul 2022 15:01:56 +0000 In-Reply-To: <87bkto83n7.fsf@localhost> (Ihor Radchenko's message of "Sun, 17 Jul 2022 17:55:24 +0800") Message-ID: <87v8rtno2j.fsf@posteo.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.66; envelope-from=maciaschain@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1658246604; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=w+HlMfkms2+LyAC8afhpEZnl+GxezoG/sgZLS7q33U0=; b=be6pFAVcvCDL6/6PDQJoa6P/tbQRjFSn4+/nB5mY3mf7gx9+Gi75JkJDJZfA0OBp5ncRRv O8xqeGf+olDf3Fjjg2+a3ULVR/TssMj3+eEOPRq3NBSCVJpjptDeNOpgO7Pjw9aYa2MaFw 4xMj/2+Ix2Os+cVfDdNmlQtY94n7jMheTYsnOp5PCoFKAWReSD8demcsN9hiO8Mdq65diX R38P6hoyACur9RhY2gkZOMDD/xafS0pICN/6jXUy7JTARGZA5xIogIzK+rUALC+5CS2YcZ Dz8nLRe2UyNuU+ay5tFV4POBtp18kHjw7TnOwhWSeStIQ6ZQIsOb6mx+VyRFUw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1658246604; a=rsa-sha256; cv=none; b=takOENEwn4WsCpVejY8/iLXJ69sfbaGO6o9wOQmmiTsQRvopQEJK+MZGWN+ZKKaPWdKK4z +CX0SHyTLn4uu2DtcCjBoZXEpNDH5Twbfb1fsV3gwjiJvG3NOqOEBsOof+z5bTbOV9ReBs JiH8y39tJJqCjOavlFLkZXisOC7I6FWufIkD55S3lwW7HEYNyfWI1inVsByyN7Mh95T/Ah aSgEAyGxF1MbWNWm9VxVAzUDDECYvvAMaX3CMfLEBK/dHbmQ2oBj6OoLOYicIFIQB5gwYk G5VDGLO9XKpMh9xHazEKCuVbnhgEGSpj4zj8GLDJBgLyIE5Lu1cjiT1rDvCZBg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=QZygEVxG; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -5.73 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=QZygEVxG; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: C025B384A7 X-Spam-Score: -5.73 X-Migadu-Scanner: scn0.migadu.com X-TUID: GjbisUOwZTPJ --=-=-= Content-Type: text/plain 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 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-lisp-ox-latex.el-New-variable-org-latex-language-ali.patch >From 2f78d6a75849819f1d3aececff70b7ffa4f36c7c Mon Sep 17 00:00:00 2001 From: Juan Manuel Macias 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 + + ;;; 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 @@ ;;; 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 --=-=-=--