From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: a better way with babel Date: Mon, 21 Jun 2010 09:37:36 -0700 Message-ID: <87wrts734p.fsf@gmail.com> References: <201006211803.25616.robut@iinet.net.au> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from [140.186.70.92] (port=46927 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OQk0b-0003C5-P4 for Emacs-orgmode@gnu.org; Mon, 21 Jun 2010 12:38:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OQk0a-0001rE-0j for Emacs-orgmode@gnu.org; Mon, 21 Jun 2010 12:38:05 -0400 Received: from mail-pv0-f169.google.com ([74.125.83.169]:51447) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OQk0Z-0001qy-KK for Emacs-orgmode@gnu.org; Mon, 21 Jun 2010 12:38:03 -0400 Received: by pvg16 with SMTP id 16so3374743pvg.0 for ; Mon, 21 Jun 2010 09:38:02 -0700 (PDT) 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: Robert Cunningham Cc: Emacs-orgmode@gnu.org --=-=-= Hi Robert, Thanks for the thoughtful message. I present a couple of solutions below. Robert Cunningham writes: > G'day All, > > I wonder if I've missed something and there is a better way. > > Essentially I'm trying to use org babel with R and LaTeX to create figures > with both long and short captions (for contents) > > I'd started with: > > #+CAPTION: Nice data (filled points indicate less nice data) > #+LABEL: fig:nicedata > #+ATTR_LaTeX: width=0.98\textwidth > #+begin_src R :file ndata.pdf :width 1000 :height 617 :exports results > dotchart(data$ndata) > #+end_src > > which pointed to the need for long/short captions... > > feeling hopeful I tried: > > #+CAPTION: Nice data [Nice data (filled points indicate less nice data)] > #+LABEL: fig:nicedata > #+ATTR_LaTeX: width=0.98\textwidth > #+begin_src R :file ndata.pdf :width 1000 :height 617 :exports results > dotchart(data$ndata) > #+end_src > I'm attaching a patch [1] which adds shortname support for captions. Once applied, the following syntax will result in a caption with a shortname and a longname. --8<---------------cut here---------------start------------->8--- some pre-table text #+source: g-nicedata #+begin_src gnuplot :file graph.png :exports results plot sin(x) #+end_src #+Caption: [nice data]{a longer description of the niceness of the data} #+results: g-nicedata [[file:graph.png]] some post-table text --8<---------------cut here---------------end--------------->8--- however, while this patch is still pending there is an Org-babel solution below which should work immediately. > > > but no luck there. > > Next effort was to try to use R and LaTex more directly with noweb. I tried > this: > > > > #+srcname: r-nicedata > #+begin_src R :session :file ndata.pdf :results output :exports results > dotchart(data$ndata) > #+end_src > > > #+begin_src latex :noweb yes > \begin{figure}[htb!] > \centering > \includegraphics[width=0.98\textwidth]{<>} > \caption[Nice data]{Nice data (filled points indicate less nice data)} > \label{fig:nicedata} > \end{figure} > #+end_src > > > > This does produce the figure and long/short contents BUT ALSO produces this: > > #+results: r-nicedata > [[file:ndata.pdf]] > > which upon export results in a link and consequently the plot appearing both > in the figure and elsewhere. This second plot is unwelcome. > > I've tried assorted :results and :output options but have not found how to > suppress the #+results: but still obtain the figure. I've always used > the :session option. > > I've also tried twigging an org-export option to suppress pdf export but the > link is still exported so that is not a solution. > > The current "working" solution is to use the noweb approach and then use sed > to clean out the links to the second image-ugly to say the least! > You were very close with the noweb approach. The following combination should work -- notice the ":results silent" header argument to the source block. --8<---------------cut here---------------start------------->8--- some pre-table text #+source: g-nicedata #+begin_src gnuplot :file graph.png :results silent :exports none plot sin(x) #+end_src #+begin_src latex :noweb yes \begin{figure}[htb!] \centering \includegraphics[width=0.98\textwidth]{<>} \caption[Nice data]{some nice data -- filled points indicate less nice data} \label{fig:nicedata} \end{figure} #+end_src some post-table text --8<---------------cut here---------------end--------------->8--- is exported to the following latex, --8<---------------cut here---------------start------------->8--- some pre-table text \begin{figure}[htb!] \centering \includegraphics[width=0.98\textwidth]{graph.png} \caption[Nice data]{some nice data -- filled points indicate less nice data} \label{fig:nicedata} \end{figure} some post-table text --8<---------------cut here---------------end--------------->8--- Hope this helps, Best -- Eric > > > > All this with org version 6.36c > > > What have I missed? What is the best way to do this? > > > Cheers, > > Robert Cunningham > > > > > > _______________________________________________ > 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 Footnotes: [1] --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-add-short-names-to-captions-with-support-for-latex-e.patch >From 6a55dcab99bbd7840117b8390ab5db347d2573ef Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Mon, 21 Jun 2010 09:02:37 -0700 Subject: [PATCH] add short-names to #+captions with support for latex export captions specified with the following syntax #+CAPTION: [shortname]{longname} will have their short and longnames handled appropriately. Thanks to Robert Cunningham for suggesting this feature. * lisp/org-exp.el (org-export-attach-captions-and-attributes): adding a shortname attribute to caption strings under the symbol name org-caption-shortn. * lisp/org-latex.el (org-export-latex-tables): handling caption short names on table export (org-export-latex-convert-table.el-table): handling caption short names on table.el type table export (org-export-latex-links): handling caption short names on link/image export (org-export-latex-format-image): now takes an optional argument specifying a caption short name --- lisp/org-exp.el | 14 +++++++++----- lisp/org-latex.el | 21 ++++++++++++++------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/lisp/org-exp.el b/lisp/org-exp.el index 029e4d7..466d7da 100644 --- a/lisp/org-exp.el +++ b/lisp/org-exp.el @@ -1256,7 +1256,7 @@ the current file." (goto-char (point-min)) (while (re-search-forward org-bracket-link-regexp nil t) (org-if-unprotected-at (1+ (match-beginning 0)) - (let* ((md (match-data)) + (let* ((md (match-data)) (desc (match-end 2)) (link (org-link-unescape (match-string 1))) (slink (org-solidify-link-text link)) @@ -1381,8 +1381,8 @@ removed as well." select-tags "\\|") "\\):")) (re-excl (concat ":\\(" (mapconcat 'regexp-quote - exclude-tags "\\|") - "\\):")) + exclude-tags "\\|") + "\\):")) beg end cont) (goto-char (point-min)) (when (and select-tags @@ -1593,11 +1593,14 @@ table line. If it is a link, add it to the line containing the link." "^[ \t]*\\(|[^-]\\)" "\\|" "^[ \t]*\\[\\[.*\\]\\][ \t]*$")) - cap attr label end) + cap shortn attr label end) (while (re-search-forward re nil t) (cond ((match-end 1) - (setq cap (concat cap (if cap " " "") (org-trim (match-string 1))))) + (setq cap (concat cap (if cap " " "") (org-trim (match-string 1)))) + (when (string-match "\\[\\(.*\\)\\]{\\(.*\\)}" cap) + (setq shortn (match-string 1 cap) + cap (match-string 2 cap)))) ((match-end 2) (setq attr (concat attr (if attr " " "") (org-trim (match-string 2))))) ((match-end 3) @@ -1609,6 +1612,7 @@ table line. If it is a link, add it to the line containing the link." (point-at-eol))) (add-text-properties (point-at-bol) end (list 'org-caption cap + 'org-caption-shortn shortn 'org-attributes attr 'org-label label)) (if label (push (cons label label) target-alist)) diff --git a/lisp/org-latex.el b/lisp/org-latex.el index 01a4b05..6c2aab2 100644 --- a/lisp/org-latex.el +++ b/lisp/org-latex.el @@ -1576,7 +1576,7 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER." (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) + caption shortn label attr floatp longtblp) (if org-export-latex-tables-verbatim (let* ((tbl (concat "\\begin{verbatim}\n" raw-table "\\end{verbatim}\n"))) @@ -1585,6 +1585,8 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER." (progn (setq caption (org-find-text-property-in-string 'org-caption raw-table) + shortn (org-find-text-property-in-string + 'org-caption-shortn raw-table) attr (org-find-text-property-in-string 'org-attributes raw-table) label (org-find-text-property-in-string @@ -1652,7 +1654,8 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER." (if floatp "\\begin{table}[htb]\n")) (if floatp (format - "\\caption{%s%s}" + "\\caption%s{%s%s}" + (if shortn (concat "[" shortn "]") "") (if label (concat "\\\label{" label "}") "") (or caption ""))) (if (and longtblp caption) "\\\\\n" "\n") @@ -1680,10 +1683,11 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER." (defun org-export-latex-convert-table.el-table () "Replace table.el table at point with LaTeX code." - (let (tbl caption label line floatp attr align rmlines) + (let (tbl caption shortn label line floatp attr align rmlines) (setq line (buffer-substring (point-at-bol) (point-at-eol)) label (org-get-text-property-any 0 'org-label line) caption (org-get-text-property-any 0 'org-caption line) + shortn (org-get-text-property-any 0 'org-caption-shortn line) attr (org-get-text-property-any 0 'org-attributes line) align (and attr (stringp attr) (string-match "\\