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 ms0.migadu.com with LMTPS id 8OV1J6M6P2JIhwAAgWs5BA (envelope-from ) for ; Sat, 26 Mar 2022 17:09:07 +0100 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 gH6+JKM6P2JaGwAA9RJhRA (envelope-from ) for ; Sat, 26 Mar 2022 17:09:07 +0100 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 E63972C2E4 for ; Sat, 26 Mar 2022 17:09:06 +0100 (CET) Received: from localhost ([::1]:47068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nY8yQ-0000Yn-22 for larch@yhetil.org; Sat, 26 Mar 2022 12:09:06 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55264) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nY8xL-0000Yb-D2 for emacs-orgmode@gnu.org; Sat, 26 Mar 2022 12:08:00 -0400 Received: from pv50p00im-hyfv10011601.me.com ([17.58.6.43]:60564) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nY8xJ-0003NI-9X for emacs-orgmode@gnu.org; Sat, 26 Mar 2022 12:07:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1648310871; bh=e5FC+qVC20IbZc2tMJ936mD9tUk+rhlGKN4j7yhAzlA=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=EiNpdcTq5ulK3zoVEK5+uzNvhj/gYlXn5hmWeDD9AyqGZByIWx2C1ClPYAW4rjgX/ poFSqUyBcrvOgaflL4s7IU70gPLRDTTTDBKIrjYZ7chjg5ns9Wa9f2QSF7Qo708Lc7 KXS+1TwsG6NtPDhk2eevABi4g0Yv7EsB60qwYmbt/T2ZQha5ulZdqgI8lVDcI+/gJ6 5woLCREu+f84QoehebqZXrA91Ixr2MZO1DEgQyOsHaC8O8PfhE/C5vOVL4WKsF9I0O Y9eKCxrzn/1J3hfHPa2BU8avAaM2igW4KWalPTKLYUwIGK5H+GEZiV6HkxwtNVEIuR UZSTAhA4dB+2Q== Received: from Workstation.local (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-hyfv10011601.me.com (Postfix) with ESMTPSA id A4B6A9602E6; Sat, 26 Mar 2022 16:07:49 +0000 (UTC) From: Rudolf =?utf-8?Q?Adamkovi=C4=8D?= To: emacs-orgmode@gnu.org Cc: mail@nicolasgoaziou.fr Subject: [PATCH] Re: No mathematics in Texinfo exports In-Reply-To: References: Date: Sat, 26 Mar 2022 17:07:45 +0100 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425, 18.0.850 definitions=2022-03-26_06:2022-03-24, 2022-03-26 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 mlxscore=0 mlxlogscore=885 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-2009150000 definitions=main-2203260105 Received-SPF: pass client-ip=17.58.6.43; envelope-from=salutis@me.com; helo=pv50p00im-hyfv10011601.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, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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=1648310947; 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=e5FC+qVC20IbZc2tMJ936mD9tUk+rhlGKN4j7yhAzlA=; b=vB/5wQOOV9o1Hu63KiSga9jtPHL7fOHnrFmZk5W2g2CGmVF2LNoHoNTHluGEvP+1lsh/si R+tea41ywXw4i2aWU12mwl7N1qMCN9vQzAUREmnXOgTgUH2bHLngoMZdaM/p1ttXM1h/m+ kq9ZcKxhsfoGnKGb73O5qzndqNtXFr7YfbGLIvdVqT9Q5gmdGVFhiLaxoTre3FG2YN3EZ2 Y3xN6lUQouKedSMsZU34vrWuiwSMUmeQiKuhsyTyfptPpjppWh4SGBcnM5+7MbS5IScD3f JjGxTbngdukaT+fX05dou4W0CU2QtftjH1vGONxjuedAacBXDh9nrJw+tq91Yw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1648310947; a=rsa-sha256; cv=none; b=EnZfeYBPW/k1bDhkNsQ0Nu1jl+BGYS3VEodKkGnFZKDDAMGPVK/UZ52A7Z4L7cCVUajs75 ZJ7EvqueB3sCrzP6UhdsJ1T4LWVm7kOnVI1WSNzWx4lK4/fo2zIOEh1u3nbcjxYwR74+2e ZrNjB/jEM6LOn1QVi+7fhRRdMNlV8UgEvbY8h2pAbCwZbCqvNkcbsjsL+BiLa9Vd895R0h M+q9ORbZSgb7sdrOIj28FidxXPLOZP20++PthyGRRnYP5KAeH7ZPTVa8ethPQtxeRttZyn GTJ9qfESW6ivb3x/AW1VSsb9UINc4eCq9aXLKdJTeZGHewj2vV4oJrnIr94C2A== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=me.com header.s=1a1hai header.b=EiNpdcTq; dmarc=pass (policy=quarantine) header.from=me.com; 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.98 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=me.com header.s=1a1hai header.b=EiNpdcTq; dmarc=pass (policy=quarantine) header.from=me.com; 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: E63972C2E4 X-Spam-Score: -5.98 X-Migadu-Scanner: scn0.migadu.com X-TUID: OU47zGhteDWf --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Rudolf Adamkovi=C4=8D writes: > [=E2=80=A6], or do I have to tackle the problem myself? I would apprecia= te > any tips. I pulled up my sleeves and added the functionality myself. See the attached patch. Please note that I have never contributed patches via mail, and I have never signed any FSF papers. I would appreciate your guidance. Thank you! --=-=-= 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 Content-Description: A patch adding LaTeX to Texinfo exports >From 5fe65432c1a6440c86d0bbc0b66a6603e5a8f100 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 | 42 ++++++ testing/lisp/test-ox-texinfo.el | 221 ++++++++++++++++++++++++++++++++ 2 files changed, 263 insertions(+) create mode 100644 testing/lisp/test-ox-texinfo.el diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el index a01bb268c..0bfd06550 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) @@ -1212,6 +1214,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.35.1 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Rudy --=20 "'Contrariwise,' continued Tweedledee, 'if it was so, it might be; and if it were so, it would be; but as it isn't, it ain't. That's logic.'" -- Lewis Carroll, Through the Looking Glass, 1871/1872 Rudolf Adamkovi=C4=8D [he/him] Studenohorsk=C3=A1 25 84103 Bratislava Slovakia --=-=-=--