all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [bug] overprotective begin/end during latex export
@ 2010-06-13  5:25 Eric Schulte
  2010-06-13 15:41 ` [patch] " Nicolas Goaziou
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Schulte @ 2010-06-13  5:25 UTC (permalink / raw)
  To: Org Mode

Hi,

I've run across the following bug a couple of times before, but have
finally had a chance to really distill it.  When exporting the following

--8<---------------cut here---------------start------------->8---
#+TITLE: latex environments bug

there is markup /out here/

#+LaTeX: \begin{enumerate}

but *no markup* in here

#+LaTeX: \end{enumerate}

and markup _down here_ as well
--8<---------------cut here---------------end--------------->8---

everything works as expected, except that the

  but *no markup* in here

line is *not* exported to LaTeX, but is rather copied verbatim into the
final LaTeX file.

I've isolated the culprit down into this nice little self-contained
block of emacs-lisp from org-latex.el

--8<---------------cut here---------------start------------->8---
  ;; Preserve latex environments
  (goto-char (point-min))
  (while (re-search-forward "^[ \t]*\\\\begin{\\([a-zA-Z]+\\*?\\)}" nil t)
    (let* ((start (progn (beginning-of-line) (point)))
	   (end (and (re-search-forward
		      (concat "^[ \t]*\\\\end{"
			      (regexp-quote (match-string 1))
			      "}") nil t)
		     (point-at-eol))))
      (if end
	  (add-text-properties start end '(org-protected t))
	(goto-char (point-at-eol)))))
--8<---------------cut here---------------end--------------->8---

it seems that by the time this code is run, the #+LaTeX: prefixes have
been removed, and the latex exporter has no way to distinguish something
like

--8<---------------cut here---------------start------------->8---
#+LaTeX: \begin{itemize}
- first
- second
- third
#+LaTeX: \begin{itemize}
--8<---------------cut here---------------end--------------->8---

from something like

--8<---------------cut here---------------start------------->8---
\begin{itemize}
\item first
\item second
\item third
\end{itemize}
--8<---------------cut here---------------end--------------->8---

I'm not sure how this should be dealt with, but I thought I'd bring it
up.

Best -- Eric

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

* Re: [patch] overprotective begin/end during latex export
  2010-06-13  5:25 [bug] overprotective begin/end during latex export Eric Schulte
@ 2010-06-13 15:41 ` Nicolas Goaziou
  2010-06-13 16:25   ` Eric Schulte
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Goaziou @ 2010-06-13 15:41 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Org Mode

[-- Attachment #1: Type: text/plain, Size: 1470 bytes --]

>>>>> Eric Schulte writes:

Hello,

> I've run across the following bug a couple of times before, but have
> finally had a chance to really distill it.  When exporting the following

> --8<---------------cut here---------------start------------->8---
> #+TITLE: latex environments bug

> there is markup /out here/

> #+LaTeX: \begin{enumerate}

> but *no markup* in here

> #+LaTeX: \end{enumerate}

> and markup _down here_ as well
> --8<---------------cut here---------------end--------------->8---

> everything works as expected, except that the

>   but *no markup* in here

> line is *not* exported to LaTeX, but is rather copied verbatim into the
> final LaTeX file.

It is because org-latex.el doesn't check if \begin{enumerate} is
already protected or not. Thus, it treats it as if it was some plain
LaTeX code inside the file.

In other words,

#+LaTeX: \begin{enumerate}
*bold*
#+LaTeX: \end{enumerate}

is the same as

\begin{enumerate}
*bold*
\end{enumerate}

In this case, org-latex protects everything between \begin and \end,
making it impossible to apply modifications to the text in-between.

With the following patch, org-latex will not protect an environment
coming from a #+LaTeX: instruction.

Btw, a bug I described some day ago (about org-latex badly exporting
lists when an equation spans across two lines) is also about
over protection. I have a workaround, but I still don't understand
why protection is needed for lists.

HTH,

-- 
Nicolas


[-- Attachment #2: 0001-org-latex.el-do-not-protect-environments-already-pro.patch --]
[-- Type: application/octet-stream, Size: 1361 bytes --]

From 8a8478180971f61370a9257c48f0c36aa3ac5952 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@gmail.com>
Date: Sun, 13 Jun 2010 17:21:59 +0200
Subject: [PATCH] org-latex.el : do not protect environments already protected.

Environments coming from latex backend specific instructions (#+LaTeX)
are already protected and won't be treated as normal environments.

---
 lisp/org-latex.el |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/lisp/org-latex.el b/lisp/org-latex.el
index 50f5299..edc05c6 100644
--- a/lisp/org-latex.el
+++ b/lisp/org-latex.el
@@ -1984,7 +1984,8 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
   ;; Preserve latex environments
   (goto-char (point-min))
   (while (re-search-forward "^[ \t]*\\\\begin{\\([a-zA-Z]+\\*?\\)}" nil t)
-    (let* ((start (progn (beginning-of-line) (point)))
+    (org-if-unprotected
+     (let* ((start (progn (beginning-of-line) (point)))
 	   (end (and (re-search-forward
 		      (concat "^[ \t]*\\\\end{"
 			      (regexp-quote (match-string 1))
@@ -1992,7 +1993,7 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
 		     (point-at-eol))))
       (if end
 	  (add-text-properties start end '(org-protected t))
-	(goto-char (point-at-eol)))))
+	(goto-char (point-at-eol))))))
 
   ;; Preserve math snippets
 
-- 
1.7.1


[-- Attachment #3: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: [patch] overprotective begin/end during latex export
  2010-06-13 15:41 ` [patch] " Nicolas Goaziou
@ 2010-06-13 16:25   ` Eric Schulte
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Schulte @ 2010-06-13 16:25 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org Mode

Hi Nicolas,

Your patch has been applied, many thanks.

I looked at your previous email, and it's not immediately clear to me
where the problem is either.

Thanks for the quick solution on this issue however -- Eric

Nicolas Goaziou <n.goaziou@gmail.com> writes:

>>>>>> Eric Schulte writes:
>
> Hello,
>
>> I've run across the following bug a couple of times before, but have
>> finally had a chance to really distill it.  When exporting the following
>
>> --8<---------------cut here---------------start------------->8---
>> #+TITLE: latex environments bug
>
>> there is markup /out here/
>
>> #+LaTeX: \begin{enumerate}
>
>> but *no markup* in here
>
>> #+LaTeX: \end{enumerate}
>
>> and markup _down here_ as well
>> --8<---------------cut here---------------end--------------->8---
>
>> everything works as expected, except that the
>
>>   but *no markup* in here
>
>> line is *not* exported to LaTeX, but is rather copied verbatim into the
>> final LaTeX file.
>
> It is because org-latex.el doesn't check if \begin{enumerate} is
> already protected or not. Thus, it treats it as if it was some plain
> LaTeX code inside the file.
>
> In other words,
>
> #+LaTeX: \begin{enumerate}
> *bold*
> #+LaTeX: \end{enumerate}
>
> is the same as
>
> \begin{enumerate}
> *bold*
> \end{enumerate}
>
> In this case, org-latex protects everything between \begin and \end,
> making it impossible to apply modifications to the text in-between.
>
> With the following patch, org-latex will not protect an environment
> coming from a #+LaTeX: instruction.
>
> Btw, a bug I described some day ago (about org-latex badly exporting
> lists when an equation spans across two lines) is also about
> over protection. I have a workaround, but I still don't understand
> why protection is needed for lists.
>
> HTH,

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

end of thread, other threads:[~2010-06-13 16:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-13  5:25 [bug] overprotective begin/end during latex export Eric Schulte
2010-06-13 15:41 ` [patch] " Nicolas Goaziou
2010-06-13 16:25   ` Eric Schulte

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.