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 6LKcMblAqmKlYAAAbAwnHQ (envelope-from ) for ; Wed, 15 Jun 2022 22:27:37 +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 AMGZMblAqmLX8QAA9RJhRA (envelope-from ) for ; Wed, 15 Jun 2022 22:27:37 +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 78F9410A0E for ; Wed, 15 Jun 2022 22:27:37 +0200 (CEST) Received: from localhost ([::1]:57998 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1Zc0-0007rH-LV for larch@yhetil.org; Wed, 15 Jun 2022 16:27:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52360) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1ZbH-0007qK-Fy for emacs-orgmode@gnu.org; Wed, 15 Jun 2022 16:26:51 -0400 Received: from pv50p00im-ztbu10021601.me.com ([17.58.6.57]:59188) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1ZbF-0005iS-3o for emacs-orgmode@gnu.org; Wed, 15 Jun 2022 16:26:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1655324806; bh=SQUXk76VsGjW+BC+scGamuXGHTeGlux1mam3FCy1jxg=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=a8uwZvVZb5bhYqrrXfqqX5O65/rehqm0Zt+jae4DQx6q2XVM2r+ftzDmvh6xr9UCy clOIFZouwSxZC8nU5TFoo5OTdFCTs8tx4v2leM+0axpvCTazzFJkuIHEurDDzRJx9V s5bvpxONzQ2ApXY/iFmzAKFrwdXDASutM/y1smqx+EDZeB1W6nXVSiM5BN7+ly52Hf bgOEBsHxHlGVhJIQxniW+0KOZ4xuFCBTRCVHNyZJNjqVhGfJOAFYmqwefRY4A5e52q LbgoiK8tJZ2ZZ5hxGG8LJhJu8kKgf2n34pCxeUINLzVqY5k82GouJhNUXWLkiJlHkT RP5Uq4EHeDxFA== Received: from Rudolfs-MacBook-Air.local (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-ztbu10021601.me.com (Postfix) with ESMTPSA id 61AE0803F4; Wed, 15 Jun 2022 20:26:42 +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: <87bkv75mgo.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> Date: Wed, 15 Jun 2022 22:26:39 +0200 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Proofpoint-ORIG-GUID: VJz1eiUCX9glLqy40xOu1O79zN9Csywi X-Proofpoint-GUID: VJz1eiUCX9glLqy40xOu1O79zN9Csywi X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.425,18.0.572,17.0.605.474.0000000_definitions?= =?UTF-8?Q?=3D2022-01-11=5F01:2022-01-11=5F01,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 mlxscore=0 clxscore=1015 spamscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2206150074 Received-SPF: pass client-ip=17.58.6.57; envelope-from=salutis@me.com; helo=pv50p00im-ztbu10021601.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=1655324857; 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=l4TiCkxKHEjglmbFbbfvj4FiCHz1uCWdicwwmD2yriI=; b=lEBsKPh7Qg3vWzqxO3iFMYhAhte+KFDrNg1zjbhZ/T2VB1tojgaMh0asoPws3ExBpzBLqX JEPwR3ymwcjPSYL4JpNuKQpFvS4jhVA1K9yOss4Ht2CRkD2Uq4MgcVMOIHpqQQ7YldoqjL duVo5MS1Nm0Peas5zcZjrvHb+vTPRsiaD10mw4mCyJOoGsFXzU9VAZoqxVqA3YCe2Di21i PhsQmED96Gsgc4AfrC6aR8ajjVtVaT6ItHkeMfubNsfI/uX9hTiEYTSEg9ZGL81bKAVMWj qRG9CBAElBIHRkIZeAuk8n2pDbg69Vp5BkWCzArMSwxGZwbEinWAS7VzHOfAfg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1655324857; a=rsa-sha256; cv=none; b=mC7yFHd/eVP4BRhp5YZ40g9aMBe6P4D0MDGtswhtRS4SDUDxN4tniSAOB10rFhdsl9UAc7 /qV5jpKcSorioKZdZ6iRre9m63Rfwas0zsT2jFhS/A7d2o7eK/P/a7MWKSvNlyuToY1lOR K4DcXYcNtVau8Sc/veaRLpxM+W6xpM5E8y/5lgb2MiAbmZBf84f9Xq7MBmDyJW22fS/nqP Kci6Y4oKD0OkXmdRpoRZbcfGYUex6n6xpW7wjJvZeK8t4ejXnud6x0xaOfwYb4pIGDRvKu FMpZH3VHWF1rS+jEK4zW3sTVI6ZuuRvYf5hmxvyqNq6nrnUZDtPJ/Xl+bqB+zw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=me.com header.s=1a1hai header.b=a8uwZvVZ; 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=a8uwZvVZ; 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: 78F9410A0E X-Spam-Score: 6.00 X-Migadu-Spam: Yes X-Migadu-Scanner: scn1.migadu.com X-TUID: xiJtXAQWjHI6 --=-=-= Content-Type: text/plain Ihor Radchenko writes: > Sounds reasonable in general. Ihor, thank you for guiding me through the process! > `org-export-with-latex' is a global setting. I do not think that > texinfo equivalent should be global. It should only be declared inside > ox-texinfo. That makes perfect sense. Please see the new patch attached to this message. What do you think? > As for the default value, it would be better if the option were set > depending on the installed Texinfo version. If the installed Texinfo > supports math, set it to t. Otherwise, nil. Of course, users will be > able to override the default as they wish. I looked at both ox-texinfo.el and texinfo.el, and I found no function or variable that would give the installed Texinfo version. Do we pull the version from "makeinfo --version" and then parse it? If so, does that functionality belong to Org (ox-texinfo.el) or Emacs (texinfo.el) instead? I also wonder how we could test it so that it will not break. I would appreciate any ideas and/or pointers from you. 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 776b85955181709f440e55be56f8ad9d4211f931 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-latex-environment): New function. * lisp/ox-texinfo.el (org-texinfo-latex-fragment): 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 (La)TeX mathematics, both inline and display style, in Texinfo exports. --- lisp/ox-texinfo.el | 57 +++++++- testing/lisp/test-ox-texinfo.el | 221 ++++++++++++++++++++++++++++++++ 2 files changed, 277 insertions(+), 1 deletion(-) create mode 100644 testing/lisp/test-ox-texinfo.el diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el index a01bb268c..d5bb75ce8 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,17 @@ The function should return the string to be exported." :group 'org-export-texinfo :type 'function) =20 +;;;; LaTeX + +(defcustom org-texinfo-with-latex org-export-with-latex + "Non-nil means process LaTeX math snippets. + +When set, the exporter will process LaTeX environments and +fragments, using Texinfo \"@displaymath\" and \"@math\" commands, +respectively." + :group 'org-export-texinfo + :type 'boolean) + ;;;; Itemx =20 (defcustom org-texinfo-compact-itemx nil @@ -1212,6 +1227,46 @@ 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." + (when (plist-get info :with-latex) + (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." + (when (plist-get info :with-latex) + (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) 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.36.1 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable --=20 "Mathematics takes us still further from what is human into the region of absolute necessity, to which not only the actual world, but every possible world, must conform." -- Bertrand Russell, 1902 Rudolf Adamkovi=C4=8D [he/him] Studenohorsk=C3=A1 25 84103 Bratislava Slovakia --=-=-=--