emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Ihor Radchenko
Subject: Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command
Date: Mon, 26 Feb 2024 10:48:17 +0000

Max Nikulin <manikulin@gmail.com> writes:

> (let ((org-latex-to-html-convert-command
>         "printf '%%s' '%i'"))
>    (org-format-latex-as-html "$f' = df/dx$"))
> "/bin/bash: -c: line 1: unexpected EOF while looking for matching `''
> "
>
> Something weird may be executed in the case of sufficiently complex 
> equations.

> It should be more reliable to pass fragment to command stdin. It can be 
> done if %i is missed in `org-latex-to-html-convert-command'.

I agree that it will be more reliable to shell-escape argument.
However, I am concerned that escaping may break certain uses like

somecommand << EOF
%i
EOF

In the above scenario, escaping will break things.

That's why I prefer to add a new replacement, not change the meaning of
%i. We might even remove %i from the docstring, keeping support in the
code for backwards-compatibility.

Also, I just looked closer into the example with latexml we provide in
the docstring and played around with it.

I noticed that

with

(defun org-format-latex-as-html (latex-fragment)
  "Convert LATEX-FRAGMENT to HTML.
This uses  `org-latex-to-html-convert-command', which see."
  (let ((cmd (format-spec org-latex-to-html-convert-command
                          `((?i . ,latex-fragment)
                            (?I . ,(shell-quote-argument latex-fragment))))))
    (message "Running %s" cmd)
    (shell-command-to-string cmd)))

(with-temp-file "/tmp/test2.html"
(let ((org-latex-to-html-convert-command
              "latexmlc literal:%I --profile=math --preload=siunitx.sty 
2>/dev/null"))
         (insert (org-format-latex-as-html "$f' = df/dx$"))))

test2.html is rendered *incorrectly* as in the attached screenshot.

In contrast, manually providing output file as

latexmlc literal:\$f\'\ =\ df/dx\$ --profile=math --preload=siunitx.sty 
--output /tmp/test3.html

yields correct rendering.

Attachment: incorrect-rendering.png
Description: PNG image

Attachment: correct-rendering.png
Description: PNG image

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]