* [patch] latex export: org preprocesses code inside #+begin/end_latex block
@ 2009-10-07 0:02 Eric Schulte
2009-10-07 6:10 ` Carsten Dominik
0 siblings, 1 reply; 2+ messages in thread
From: Eric Schulte @ 2009-10-07 0:02 UTC (permalink / raw)
To: Org Mode
[-- Attachment #1: Type: text/plain, Size: 1172 bytes --]
Hi,
I just wanted to share the following bug and potential patch. When code
inside of a #+begin/end_latex block looks like a table, org-mode
processes it as a table on latex export. For example given the
following Org-mode
--8<---------------cut here---------------start------------->8---
The following latex isn't exported correctly
#+begin_latex
\begin{code}
data BTree = Leaf a
| Node Tree Tree
\end{code}
#+end_latex
--8<---------------cut here---------------end--------------->8---
org exports to the following LaTeX
--8<---------------cut here---------------start------------->8---
The following latex isn't exported correctly
\begin{code}
data BTree = Leaf a
\begin{center}
\begin{tabular}{l}
Node Tree Tree \\
\end{tabular}
\end{center}
\end{code}
--8<---------------cut here---------------end--------------->8---
The attached patch [1] appears to fix this bug, however as I don't know
the latex exporter that well there is the chance this could introduce
many other problems. (Note that although the patch looks big, all it
does is wrap part of org-export-latex-tables in an unless block)
Thanks -- Eric
Footnotes:
[1]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: protecting-tables.patch --]
[-- Type: text/x-patch, Size: 9982 bytes --]
diff --git a/lisp/org-latex.el b/lisp/org-latex.el
index c50f87e..8c50e4d 100644
--- a/lisp/org-latex.el
+++ b/lisp/org-latex.el
@@ -1336,114 +1336,115 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
"Convert tables to LaTeX and INSERT it."
(goto-char (point-min))
(while (re-search-forward "^\\([ \t]*\\)|" nil t)
- (org-table-align)
- (let* ((beg (org-table-begin))
- (end (org-table-end))
- (raw-table (buffer-substring beg end))
- (org-table-last-alignment (copy-sequence org-table-last-alignment))
- (org-table-last-column-widths (copy-sequence
- org-table-last-column-widths))
- fnum fields line lines olines gr colgropen line-fmt align
- caption label attr floatp longtblp)
- (if org-export-latex-tables-verbatim
- (let* ((tbl (concat "\\begin{verbatim}\n" raw-table
- "\\end{verbatim}\n")))
- (apply 'delete-region (list beg end))
- (insert (org-export-latex-protect-string tbl)))
- (progn
- (setq caption (org-find-text-property-in-string
- 'org-caption raw-table)
- attr (org-find-text-property-in-string
- 'org-attributes raw-table)
- label (org-find-text-property-in-string
- 'org-label raw-table)
- longtblp (and attr (stringp attr)
- (string-match "\\<longtable\\>" attr))
- align (and attr (stringp attr)
- (string-match "\\<align=\\([^ \t\n\r,]+\\)" attr)
- (match-string 1 attr))
- floatp (or caption label))
- (setq lines (org-split-string raw-table "\n"))
- (apply 'delete-region (list beg end))
- (when org-export-table-remove-special-lines
- (setq lines (org-table-clean-before-export lines 'maybe-quoted)))
- (when org-table-clean-did-remove-column
+ (unless (get-text-property (1- (point)) 'org-protected)
+ (org-table-align)
+ (let* ((beg (org-table-begin))
+ (end (org-table-end))
+ (raw-table (buffer-substring beg end))
+ (org-table-last-alignment (copy-sequence org-table-last-alignment))
+ (org-table-last-column-widths (copy-sequence
+ org-table-last-column-widths))
+ fnum fields line lines olines gr colgropen line-fmt align
+ caption label attr floatp longtblp)
+ (if org-export-latex-tables-verbatim
+ (let* ((tbl (concat "\\begin{verbatim}\n" raw-table
+ "\\end{verbatim}\n")))
+ (apply 'delete-region (list beg end))
+ (insert (org-export-latex-protect-string tbl)))
+ (progn
+ (setq caption (org-find-text-property-in-string
+ 'org-caption raw-table)
+ attr (org-find-text-property-in-string
+ 'org-attributes raw-table)
+ label (org-find-text-property-in-string
+ 'org-label raw-table)
+ longtblp (and attr (stringp attr)
+ (string-match "\\<longtable\\>" attr))
+ align (and attr (stringp attr)
+ (string-match "\\<align=\\([^ \t\n\r,]+\\)" attr)
+ (match-string 1 attr))
+ floatp (or caption label))
+ (setq lines (org-split-string raw-table "\n"))
+ (apply 'delete-region (list beg end))
+ (when org-export-table-remove-special-lines
+ (setq lines (org-table-clean-before-export lines 'maybe-quoted)))
+ (when org-table-clean-did-remove-column
(pop org-table-last-alignment)
(pop org-table-last-column-widths))
- ;; make a formatting string to reflect aligment
- (setq olines lines)
- (while (and (not line-fmt) (setq line (pop olines)))
- (unless (string-match "^[ \t]*|-" line)
- (setq fields (org-split-string line "[ \t]*|[ \t]*"))
- (setq fnum (make-vector (length fields) 0))
- (setq line-fmt
- (mapconcat
- (lambda (x)
- (setq gr (pop org-table-colgroup-info))
- (format "%s%%s%s"
- (cond ((eq gr :start)
- (prog1 (if colgropen "|" "|")
- (setq colgropen t)))
- ((eq gr :startend)
- (prog1 (if colgropen "|" "|")
- (setq colgropen nil)))
- (t ""))
- (if (memq gr '(:end :startend))
- (progn (setq colgropen nil) "|")
- "")))
- fnum ""))))
- ;; fix double || in line-fmt
- (setq line-fmt (replace-regexp-in-string "||" "|" line-fmt))
- ;; maybe remove the first and last "|"
- (when (and (not org-export-latex-tables-column-borders)
- (string-match "^\\(|\\)?\\(.+\\)|$" line-fmt))
- (setq line-fmt (match-string 2 line-fmt)))
- ;; format alignment
- (unless align
- (setq align (apply 'format
- (cons line-fmt
- (mapcar (lambda (x) (if x "r" "l"))
- org-table-last-alignment)))))
- ;; prepare the table to send to orgtbl-to-latex
- (setq lines
- (mapcar
- (lambda(elem)
- (or (and (string-match "[ \t]*|-+" elem) 'hline)
- (org-split-string (org-trim elem) "|")))
- lines))
- (when insert
- (insert (org-export-latex-protect-string
- (concat
- (if longtblp
- (concat "\\begin{longtable}{" align "}\n")
- (if floatp "\\begin{table}[htb]\n"))
- (if (or floatp longtblp)
- (format
- "\\caption{%s%s}"
- (if label (concat "\\\label{" label "}") "")
- (or caption "")))
- (if longtblp "\\\\\n" "\n")
- (if (and org-export-latex-tables-centered (not longtblp))
- "\\begin{center}\n")
- (if (not longtblp) (concat "\\begin{tabular}{" align "}\n"))
- (orgtbl-to-latex
- lines
- `(:tstart nil :tend nil
- :hlend ,(if longtblp
- (format "\\\\
+ ;; make a formatting string to reflect aligment
+ (setq olines lines)
+ (while (and (not line-fmt) (setq line (pop olines)))
+ (unless (string-match "^[ \t]*|-" line)
+ (setq fields (org-split-string line "[ \t]*|[ \t]*"))
+ (setq fnum (make-vector (length fields) 0))
+ (setq line-fmt
+ (mapconcat
+ (lambda (x)
+ (setq gr (pop org-table-colgroup-info))
+ (format "%s%%s%s"
+ (cond ((eq gr :start)
+ (prog1 (if colgropen "|" "|")
+ (setq colgropen t)))
+ ((eq gr :startend)
+ (prog1 (if colgropen "|" "|")
+ (setq colgropen nil)))
+ (t ""))
+ (if (memq gr '(:end :startend))
+ (progn (setq colgropen nil) "|")
+ "")))
+ fnum ""))))
+ ;; fix double || in line-fmt
+ (setq line-fmt (replace-regexp-in-string "||" "|" line-fmt))
+ ;; maybe remove the first and last "|"
+ (when (and (not org-export-latex-tables-column-borders)
+ (string-match "^\\(|\\)?\\(.+\\)|$" line-fmt))
+ (setq line-fmt (match-string 2 line-fmt)))
+ ;; format alignment
+ (unless align
+ (setq align (apply 'format
+ (cons line-fmt
+ (mapcar (lambda (x) (if x "r" "l"))
+ org-table-last-alignment)))))
+ ;; prepare the table to send to orgtbl-to-latex
+ (setq lines
+ (mapcar
+ (lambda(elem)
+ (or (and (string-match "[ \t]*|-+" elem) 'hline)
+ (org-split-string (org-trim elem) "|")))
+ lines))
+ (when insert
+ (insert (org-export-latex-protect-string
+ (concat
+ (if longtblp
+ (concat "\\begin{longtable}{" align "}\n")
+ (if floatp "\\begin{table}[htb]\n"))
+ (if (or floatp longtblp)
+ (format
+ "\\caption{%s%s}"
+ (if label (concat "\\\label{" label "}") "")
+ (or caption "")))
+ (if longtblp "\\\\\n" "\n")
+ (if (and org-export-latex-tables-centered (not longtblp))
+ "\\begin{center}\n")
+ (if (not longtblp) (concat "\\begin{tabular}{" align "}\n"))
+ (orgtbl-to-latex
+ lines
+ `(:tstart nil :tend nil
+ :hlend ,(if longtblp
+ (format "\\\\
\\hline
\\endhead
\\hline\\multicolumn{%d}{r}{Continued on next page}\\
\\endfoot
\\endlastfoot" (length org-table-last-alignment))
- nil)))
- (if (not longtblp) (concat "\n\\end{tabular}"))
- (if longtblp "\n" (if org-export-latex-tables-centered
- "\n\\end{center}\n" "\n"))
- (if longtblp
- "\\end{longtable}"
- (if floatp "\\end{table}"))))
- "\n\n")))))))
+ nil)))
+ (if (not longtblp) (concat "\n\\end{tabular}"))
+ (if longtblp "\n" (if org-export-latex-tables-centered
+ "\n\\end{center}\n" "\n"))
+ (if longtblp
+ "\\end{longtable}"
+ (if floatp "\\end{table}"))))
+ "\n\n"))))))))
(defun org-export-latex-fontify ()
"Convert fontification to LaTeX."
[-- Attachment #3: Type: text/plain, Size: 204 bytes --]
_______________________________________________
Emacs-orgmode mailing list
Remember: 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] 2+ messages in thread
* Re: [patch] latex export: org preprocesses code inside #+begin/end_latex block
2009-10-07 0:02 [patch] latex export: org preprocesses code inside #+begin/end_latex block Eric Schulte
@ 2009-10-07 6:10 ` Carsten Dominik
0 siblings, 0 replies; 2+ messages in thread
From: Carsten Dominik @ 2009-10-07 6:10 UTC (permalink / raw)
To: Eric Schulte; +Cc: Org Mode
Hi Eric,
Ouuuch, bad bug. I have applied you patch, but changed it to use the
`org-if-unprotected-at' macro.
Thanks!
- Carsten
On Oct 7, 2009, at 2:02 AM, Eric Schulte wrote:
> Hi,
>
> I just wanted to share the following bug and potential patch. When
> code
> inside of a #+begin/end_latex block looks like a table, org-mode
> processes it as a table on latex export. For example given the
> following Org-mode
>
> --8<---------------cut here---------------start------------->8---
> The following latex isn't exported correctly
>
> #+begin_latex
> \begin{code}
> data BTree = Leaf a
> | Node Tree Tree
> \end{code}
> #+end_latex
> --8<---------------cut here---------------end--------------->8---
>
> org exports to the following LaTeX
>
> --8<---------------cut here---------------start------------->8---
> The following latex isn't exported correctly
>
> \begin{code}
> data BTree = Leaf a
>
> \begin{center}
> \begin{tabular}{l}
> Node Tree Tree \\
> \end{tabular}
> \end{center}
>
>
> \end{code}
> --8<---------------cut here---------------end--------------->8---
>
> The attached patch [1] appears to fix this bug, however as I don't
> know
> the latex exporter that well there is the chance this could introduce
> many other problems. (Note that although the patch looks big, all it
> does is wrap part of org-export-latex-tables in an unless block)
>
> Thanks -- Eric
>
> Footnotes:
> [1] diff --git a/lisp/org-latex.el b/lisp/org-latex.el
> index c50f87e..8c50e4d 100644
> --- a/lisp/org-latex.el
> +++ b/lisp/org-latex.el
> @@ -1336,114 +1336,115 @@ The conversion is made depending of STRING-
> BEFORE and STRING-AFTER."
> "Convert tables to LaTeX and INSERT it."
> (goto-char (point-min))
> (while (re-search-forward "^\\([ \t]*\\)|" nil t)
> - (org-table-align)
> - (let* ((beg (org-table-begin))
> - (end (org-table-end))
> - (raw-table (buffer-substring beg end))
> - (org-table-last-alignment (copy-sequence org-table-last-
> alignment))
> - (org-table-last-column-widths (copy-sequence
> - org-table-last-column-widths))
> - fnum fields line lines olines gr colgropen line-fmt align
> - caption label attr floatp longtblp)
> - (if org-export-latex-tables-verbatim
> - (let* ((tbl (concat "\\begin{verbatim}\n" raw-table
> - "\\end{verbatim}\n")))
> - (apply 'delete-region (list beg end))
> - (insert (org-export-latex-protect-string tbl)))
> - (progn
> - (setq caption (org-find-text-property-in-string
> - 'org-caption raw-table)
> - attr (org-find-text-property-in-string
> - 'org-attributes raw-table)
> - label (org-find-text-property-in-string
> - 'org-label raw-table)
> - longtblp (and attr (stringp attr)
> - (string-match "\\<longtable\\>" attr))
> - align (and attr (stringp attr)
> - (string-match "\\<align=\\([^ \t\n\r,]+\\)" attr)
> - (match-string 1 attr))
> - floatp (or caption label))
> - (setq lines (org-split-string raw-table "\n"))
> - (apply 'delete-region (list beg end))
> - (when org-export-table-remove-special-lines
> - (setq lines (org-table-clean-before-export lines 'maybe-
> quoted)))
> - (when org-table-clean-did-remove-column
> + (unless (get-text-property (1- (point)) 'org-protected)
> + (org-table-align)
> + (let* ((beg (org-table-begin))
> + (end (org-table-end))
> + (raw-table (buffer-substring beg end))
> + (org-table-last-alignment (copy-sequence org-table-
> last-alignment))
> + (org-table-last-column-widths (copy-sequence
> + org-table-last-column-
> widths))
> + fnum fields line lines olines gr colgropen line-fmt
> align
> + caption label attr floatp longtblp)
> + (if org-export-latex-tables-verbatim
> + (let* ((tbl (concat "\\begin{verbatim}\n" raw-table
> + "\\end{verbatim}\n")))
> + (apply 'delete-region (list beg end))
> + (insert (org-export-latex-protect-string tbl)))
> + (progn
> + (setq caption (org-find-text-property-in-string
> + 'org-caption raw-table)
> + attr (org-find-text-property-in-string
> + 'org-attributes raw-table)
> + label (org-find-text-property-in-string
> + 'org-label raw-table)
> + longtblp (and attr (stringp attr)
> + (string-match "\\<longtable\\>"
> attr))
> + align (and attr (stringp attr)
> + (string-match "\\<align=\\([^ \t\n\r,]+
> \\)" attr)
> + (match-string 1 attr))
> + floatp (or caption label))
> + (setq lines (org-split-string raw-table "\n"))
> + (apply 'delete-region (list beg end))
> + (when org-export-table-remove-special-lines
> + (setq lines (org-table-clean-before-export lines
> 'maybe-quoted)))
> + (when org-table-clean-did-remove-column
> (pop org-table-last-alignment)
> (pop org-table-last-column-widths))
> - ;; make a formatting string to reflect aligment
> - (setq olines lines)
> - (while (and (not line-fmt) (setq line (pop olines)))
> - (unless (string-match "^[ \t]*|-" line)
> - (setq fields (org-split-string line "[ \t]*|[ \t]*"))
> - (setq fnum (make-vector (length fields) 0))
> - (setq line-fmt
> - (mapconcat
> - (lambda (x)
> - (setq gr (pop org-table-colgroup-info))
> - (format "%s%%s%s"
> - (cond ((eq gr :start)
> - (prog1 (if colgropen "|" "|")
> - (setq colgropen t)))
> - ((eq gr :startend)
> - (prog1 (if colgropen "|" "|")
> - (setq colgropen nil)))
> - (t ""))
> - (if (memq gr '(:end :startend))
> - (progn (setq colgropen nil) "|")
> - "")))
> - fnum ""))))
> - ;; fix double || in line-fmt
> - (setq line-fmt (replace-regexp-in-string "||" "|" line-fmt))
> - ;; maybe remove the first and last "|"
> - (when (and (not org-export-latex-tables-column-borders)
> - (string-match "^\\(|\\)?\\(.+\\)|$" line-fmt))
> - (setq line-fmt (match-string 2 line-fmt)))
> - ;; format alignment
> - (unless align
> - (setq align (apply 'format
> - (cons line-fmt
> - (mapcar (lambda (x) (if x "r" "l"))
> - org-table-last-alignment)))))
> - ;; prepare the table to send to orgtbl-to-latex
> - (setq lines
> - (mapcar
> - (lambda(elem)
> - (or (and (string-match "[ \t]*|-+" elem) 'hline)
> - (org-split-string (org-trim elem) "|")))
> - lines))
> - (when insert
> - (insert (org-export-latex-protect-string
> - (concat
> - (if longtblp
> - (concat "\\begin{longtable}{" align "}\n")
> - (if floatp "\\begin{table}[htb]\n"))
> - (if (or floatp longtblp)
> - (format
> - "\\caption{%s%s}"
> - (if label (concat "\\\label{" label "}") "")
> - (or caption "")))
> - (if longtblp "\\\\\n" "\n")
> - (if (and org-export-latex-tables-centered (not longtblp))
> - "\\begin{center}\n")
> - (if (not longtblp) (concat "\\begin{tabular}{" align "}\n"))
> - (orgtbl-to-latex
> - lines
> - `(:tstart nil :tend nil
> - :hlend ,(if longtblp
> - (format "\\\\
> + ;; make a formatting string to reflect aligment
> + (setq olines lines)
> + (while (and (not line-fmt) (setq line (pop olines)))
> + (unless (string-match "^[ \t]*|-" line)
> + (setq fields (org-split-string line "[ \t]*|[ \t]*"))
> + (setq fnum (make-vector (length fields) 0))
> + (setq line-fmt
> + (mapconcat
> + (lambda (x)
> + (setq gr (pop org-table-colgroup-info))
> + (format "%s%%s%s"
> + (cond ((eq gr :start)
> + (prog1 (if colgropen "|" "|")
> + (setq colgropen t)))
> + ((eq gr :startend)
> + (prog1 (if colgropen "|" "|")
> + (setq colgropen nil)))
> + (t ""))
> + (if (memq gr '(:end :startend))
> + (progn (setq colgropen nil) "|")
> + "")))
> + fnum ""))))
> + ;; fix double || in line-fmt
> + (setq line-fmt (replace-regexp-in-string "||" "|" line-
> fmt))
> + ;; maybe remove the first and last "|"
> + (when (and (not org-export-latex-tables-column-borders)
> + (string-match "^\\(|\\)?\\(.+\\)|$" line-fmt))
> + (setq line-fmt (match-string 2 line-fmt)))
> + ;; format alignment
> + (unless align
> + (setq align (apply 'format
> + (cons line-fmt
> + (mapcar (lambda (x) (if x
> "r" "l"))
> + org-table-last-
> alignment)))))
> + ;; prepare the table to send to orgtbl-to-latex
> + (setq lines
> + (mapcar
> + (lambda(elem)
> + (or (and (string-match "[ \t]*|-+" elem) 'hline)
> + (org-split-string (org-trim elem) "|")))
> + lines))
> + (when insert
> + (insert (org-export-latex-protect-string
> + (concat
> + (if longtblp
> + (concat "\\begin{longtable}{" align "}
> \n")
> + (if floatp "\\begin{table}[htb]\n"))
> + (if (or floatp longtblp)
> + (format
> + "\\caption{%s%s}"
> + (if label (concat "\\\label{" label
> "}") "")
> + (or caption "")))
> + (if longtblp "\\\\\n" "\n")
> + (if (and org-export-latex-tables-centered
> (not longtblp))
> + "\\begin{center}\n")
> + (if (not longtblp) (concat "\\begin{tabular}
> {" align "}\n"))
> + (orgtbl-to-latex
> + lines
> + `(:tstart nil :tend nil
> + :hlend ,(if longtblp
> + (format "\\\\
> \\hline
> \\endhead
> \\hline\\multicolumn{%d}{r}{Continued on next page}\\
> \\endfoot
> \\endlastfoot" (length org-table-last-alignment))
> - nil)))
> - (if (not longtblp) (concat "\n\\end{tabular}"))
> - (if longtblp "\n" (if org-export-latex-tables-centered
> - "\n\\end{center}\n" "\n"))
> - (if longtblp
> - "\\end{longtable}"
> - (if floatp "\\end{table}"))))
> - "\n\n")))))))
> + nil)))
> + (if (not longtblp) (concat "\n\
> \end{tabular}"))
> + (if longtblp "\n" (if org-export-latex-
> tables-centered
> + "\n\\end{center}\n"
> "\n"))
> + (if longtblp
> + "\\end{longtable}"
> + (if floatp "\\end{table}"))))
> + "\n\n"))))))))
>
> (defun org-export-latex-fontify ()
> "Convert fontification to LaTeX."
> _______________________________________________
> Emacs-orgmode mailing list
> Remember: use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-10-07 6:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-07 0:02 [patch] latex export: org preprocesses code inside #+begin/end_latex block Eric Schulte
2009-10-07 6:10 ` Carsten Dominik
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.