emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Problems with LaTeX export for $x\text{foo $x$}$-like construts?
@ 2022-12-28 13:57 Alain.Cochard
  2022-12-29 10:04 ` Ihor Radchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Alain.Cochard @ 2022-12-28 13:57 UTC (permalink / raw)
  To: emacs-orgmode


Version used: release_9.6-149-g554935 

With an org file containing only

   #+begin_export latex
   $x \text{foo $y$}$

   \(x \text{foo \(y\)}\)

   $x \text{foo \(y\)}$

   \(x \text{foo $y$}\)
   #+end_export

the pdf generated upon latex export gives as expected, i.e., with 'x'
and 'y' in mathematical font.

Maybe this is fully normal, but I find it annoying: when the 4 lines
above are not within a latex block, only the last 2 (that is, with
mixed "$...$" and "\(...\)" constructs), are shown correctly on the
resulting pdf.

The 1st one shows, on the pdf

   $x foo y$
   
(with 'y' in mathematical font).

The 2nd one (if alone in the org file) gives

   File "/home/cochard/Org/debug.pdf" wasn’t produced.  See "*Org PDF
   LaTeX Output*" for details


PS/incidentally: if one adds a blank line and another line to that 2nd
one, i.e., if the org file contains something like

   \(x \text{foo \(y\)}\)

   foo

then a pdf is generated, which shows

   x
   foo

The *Messages* buffer contains

   PDF file produced with errors.
   Running /usr/bin/xdg-open /home/cochard/Org/debug.pdf...done

but only the last of those lines is seen in the minibuffer.  So this
adds another example to those discussed in thread
https://list.orgmode.org/25477.57044.35186.766042@gargle.gargle.HOWL/
where one (at least I) would like to more permanently see "PDF file
produced with errors."


-- 
EOST (École et Observatoire des Sciences de la Terre) 
ITE (Institut Terre & Environnement) | alain.cochard@unistra.fr
5 rue René Descartes   [bureau 110]  | Phone: +33 (0)3 68 85 50 44 
F-67084 Strasbourg Cedex, France     | [ slot available for rent ]



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Problems with LaTeX export for $x\text{foo $x$}$-like construts?
  2022-12-28 13:57 Problems with LaTeX export for $x\text{foo $x$}$-like construts? Alain.Cochard
@ 2022-12-29 10:04 ` Ihor Radchenko
  2022-12-29 10:39   ` Alain.Cochard
  2022-12-29 11:52   ` Ihor Radchenko
  0 siblings, 2 replies; 5+ messages in thread
From: Ihor Radchenko @ 2022-12-29 10:04 UTC (permalink / raw)
  To: alain.cochard; +Cc: emacs-orgmode

Alain.Cochard@unistra.fr writes:

> Version used: release_9.6-149-g554935 
>
> With an org file containing only
>
>    #+begin_export latex
>    $x \text{foo $y$}$
>
>    \(x \text{foo \(y\)}\)
>
>    $x \text{foo \(y\)}$
>
>    \(x \text{foo $y$}\)
>    #+end_export
>
> the pdf generated upon latex export gives as expected, i.e., with 'x'
> and 'y' in mathematical font.

This is to be expected because of how Org parser works.

In particular, $-style math is tricky because Org allows "$" both as
math delimiter and also as standalone symbol. There are trade-offs.

For the \(...\), it is because Org parser does not understand nesting:
it takes first opening \( and match it with the first closing \) - thus
what you observe.

Unfortunately, I do not see an easy solution without hitting parser
performance. Our general approach is to avoid forward-parsing as much as
possible with an exception to paired brackets (because Elisp allows
parsing paired brackets fast using C-level code). However, AFAIK, there
is no easy way to parse brackets that are not single symbols. "\(" is
impossible to match using `scan-lists'.

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Problems with LaTeX export for $x\text{foo $x$}$-like construts?
  2022-12-29 10:04 ` Ihor Radchenko
@ 2022-12-29 10:39   ` Alain.Cochard
  2022-12-29 10:44     ` Ihor Radchenko
  2022-12-29 11:52   ` Ihor Radchenko
  1 sibling, 1 reply; 5+ messages in thread
From: Alain.Cochard @ 2022-12-29 10:39 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: alain.cochard, emacs-orgmode

Ihor Radchenko writes on Thu 29 Dec 2022 10:04:

 > This is to be expected because [...]

Thanks for taking the time to explain.

(I don't understand why you quoted the part of my message related to
things which work as expected, though.)

-- 
EOST (École et Observatoire des Sciences de la Terre) 
ITE (Institut Terre & Environnement) | alain.cochard@unistra.fr
5 rue René Descartes   [bureau 110]  | Phone: +33 (0)3 68 85 50 44 
F-67084 Strasbourg Cedex, France     | [ slot available for rent ]



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Problems with LaTeX export for $x\text{foo $x$}$-like construts?
  2022-12-29 10:39   ` Alain.Cochard
@ 2022-12-29 10:44     ` Ihor Radchenko
  0 siblings, 0 replies; 5+ messages in thread
From: Ihor Radchenko @ 2022-12-29 10:44 UTC (permalink / raw)
  To: Alain.Cochard; +Cc: emacs-orgmode

Alain.Cochard@unistra.fr writes:

> (I don't understand why you quoted the part of my message related to
> things which work as expected, though.)

(because I skipped them mentally :])

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Problems with LaTeX export for $x\text{foo $x$}$-like construts?
  2022-12-29 10:04 ` Ihor Radchenko
  2022-12-29 10:39   ` Alain.Cochard
@ 2022-12-29 11:52   ` Ihor Radchenko
  1 sibling, 0 replies; 5+ messages in thread
From: Ihor Radchenko @ 2022-12-29 11:52 UTC (permalink / raw)
  To: alain.cochard; +Cc: emacs-orgmode

Ihor Radchenko <yantar92@posteo.net> writes:

> Unfortunately, I do not see an easy solution without hitting parser
> performance. Our general approach is to avoid forward-parsing as much as
> possible with an exception to paired brackets (because Elisp allows
> parsing paired brackets fast using C-level code). However, AFAIK, there
> is no easy way to parse brackets that are not single symbols. "\(" is
> impossible to match using `scan-lists'.

One interesting idea to consider is using PEG (third-party ELPA package).
The above examples with paired parenthesis can be parsed using the
following PEG:

(with-peg-rules
    ((no-paren (not "\\(") (not "\\)") (any))
     (no-paren-expr (+ no-paren))
     (paren-expr "\\(" (* (or no-paren-expr paren-expr)) "\\)"))
  (peg-run (peg paren-expr)))

PEG is not built-in though, so we cannot use it in Org.

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-12-29 11:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-28 13:57 Problems with LaTeX export for $x\text{foo $x$}$-like construts? Alain.Cochard
2022-12-29 10:04 ` Ihor Radchenko
2022-12-29 10:39   ` Alain.Cochard
2022-12-29 10:44     ` Ihor Radchenko
2022-12-29 11:52   ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).