Re: [PATCH] Re: No mathematics in Texinfo exports

2022-09-21 Thread Rudolf Adamkovič
Ihor Radchenko  writes:

> Applied onto main with minor amendments.

Amazing!  Thank you so much for guiding me through.

Rudy
-- 
"It is no paradox to say that in our most theoretical moods we may be
nearest to our most practical applications."
-- Alfred North Whitehead, 1861-1947

Rudolf Adamkovič  [he/him]
Studenohorská 25
84103 Bratislava
Slovakia



Re: [PATCH] Re: No mathematics in Texinfo exports

2022-09-21 Thread Ihor Radchenko
Rudolf Adamkovič  writes:

> Please see the attached patch where I attempt to fix every issue you
> pointed out.  I also split the tests into smaller functions for better
> maintainability.  Please, let me know what you think about my latest
> attempt.  Thank you for your guidance!

Applied onto main with minor amendments.
Thanks for your contribution!
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=c940b460c7bb31e98089286a5a45306cc27034cc

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92



Re: [PATCH] Re: No mathematics in Texinfo exports

2022-08-18 Thread Ihor Radchenko
Rudolf Adamkovič  writes:

>> 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

I did not mean that the behaviour should necessarily be different. In any
case, you cannot really distinguish this easily. The difference between
info and texinfo exports is simply in the arguments to
org-export-to-file. When exporting to info, the normal texinfo export is
post-processed using org-texinfo-compile. See org-texinfo-export-to-info
and org-texinfo-export-to-texinfo.

>> 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.

'detect is OK.

> --- a/etc/ORG-NEWS
> +++ b/etc/ORG-NEWS
> @@ -270,6 +270,7 @@ example,
>  
>  prints a sub-bibliography containing the book entries with =ai= among
>  their keywords.
> +*** Support for LaTeX mathematics in Texinfo exports

Please provide a bit mode info here. At least, mention the new
customization and its default value.

> +(defcustom org-texinfo-with-latex (and org-export-with-latex 'auto)

I guess that you meant (and org-export-with-latex 'detect).

> +  "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

'detect will trigger unescaped quote warning in Emacs 29. Use `detect'.

> +(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."

> +(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."

Please Use a single sentence at the first line of the docstring.
"CONTENTS is nil" is misleading. If you want to mention CONTENTS
argument at all, just say that it is ignored.

> +(defun org-texinfo-supports-math-p ()
> +  "Return t if the installed version of Texinfo supports \"@math\"."

This function may be called frequently. Its value should better be
cached. We really only need to calculate it once per Emacs session and
store in some variable.

> +  ;; inline TeX fragment

Please use full sentences in comments. Start sentences with capitalized
words and end with ".".

> +  (should
> +   (equal "@math{a^2 = b}"
> +  (org-texinfo-latex-fragment
> +   (org-element-create 'latex-fragment
> +   '(:value "$a^2 = b$"))
> +   nil
> +   '(:with-latex t

Please note that the test results may depend on the installed texinfo
version. Please guard the tests with (let ((org-texinfo-with-latex t)) ...)

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92



Re: [PATCH] Re: No mathematics in Texinfo exports

2022-06-24 Thread Ihor Radchenko
Rudolf Adamkovič  writes:

> After thinking about this for a while, I realized I do not know when I
> will have the time to implement the proposed improvements.  So I wonder,
> should we merge what we have, with the feature disabled by default using
> the existing customization variable?  That way, some people can enable
> the feature today.

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).

Best,
Ihor



Re: [PATCH] Re: No mathematics in Texinfo exports

2022-06-24 Thread Rudolf Adamkovič
Ihor Radchenko  writes:

> 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.
>
> This customization might be set to 'auto by default, making ox-texinfo
> check makeinfo version.
>
> 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.

After thinking about this for a while, I realized I do not know when I
will have the time to implement the proposed improvements.  So I wonder,
should we merge what we have, with the feature disabled by default using
the existing customization variable?  That way, some people can enable
the feature today.

Rudy
-- 
"It is no paradox to say that in our most theoretical moods we may be
nearest to our most practical applications."
-- Alfred North Whitehead, 1861-1947

Rudolf Adamkovič  [he/him]
Studenohorská 25
84103 Bratislava
Slovakia



Re: [PATCH] Re: No mathematics in Texinfo exports

2022-06-19 Thread Ihor Radchenko
Rudolf Adamkovič  writes:

>> `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?

> -(: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)))

Looks reasonable.  

>> 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.

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.

This customization might be set to 'auto by default, making ox-texinfo
check makeinfo version.

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.

Best,
Ihor



Re: [PATCH] Re: No mathematics in Texinfo exports

2022-06-05 Thread Ihor Radchenko
Rudolf Adamkovič  writes:

> Ihor Radchenko  writes:
>
>> We are back to the previous comments on the patch itself. You need to
>> address the problem with older versions of texinfo. What will happen
>> if one tries to open a document generated with your patch using old
>> texinfo version? Will it render correctly?
>
> I compiled Texinfo 6.7, tried it, and it indeed trips over math.  So, do
> we declare a new Texinfo-specific "include math" variable that defaults
> to nil?  I ask because we already have 'org-export-with-latex' which,
> when set to nil, results in math-less exports.  The new variable would
> have the same effect, but just for Texinfo exports.  Does that raise any
> red flags?  Do you have any other thoughts?  Thank you!

Sounds reasonable in general.

`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.

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.

Best,
Ihor



Re: [PATCH] Re: No mathematics in Texinfo exports

2022-06-05 Thread Rudolf Adamkovič
Ihor Radchenko  writes:

> We are back to the previous comments on the patch itself. You need to
> address the problem with older versions of texinfo. What will happen
> if one tries to open a document generated with your patch using old
> texinfo version? Will it render correctly?

I compiled Texinfo 6.7, tried it, and it indeed trips over math.  So, do
we declare a new Texinfo-specific "include math" variable that defaults
to nil?  I ask because we already have 'org-export-with-latex' which,
when set to nil, results in math-less exports.  The new variable would
have the same effect, but just for Texinfo exports.  Does that raise any
red flags?  Do you have any other thoughts?  Thank you!

Rudy
-- 
"It is no paradox to say that in our most theoretical moods we may be
nearest to our most practical applications."
-- Alfred North Whitehead, 1861-1947

Rudolf Adamkovič  [he/him]
Studenohorská 25
84103 Bratislava
Slovakia



Re: [PATCH] Re: No mathematics in Texinfo exports

2022-05-27 Thread Ihor Radchenko
Rudolf Adamkovič  writes:

> Ihor Radchenko  writes:
>
>> Do not wait one month. Just 5 working days. Then, do not hesitate to
>> follow up.
>
> And ... done!  So, what happens next?

We are back to the previous comments on the patch itself. You need to
address the problem with older versions of texinfo. What will happen if
one tries to open a document generated with your patch using old texinfo
version? Will it render correctly?

Best,
Ihor



Re: [PATCH] Re: No mathematics in Texinfo exports

2022-05-27 Thread Rudolf Adamkovič
Ihor Radchenko  writes:

> Do not wait one month. Just 5 working days. Then, do not hesitate to
> follow up.

And ... done!  So, what happens next?

Rudy
-- 
"The whole science is nothing more than a refinement of everyday
thinking."
-- Albert Einstein, 1879-1955

Rudolf Adamkovič  [he/him]
Studenohorská 25
84103 Bratislava
Slovakia



Re: [PATCH] Re: No mathematics in Texinfo exports

2022-05-23 Thread Ihor Radchenko
Rudolf Adamkovič  writes:

> FYI, I did receive a reply after the follow-up mail.  I signed the papers and
> sent them back to FSF just now.  I will revive the thread once FSF does its
> part.  Hopefully, I will not wait for yet another (third) month. :)

Do not wait one month. Just 5 working days. Then, do not hesitate to
follow up.

Best,
Ihor



Re: [PATCH] Re: No mathematics in Texinfo exports

2022-05-23 Thread Rudolf Adamkovič
Rudolf Adamkovič  writes:

> Ihor Radchenko  writes:
>
>> Sorry for this delay. Then, can you send them a followup email reminder?
>> If they do not reply within another week, we will contact FSF directly.
>
> Thank you.  I sent a followup email just now, FYI.

FYI, I did receive a reply after the follow-up mail.  I signed the papers and
sent them back to FSF just now.  I will revive the thread once FSF does its
part.  Hopefully, I will not wait for yet another (third) month. :)

Rudy
-- 
"Programming reliably -- must be an activity of an undeniably
mathematical nature […] You see, mathematics is about thinking, and
doing mathematics is always trying to think as well as possible."
-- Edsger W. Dijkstra, 1981

Rudolf Adamkovič  [he/him]
Studenohorská 25
84103 Bratislava
Slovakia



Re: [PATCH] Re: No mathematics in Texinfo exports

2022-05-20 Thread Rudolf Adamkovič
Ihor Radchenko  writes:

> Sorry for this delay. Then, can you send them a followup email reminder?
> If they do not reply within another week, we will contact FSF directly.

Thank you.  I sent a followup email just now, FYI.

Rudy
-- 
"Logic is a science of the necessary laws of thought, without which no
employment of the understanding and the reason takes place."
-- Immanuel Kant, 1785

Rudolf Adamkovič  [he/him]
Studenohorská 25
84103 Bratislava
Slovakia



Re: [PATCH] Re: No mathematics in Texinfo exports

2022-05-15 Thread Ihor Radchenko
Rudolf Adamkovič  writes:

> Ihor Radchenko  writes:
>
>> Rudolf Adamkovič, feel free to ask questions if you find the copyright
>> assignment instructions unclear.
>
> I think I need help with the copyright assignment. On April 23, I sent a
> request to ass...@gnu.org, and I have yet to receive a reply as of May 15.

Sorry for this delay. Then, can you send them a followup email reminder?
If they do not reply within another week, we will contact FSF directly.

Best,
Ihor

P.S. The precise procedure is the following as in
https://www.gnu.org/prep/maintain/maintain.html

>>> When the contributor emails the form to the FSF, the FSF sends per
>>> an electronic (usually PDF) copy of the assignment. This, or
>>> whatever response is required, should happen within five business
>>> days of the initial request. If no reply from the FSF comes after
>>> that time, please send a reminder. If there is still no response
>>> after an additional week, please write to maintain...@gnu.org about
>>> it.
(the last thing is what I (or other Org maintainers) need to do).




Re: [PATCH] Re: No mathematics in Texinfo exports

2022-05-15 Thread Rudolf Adamkovič
Ihor Radchenko  writes:

> Rudolf Adamkovič, feel free to ask questions if you find the copyright
> assignment instructions unclear.

I think I need help with the copyright assignment. On April 23, I sent a
request to ass...@gnu.org, and I have yet to receive a reply as of May 15.

Rudy
-- 
"Genius is 1% inspiration and 99% perspiration."
-- Thomas Alva Edison, 1932

Rudolf Adamkovič  [he/him]
Studenohorská 25
84103 Bratislava
Slovakia



Re: [PATCH] Re: No mathematics in Texinfo exports

2022-04-21 Thread Ihor Radchenko
Nicolas Goaziou  writes:

>>> My Texinfo 6.7 manual does not contain any reference to displaymath
>>> environment, which is used throughout the patch. Where is it coming
>>> from?
>>
>> I do see @displaymath in my TeXinfo 6.8. Also,
>> https://www.gnu.org/software/texinfo/manual/texinfo/html_node/Inserting-Math.html
>
> So it is a fairly recent addition, since Texinfo 6.8 was released last
> July. For example, it is not available in Debian stable. I don't know if
> displaymath was stealthily supported before.

I see. Compatibility may indeed be an issue. However, I still believe
that the feature may be useful for users aiming for newer TeXinfo.
Maybe, this feature can be disabled by default unless the user
explicitly customize some variable.

> Anyway, AFAIU, we need FSF papers from Rudolf Adamkovič before
> processing.

Yeah. The patch is certainly over 15LOC.

Rudolf Adamkovič, feel free to ask questions if you find the copyright
assignment instructions unclear.

Best,
Ihor



Re: [PATCH] Re: No mathematics in Texinfo exports

2022-04-21 Thread Nicolas Goaziou
Ihor Radchenko  writes:

> Nicolas Goaziou  writes:
>
>>> Rudolf Adamkovič  writes:
>>>
>>> The idea sounds good and having tests is very good. Though I am not
>>> expert in texinfo. CC-ing Nicolas. He is the maintainer.
>>
>> My Texinfo 6.7 manual does not contain any reference to displaymath
>> environment, which is used throughout the patch. Where is it coming
>> from?
>
> I do see @displaymath in my TeXinfo 6.8. Also,
> https://www.gnu.org/software/texinfo/manual/texinfo/html_node/Inserting-Math.html

So it is a fairly recent addition, since Texinfo 6.8 was released last
July. For example, it is not available in Debian stable. I don't know if
displaymath was stealthily supported before.

Anyway, AFAIU, we need FSF papers from Rudolf Adamkovič before
processing.

Regards,



Re: [PATCH] Re: No mathematics in Texinfo exports

2022-04-21 Thread Ihor Radchenko
Nicolas Goaziou  writes:

>> Rudolf Adamkovič  writes:
>>
>> The idea sounds good and having tests is very good. Though I am not
>> expert in texinfo. CC-ing Nicolas. He is the maintainer.
>
> My Texinfo 6.7 manual does not contain any reference to displaymath
> environment, which is used throughout the patch. Where is it coming
> from?

I do see @displaymath in my TeXinfo 6.8. Also,
https://www.gnu.org/software/texinfo/manual/texinfo/html_node/Inserting-Math.html

>> Why don't we just have an extra element property with the bracket info
>> in the output of org-element-latex-fragment-parser?
>
> Because we didn't need it so far, as Org doesn't make a difference
> between the different markers.

Fair point. I somehow assumed that knowing about latex fragment type is
commonly needed in exporters. Grepping through the code revealed that it
is not the case.

Best,
Ihor



Re: [PATCH] Re: No mathematics in Texinfo exports

2022-04-21 Thread Nicolas Goaziou
Hello,

Ihor Radchenko  writes:

> Rudolf Adamkovič  writes:
>
> The idea sounds good and having tests is very good. Though I am not
> expert in texinfo. CC-ing Nicolas. He is the maintainer.

My Texinfo 6.7 manual does not contain any reference to displaymath
environment, which is used throughout the patch. Where is it coming
from?

> A more general comment is rather about our org-element.el (maybe Nicolas
> can answer)
>
>> +  (cond
>> +   ((or (string-match-p "^\\[" value)
>> +(string-match-p "^\\$\\$" value))
>> ...
>> +   ((string-match-p "^\\$" value)
>> ...
>> +   ((string-match-p "^(" value)
>
> Why don't we just have an extra element property with the bracket info
> in the output of org-element-latex-fragment-parser?

Because we didn't need it so far, as Org doesn't make a difference
between the different markers.

Regards,
-- 
Nicolas Goaziou



Re: [PATCH] Re: No mathematics in Texinfo exports

2022-04-21 Thread Ihor Radchenko
Rudolf Adamkovič  writes:

> My patch (from almost a month ago) has yet to appear at
>
> https://updates.orgmode.org

This is strange. Marking the patch manually.
In any case, thanks for your contribution and patience.

> Any ideas what to do?  Could someone review it?

The idea sounds good and having tests is very good. Though I am not
expert in texinfo. CC-ing Nicolas. He is the maintainer.

A more general comment is rather about our org-element.el (maybe Nicolas
can answer)

> +  (cond
> +   ((or (string-match-p "^\\[" value)
> +(string-match-p "^\\$\\$" value))
> ...
> +   ((string-match-p "^\\$" value)
> ...
> +   ((string-match-p "^(" value)

Why don't we just have an extra element property with the bracket info
in the output of org-element-latex-fragment-parser?

> Please note that I have never contributed patches via mail, and I have
> never signed any FSF papers. I would appreciate your guidance.

See https://orgmode.org/worg/org-contribute.html#copyright

Best,
Ihor




Re: [PATCH] Re: No mathematics in Texinfo exports

2022-04-20 Thread Rudolf Adamkovič
Hello everyone,

My patch (from almost a month ago) has yet to appear at

https://updates.orgmode.org

Any ideas what to do?  Could someone review it?

Thank you!

Rudy

+++ The original message below. +++

Rudolf Adamkovič  writes:

> Rudolf Adamkovič  writes:
>
>> […], or do I have to tackle the problem myself?  I would appreciate
>> 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!
>
> From 5fe65432c1a6440c86d0bbc0b66a6603e5a8f100 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= 
> 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
>  
> + 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
>  
>  (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 0..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č
> +
> +;; Author: Rudolf Adamkovič 
> +
> +;; 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 

[PATCH] Re: No mathematics in Texinfo exports

2022-03-26 Thread Rudolf Adamkovič
Rudolf Adamkovič  writes:

> […], or do I have to tackle the problem myself?  I would appreciate
> 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!

>From 5fe65432c1a6440c86d0bbc0b66a6603e5a8f100 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= 
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
 
+ 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
 
 (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 0..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č
+
+;; Author: Rudolf Adamkovič 
+
+;; 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 = b}"
+  (org-texinfo-latex-fragment
+   (org-element-create 'latex-fragment
+   '(:value "$a^2 = b$"))
+   nil
+   '(:with-latex t
+
+  ;; inline TeX fragment, padded
+  (should
+   (equal "@math{a^2 = b}"
+