From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: [patch] latex export: org preprocesses code inside #+begin/end_latex block Date: Wed, 7 Oct 2009 08:10:55 +0200 Message-ID: References: Mime-Version: 1.0 (Apple Message framework v936) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MvPjv-00034z-86 for emacs-orgmode@gnu.org; Wed, 07 Oct 2009 02:11:07 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MvPjq-00030m-Ru for emacs-orgmode@gnu.org; Wed, 07 Oct 2009 02:11:06 -0400 Received: from [199.232.76.173] (port=51620 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvPjq-00030G-Iv for emacs-orgmode@gnu.org; Wed, 07 Oct 2009 02:11:02 -0400 Received: from mx20.gnu.org ([199.232.41.8]:9304) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MvPjp-0001QG-TZ for emacs-orgmode@gnu.org; Wed, 07 Oct 2009 02:11:02 -0400 Received: from mail-ew0-f223.google.com ([209.85.219.223]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MvPjo-0003pf-DX for emacs-orgmode@gnu.org; Wed, 07 Oct 2009 02:11:00 -0400 Received: by ewy23 with SMTP id 23so5022513ewy.2 for ; Tue, 06 Oct 2009 23:10:58 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org 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 "\\" attr)) > - align (and attr (stringp attr) > - (string-match "\\ - (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 "\\" > attr)) > + align (and attr (stringp attr) > + (string-match "\\ \\)" 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