Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-02-24 Thread Martin Edström
Ah yes. My custom Node script (which I hope it's OK to paste below) strips
the beginnings and ends of the input. I suppose that it could be done
already on the Elisp side, which would take care of interpreting the
$-signs as envvars too.

const katex = require('katex')
let input = process.argv[2].trim()
let disp = true
if (input.slice(0, 2) === '\\[' || input.slice(0, 2) === '$$') {
  input = input.slice(2, -2)
}
else if (input.slice(0, 2) === '\\(') {
  input = input.slice(2, -2)
  disp = false
}
else if (input.slice(0, 1) === '$') {
  input = input.slice(1, -1)
  disp = false
}
else {
  console.error("Did you quote the input correctly?")
  process.exit(1)
}
console.log(katex.renderToString(
  input, {
displayMode: disp,
output: 'mathml',
trust: true,
strict: false,
throwOnError: false,
  }
))

On Wed, Feb 21, 2024 at 15:38 Max Nikulin  wrote:

> On 19/02/2024 02:36, Martin Edström wrote:
> > +Since this is a shell-command, remember to use single-quotes
> > +around \\='%i\\=', not double-quotes!  Else a math fragment such
> > +as \"$y = 200$\" gets butchered into only \" = 200\"."
>
> I am afraid, the code, not the docstring must be fixed. I have not tried
> it, but I expect an issue with
>
>  Test \(f' = df/dx\)
>
> So `shell-quote-argument' is necessary and quotes around %i must be
> stripped similar to %s in mailcap entries in `org-open-file'.
>
> Notice that dollar-math $x = y$ is not recommended and considered as
> obsolete syntax. Use \(x = y\) or \[x = y\] (the latter for display math).
>


Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-02-24 Thread Martin Edström
And ignore my suggestion about stripping input on the Elisp side.
Didn't think that through.

On Wed, 21 Feb 2024 at 16:04, Martin Edström  wrote:
>
> Actually, I agree about your test case, that looks like it'd cause a problem.
>
> So we patch the function to use `shell-quote-argument'?
>
> On Wed, 21 Feb 2024 at 15:38, Max Nikulin  wrote:
> >
> > On 19/02/2024 02:36, Martin Edström wrote:
> > > +Since this is a shell-command, remember to use single-quotes
> > > +around \\='%i\\=', not double-quotes!  Else a math fragment such
> > > +as \"$y = 200$\" gets butchered into only \" = 200\"."
> >
> > I am afraid, the code, not the docstring must be fixed. I have not tried
> > it, but I expect an issue with
> >
> >  Test \(f' = df/dx\)
> >
> > So `shell-quote-argument' is necessary and quotes around %i must be
> > stripped similar to %s in mailcap entries in `org-open-file'.
> >
> > Notice that dollar-math $x = y$ is not recommended and considered as
> > obsolete syntax. Use \(x = y\) or \[x = y\] (the latter for display math).



Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-02-24 Thread Martin Edström
Actually, I agree about your test case, that looks like it'd cause a problem.

So we patch the function to use `shell-quote-argument'?

On Wed, 21 Feb 2024 at 15:38, Max Nikulin  wrote:
>
> On 19/02/2024 02:36, Martin Edström wrote:
> > +Since this is a shell-command, remember to use single-quotes
> > +around \\='%i\\=', not double-quotes!  Else a math fragment such
> > +as \"$y = 200$\" gets butchered into only \" = 200\"."
>
> I am afraid, the code, not the docstring must be fixed. I have not tried
> it, but I expect an issue with
>
>  Test \(f' = df/dx\)
>
> So `shell-quote-argument' is necessary and quotes around %i must be
> stripped similar to %s in mailcap entries in `org-open-file'.
>
> Notice that dollar-math $x = y$ is not recommended and considered as
> obsolete syntax. Use \(x = y\) or \[x = y\] (the latter for display math).



Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-02-18 Thread Martin Edström
Here you go!

Tests passed (14 SKIPPED), compiled fine.  I've made no prior
contributions and this changes 5 lines. I'm ok if you want to rephrase
it in any way.

Martin

On Sun, 18 Feb 2024 at 19:56, Martin Edström  wrote:
>
> I will try to do a patch, thanks for the link. Stay tuned.
>
> On Sun, Feb 18, 2024 at 15:06 Ihor Radchenko  wrote:
>>
>> Martin Edström  writes:
>>
>> > I've just been struggling with my custom setting for
>> > `org-latex-to-html-convert-command` outputting many math snippets
>> > wrong. The fault was mine: I didn't correctly shell-quote the input.
>> > I propose to add a warning in the docstring, because many people will
>> > trip the same problem.
>>
>> > The thing is that double-quotes don't work in shell commands.  I had
>> > \"%i\", but it should've been '%i':
>>
>> Would you be interested to submit a patch?
>> See https://orgmode.org/worg/org-contribute.html#first-patch
>>
>> --
>> Ihor Radchenko // yantar92,
>> 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>
From d3b1b0a3cc4deac7ac47f446fb0bf27f61169ac4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Edstr=C3=B6m?= 
Date: Sun, 18 Feb 2024 20:29:48 +0100
Subject: [PATCH] lisp/org.el: Enhance a docstring

* org.el (org-latex-to-html-convert-command): Add a note in the
docstring about proper shell-quoting.

It can trip you up because wrongly quoted input still works with some
math snippets, so the command may work during testing but not later
when you have different math snippets in play.

TINYCHANGE
---
 lisp/org.el | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lisp/org.el b/lisp/org.el
index 947037559..6b2ebf9ac 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -3275,7 +3275,11 @@ Replace format-specifiers in the command as noted below and use
 %i: The LaTeX fragment to be converted.
 
 For example, this could be used with LaTeXML as
-\"latexmlc \\='literal:%i\\=' --profile=math --preload=siunitx.sty 2>/dev/null\"."
+\"latexmlc \\='literal:%i\\=' --profile=math --preload=siunitx.sty 2>/dev/null\".
+
+Since this is a shell-command, remember to use single-quotes
+around \\='%i\\=', not double-quotes!  Else a math fragment such
+as \"$y = 200$\" gets butchered into only \" = 200\"."
   :group 'org-latex
   :package-version '(Org . "9.4")
   :type '(choice
-- 
2.40.1



Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-02-18 Thread Martin Edström
I will try to do a patch, thanks for the link. Stay tuned.

On Sun, Feb 18, 2024 at 15:06 Ihor Radchenko  wrote:

> Martin Edström  writes:
>
> > I've just been struggling with my custom setting for
> > `org-latex-to-html-convert-command` outputting many math snippets
> > wrong. The fault was mine: I didn't correctly shell-quote the input.
> > I propose to add a warning in the docstring, because many people will
> > trip the same problem.
>
> > The thing is that double-quotes don't work in shell commands.  I had
> > \"%i\", but it should've been '%i':
>
> Would you be interested to submit a patch?
> See https://orgmode.org/worg/org-contribute.html#first-patch
>
> --
> Ihor Radchenko // yantar92,
> 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>
>


Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-02-16 Thread Martin Edström
I've just been struggling with my custom setting for
`org-latex-to-html-convert-command` outputting many math snippets
wrong. The fault was mine: I didn't correctly shell-quote the input.
I propose to add a warning in the docstring, because many people will
trip the same problem.

The thing is that double-quotes don't work in shell commands.  I had
\"%i\", but it should've been '%i':

(setopt org-latex-to-html-convert-command "node
/home/kept/pub/texToMathML.js \"%i\"")

Math snippets that start with $, like $y = 200$ of course get
butchered into just " = 200$" because of course the first $y gets
interpreted as a shell environment variable.