From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.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 0D1zFQxN+WLj2gAAbAwnHQ (envelope-from ) for ; Sun, 14 Aug 2022 21:29:16 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id QPWCFQxN+WJsqgAA9RJhRA (envelope-from ) for ; Sun, 14 Aug 2022 21:29:16 +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 B03552E51D for ; Sun, 14 Aug 2022 21:29:15 +0200 (CEST) Received: from localhost ([::1]:45466 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNJIQ-0003gt-Sh for larch@yhetil.org; Sun, 14 Aug 2022 15:29:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55218) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNJHz-0003gU-EU for emacs-orgmode@gnu.org; Sun, 14 Aug 2022 15:28:47 -0400 Received: from mr85p00im-ztdg06021701.me.com ([17.58.23.196]:51480) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNJHw-0003cC-VQ for emacs-orgmode@gnu.org; Sun, 14 Aug 2022 15:28:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1660505322; bh=aDlKdcyF9v5HEQ0X/VkCD3wjN+MH2fqFepQN7sNoZts=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=sUreqkFsrGDE4ZnPyCs+jrm077whKlkklD8XINp1z7pmUDwOoW8wN8fExMhSXBHLk 8nVpGGLXa7jUCxO0VZagghBKs9M/5MQbHJFk7YfiwlryC0r9KCZG03VL1sG+f3vHYA tZhYiFXPFFUTj+9z4QUuJpOtq0iEi96Haov56BHZfLdueJTpTJrMKaYCWtW1tzL+F+ +USArHrJSb91jWBfR7sNYVD/G642dLexgeIbi84bwQCGNzb0JRMWl9eoJjkYkmLQ4Y JF78vbXWAC7xKndfrwPrnUSkVHcKVOP+RhO8xD5fAydmIjxy5yuXl1kBGdBpurxrdy 4bpItw4gy2VxA== Received: from Rudolfs-MacBook-Air.local (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-ztdg06021701.me.com (Postfix) with ESMTPSA id 7745A9A0565; Sun, 14 Aug 2022 19:28:41 +0000 (UTC) From: Rudolf =?utf-8?Q?Adamkovi=C4=8D?= To: Ihor Radchenko Cc: Nicolas Goaziou , emacs-orgmode@gnu.org Subject: Re: [PATCH] Re: No mathematics in Texinfo exports In-Reply-To: <87edzlxdsq.fsf@localhost> References: <87o80v3qzw.fsf@localhost> <87mtgedh98.fsf@nicolasgoaziou.fr> <87a6cezrhm.fsf@localhost> <87bkwud6ni.fsf@nicolasgoaziou.fr> <87czhazhfz.fsf@localhost> <87k0amb4qf.fsf@localhost> <87v8twscml.fsf@localhost> <874k1ae5tz.fsf@localhost> <87bkv75mgo.fsf@localhost> <87edzlxdsq.fsf@localhost> Date: Sun, 14 Aug 2022 21:28:37 +0200 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Proofpoint-ORIG-GUID: QvUEDQ-RBb670ZytuBn3DkDG0SKMrWiE X-Proofpoint-GUID: QvUEDQ-RBb670ZytuBn3DkDG0SKMrWiE X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.138,18.0.572,17.0.605.474.0000000_definitions?= =?UTF-8?Q?=3D2020-02-14=5F11:2020-02-14=5F02,2020-02-14=5F11,2020-01-23?= =?UTF-8?Q?=5F02_signatures=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 clxscore=1015 mlxscore=0 spamscore=0 bulkscore=0 adultscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2208140085 Received-SPF: pass client-ip=17.58.23.196; envelope-from=salutis@me.com; helo=mr85p00im-ztdg06021701.me.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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=1660505356; 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=L7nZG0cic5yvwqGAut531E2JIz5vJ7HoqNhfRKbIvoo=; b=Bl3jdtAHxFhVJ1Q4KrfRxgInYQfmh6Geg0AbJli+YYF5xNZsHyCQPSl+joHFz96CPXU0u0 RvNDqsFg4BwR8xadH4Ga4D9dBUoBflOX5gBLmRIklS5txfg7acTyqxrL3A8mlfuhrxmFjG /2z+8HFck+EAjZm9lp8DCw5CiMABTiXV2rFLALmXD/u3IwRrl09ZE9qjkb5WLQSfgPfKTX kKoXqw4LIcYqKn1FMSEvoUBy87sZeJ/VtM2jixhakS4i8hj3KpcJbLvZ6IebtbLG0HxoHA rGCEHEGGml3JFKA3bOxKderK5LQjfxXvGqS+P/ZkZoMhhkfSBPWFj0Bqe4KQlw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1660505356; a=rsa-sha256; cv=none; b=MLxNkBz+Bvg+9g9W+eQewsMJXf25Tq3Jc2clfLr8aB2WYaLOZ55W6uOsx8cN2d4FXtRXdZ 1W2dEpAnUiTcH4pTLitgR4l+ICaIlPdBMHiFDtcXCZL8yv5uNvgML8QSRehSqPvOeDONGl 859f32xfkSgPC2ga7x4B6LdEsU2OgKH0mUSRYxXPULaAKI2tX9uC5iUGghP9RuJg6KExqv ongNVfneNWHTOl0+RiluFPBz4vF3VttK8il0FL04eJeYKtRO/PrMNn4ghzJHNOIq6+3eax kK+j/QQRK0VAdO+btDT/jAZkUyIHqXJDr6U5cjnxdOE6r0BRE/pwzEIOsDYopA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=me.com header.s=1a1hai header.b=sUreqkFs; dmarc=fail reason="SPF not aligned (relaxed)" header.from=me.com (policy=quarantine); 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: 6.00 X-Spam: Yes Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=me.com header.s=1a1hai header.b=sUreqkFs; dmarc=fail reason="SPF not aligned (relaxed)" header.from=me.com (policy=quarantine); 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: B03552E51D X-Spam-Score: 6.00 X-Migadu-Spam: Yes X-Migadu-Scanner: scn1.migadu.com X-TUID: i5w9IKz0mhh9 --=-=-= Content-Type: text/plain Ihor Radchenko writes: > Looks reasonable. Thank you for guiding me through, Ihor. I had some time today, so I pushed the envelope a bit further, hopefully in the right direction! > First of all, checking version should probably be controlled by some > customization. Especially when we export to .texi (which does not > involve calling makeinfo), not to .info. I could not figure out how to tell between the two kinds of export. My attempt, in 'org-texinfo-latex-environment': (message "filename1: %s" (plist-get info :output-file)) (message "filename2: %s" (plist-get info :texinfo-filename)) I always got the following, not matter what: filename1: test.texi filename2: nil > This customization might be set to 'auto by default, making ox-texinfo > check makeinfo version. We now set the customization to 'detect. If you think 'auto makes for a better name, for consistency or some other reason, please let me know. > Parsing version is probably the easiest way. Another alternative is > trying to run makeinfo on a small test file with math environment and > checking if it gets exported as expected. I went for the latter, see 'org-texinfo-supports-math-p' in the attached patch. Please take a look. [From the other thread:] > The problem is that people may not know this feature exists and should > be enabled. You still need to add NEWS entry (in any case) and manual > entry (if the feature should be enabled manually). I decided NOT to "chicken out", so I added just a NEWS entry, now that we attempt to auto-detect whether Texinfo supports math or not. Rudy --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=0001-ox-texinfo-Include-LaTeX-in-Texinfo-exports.patch Content-Transfer-Encoding: quoted-printable >From e03b29319b602b0dea3c15604d711010bddaa3ba Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Rudolf=3D20Adamkovi=3DC4=3D8D?=3D Date: Sat, 26 Mar 2022 16:46:47 +0100 Subject: [PATCH] ox-texinfo: Include LaTeX in Texinfo exports * lisp/ox-texinfo.el (org-texinfo-with-latex): New customize. * lisp/ox-texinfo.el (org-texinfo-latex-environment): New function. * lisp/ox-texinfo.el (org-texinfo-latex-fragment): New function. * lisp/ox-texinfo.el (org-texinfo-supports-math-p): New function. * lisp/ox-texinfo.el (texinfo): Set latex-environment. * lisp/ox-texinfo.el (texinfo): Set latex-fragment. * testing/lisp/test-ox-texinfo.el: Add basic tests. Include inline and display style (La)TeX mathematics in Texinfo exports. --- etc/ORG-NEWS | 1 + lisp/ox-texinfo.el | 86 ++++++++++++- testing/lisp/test-ox-texinfo.el | 221 ++++++++++++++++++++++++++++++++ 3 files changed, 307 insertions(+), 1 deletion(-) create mode 100644 testing/lisp/test-ox-texinfo.el diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 00fe101dc..52fa881f3 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -270,6 +270,7 @@ example, =20 prints a sub-bibliography containing the book entries with =3Dai=3D among their keywords. +*** Support for LaTeX mathematics in Texinfo exports ** New options *** A new custom setting =3Dorg-hide-drawer-startup=3D to control initial = folding state of drawers =20 diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el index 1eec586fd..a88224197 100644 --- a/lisp/ox-texinfo.el +++ b/lisp/ox-texinfo.el @@ -55,6 +55,8 @@ (italic . org-texinfo-italic) (item . org-texinfo-item) (keyword . org-texinfo-keyword) + (latex-environment . org-texinfo-latex-environment) + (latex-fragment . org-texinfo-latex-fragment) (line-break . org-texinfo-line-break) (link . org-texinfo-link) (node-property . org-texinfo-node-property) @@ -120,7 +122,9 @@ (:texinfo-text-markup-alist nil nil org-texinfo-text-markup-alist) (:texinfo-format-drawer-function nil nil org-texinfo-format-drawer-fun= ction) (:texinfo-format-inlinetask-function nil nil org-texinfo-format-inline= task-function) - (:texinfo-compact-itemx nil "compact-itemx" org-texinfo-compact-itemx)= )) + (:texinfo-compact-itemx nil "compact-itemx" org-texinfo-compact-itemx) + ;; Redefine regular options. + (:with-latex nil "tex" org-texinfo-with-latex))) =20 ;;; User Configurable Variables @@ -355,6 +359,22 @@ The function should return the string to be exported." :group 'org-export-texinfo :type 'function) =20 +;;;; LaTeX + +(defcustom org-texinfo-with-latex (and org-export-with-latex 'auto) + "If non-nil, the Texinfo exporter attempts to process LaTeX math. + +When set to t, the exporter always processes LaTeX environments +and fragments as Texinfo \"@displaymath\" and \"@math\" commands +respectively. Alternatively, when set to 'detect, the exporter +does so only if the installed version of Texinfo supports the +necessary commands." + :group 'org-export-texinfo + :type '(choice + (const :tag "Detect" detect) + (const :tag "Yes" t) + (const :tag "No" nil))) + ;;;; Itemx =20 (defcustom org-texinfo-compact-itemx nil @@ -1212,6 +1232,52 @@ CONTENTS is nil. INFO is a plist holding contextual= information." (concat "@listoffloats " (org-export-translate "Listing" :utf-8 info)))))))) =20 +;;;; LaTeX Environment + +(defun org-texinfo-latex-environment (environment _contents info) + "Transcode a LaTeX ENVIRONMENT from Org to Texinfo. CONTENTS is +nil. INFO is a plist holding contextual information." + (let ((with-latex (plist-get info :with-latex))) + (when (or (eq with-latex t) + (and (eq with-latex 'detect) + (org-texinfo-supports-math-p))) + (let ((value (org-element-property :value environment))) + (string-join (list "@displaymath" + (string-trim (org-remove-indentation value)) + "@end displaymath") + "\n"))))) + +;;;; LaTeX Fragment + +(defun org-texinfo-latex-fragment (fragment _contents info) + "Transcode a LaTeX FRAGMENT from Org to Texinfo. CONTENTS is +nil. INFO is a plist holding contextual information." + (let ((with-latex (plist-get info :with-latex))) + (when (or (eq with-latex t) + (and (eq with-latex 'detect) + (org-texinfo-supports-math-p))) + (let ((value (org-remove-indentation + (org-element-property :value fragment)))) + (cond + ((or (string-match-p "^\\\\\\[" value) + (string-match-p "^\\$\\$" value)) + (concat "\n" + "@displaymath" + "\n" + (string-trim (substring value 2 -2)) + "\n" + "@end displaymath" + "\n")) + ((string-match-p "^\\$" value) + (concat "@math{" + (string-trim (substring value 1 -1)) + "}")) + ((string-match-p "^\\\\(" value) + (concat "@math{" + (string-trim (substring value 2 -2)) + "}")) + (t value)))))) + ;;;; Line Break =20 (defun org-texinfo-line-break (_line-break _contents _info) @@ -1948,6 +2014,24 @@ Return INFO file name or an error if it couldn't be = produced." (message "Process completed.") output)) =20 +(defun org-texinfo-supports-math-p () + "Return t if the installed version of Texinfo supports \"@math\"." + (let ((math-example "1 + 1 =3D 2")) + (let* ((input-file (make-temp-file "test" nil ".info")) + (input-content (concat (format "@setfilename %s" input-file) "\= n" + "@node Top" "\n" + (format "@math{%s}" math-example) "\n"))) + (with-temp-file input-file + (insert input-content)) + (let* ((output-file (org-texinfo-compile input-file)) + (output-content (with-temp-buffer + (insert-file-contents output-file) + (buffer-string)))) + (let ((result (string-match-p (regexp-quote math-example) + output-content))) + (delete-file input-file) + (delete-file output-file) + (if result t nil)))))) =20 (provide 'ox-texinfo) =20 diff --git a/testing/lisp/test-ox-texinfo.el b/testing/lisp/test-ox-texinfo= .el new file mode 100644 index 000000000..316b7cb1d --- /dev/null +++ b/testing/lisp/test-ox-texinfo.el @@ -0,0 +1,221 @@ +;;; test-ox-texinfo.el --- Tests for ox-texinfo.el + +;; Copyright (C) 2022 Rudolf Adamkovi=C4=8D + +;; Author: Rudolf Adamkovi=C4=8D + +;; This file is not part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Code: + +(require 'cl-lib) +(require 'ox-texinfo) + +(unless (featurep 'ox-texinfo) + (signal 'missing-test-dependency "org-export-texinfo")) + +(ert-deftest test-org-export-texinfo/latex-fragment () + "Test `org-texinfo-latex-fragment' output." + + ;; inline TeX fragment + (should + (equal "@math{a^2 =3D b}" + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + '(:value "$a^2 =3D b$")) + nil + '(:with-latex t)))) + + ;; inline TeX fragment, padded + (should + (equal "@math{a^2 =3D b}" + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + '(:value "$ a^2 =3D b $")) + nil + '(:with-latex t)))) + + ;; inline LaTeX fragment + (should + (equal "@math{a^2 =3D b}" + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + '(:value "\\(a^2 =3D b\\)")) + nil + '(:with-latex t)))) + + ;; inline LaTeX fragment, padded + (should + (equal "@math{a^2 =3D b}" + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + '(:value "\\( a^2 =3D b \\)")) + nil + '(:with-latex t)))) + + ;; displayed TeX fragment, inline + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 =3D b" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value "$$a ^ 2 =3D b$$")) + nil + '(:with-latex t)))) + + ;; displayed TeX fragment, inline, padded + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 =3D b" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value "$$ a ^ 2 =3D b $$")) + nil + '(:with-latex t)))) + + ;; displayed TeX fragment, multi-line + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 =3D b" + "b ^ 2 =3D c" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value + (string-join + (list "$$" + "a ^ 2 =3D b" + "b ^ 2 =3D c" + "$$") + "\n"))) + nil + '(:with-latex t)))) + + ;; displayed TeX fragment, multi-line, indented + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 =3D b" + "b ^ 2 =3D c" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value + (string-join + (list " $$" + " a ^ 2 =3D b" + " b ^ 2 =3D c" + " $$") + "\n"))) + nil + '(:with-latex t)))) + + ;; displayed LaTeX fragment, inline + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 =3D b" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value "\\[a ^ 2 =3D b\\]")) + nil + '(:with-latex t)))) + + ;; displayed LaTeX fragment, inline, padded + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 =3D b" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value "\\[ a ^ 2 =3D b \\]")) + nil + '(:with-latex t))))) + +(ert-deftest test-org-export-texinfo/latex-environment () + "Test `org-texinfo-latex-environment' output." + + ;; LaTeX environment + (should + (equal (string-join + (list "@displaymath" + "\\begin{equation}" + "a ^ 2 =3D b" + "b ^ 2 =3D c" + "\\end{equation}" + "@end displaymath") + "\n") + (org-texinfo-latex-environment + (org-element-create 'latex-environment + (list :value + (string-join + (list "\\begin{equation}" + "a ^ 2 =3D b" + "b ^ 2 =3D c" + "\\end{equation}") + "\n"))) + nil + '(:with-latex t)))) + + ;; LaTeX environment, indented + (should + (equal (string-join + (list "@displaymath" + "\\begin{equation}" + "a ^ 2 =3D b" + "b ^ 2 =3D c" + "\\end{equation}" + "@end displaymath") + "\n") + (org-texinfo-latex-environment + (org-element-create 'latex-environment + (list :value + (string-join + (list " \\begin{equation}" + " a ^ 2 =3D b" + " b ^ 2 =3D c" + " \\end{equation}") + "\n"))) + nil + '(:with-latex t))))) + +(provide 'test-ox-texinfo) +;;; test-ox-texinfo.el end here --=20 2.37.1 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable --=20 "Genius is 1% inspiration and 99% perspiration." -- Thomas Alva Edison, 1932 Rudolf Adamkovi=C4=8D [he/him] Studenohorsk=C3=A1 25 84103 Bratislava Slovakia --=-=-=--