From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: Add figure/table numbers to HTML captions Date: Thu, 27 Jun 2013 16:46:19 +0200 Message-ID: <87li5vsjb8.fsf@gmail.com> References: <20130627.195226.131243714189666347.nom@cs.okayama-u.ac.jp> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54201) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UsDSd-0000rw-QI for emacs-orgmode@gnu.org; Thu, 27 Jun 2013 10:46:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UsDSb-0004El-Qd for emacs-orgmode@gnu.org; Thu, 27 Jun 2013 10:46:11 -0400 Received: from mail-wg0-x22f.google.com ([2a00:1450:400c:c00::22f]:55316) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UsDSb-0004Eb-HR for emacs-orgmode@gnu.org; Thu, 27 Jun 2013 10:46:09 -0400 Received: by mail-wg0-f47.google.com with SMTP id l18so644843wgh.2 for ; Thu, 27 Jun 2013 07:46:08 -0700 (PDT) In-Reply-To: <20130627.195226.131243714189666347.nom@cs.okayama-u.ac.jp> (Yoshinari Nomura's message of "Thu, 27 Jun 2013 19:52:26 +0900 (JST)") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Yoshinari Nomura Cc: emacs-orgmode@gnu.org Hello, Yoshinari Nomura writes: > I sometimes need to export an org document into both HTML and LaTeX. > In such case, I want HTML exporter to create numbered captions for > figures and tables. > > So, I've written a small patch to add figure/table numbers to HTML > captions. (see 0001-Add-figure-table-numbers-to-HTML-captions.patch) I hadn't noticed HTML export back-end didn't provide this feature already. I agree this should be implemented. Thank you for taking care of it. > I'll be very happy if this feature is merged into the master branch. Sure. Here are a few comments in addition to those suggested by Rasmus in this thread. > + (unless (string=3D caption "") > + (let* ((org-html-standalone-image-predicate > + (lambda (img) (org-element-property :caption img))) > + (number (org-export-get-ordinal > + link info nil 'org-html-standalone-image-p))) You should put this function at the top level instead, since another transcoder use it. See `org-ascii--has-caption-p' in ascii export back-end. You can also use a lambda each time. Your call. > + (setq caption > + (concat > + (format (org-html--translate "Figure %d:" info) number) > + " " caption)))) I would move this in the first caption binding. Assuming you implemented `org-html--has-caption-p', you could use something like: (let (... (caption (let ((raw (org-export-data (org-export-get-caption parent) info))) (when (org-string-nw-p raw) (concat (format (org-html--translate "Figure %d:" info) (org-export-get-ordinal link info nil 'org-html--has-caption-p)) " " raw)))))) > ;; Return proper string, depending on DISPOSITION. > (org-html-format-inline-image > path info caption label > @@ -2725,14 +2734,23 @@ INFO is a plist holding contextual information. = See > (org-export-solidify-link-text href) attributes desc))) > ;; Fuzzy link points to a target. Do as above. > (t > - (let ((path (org-export-solidify-link-text path)) number) > + (let ((path (org-export-solidify-link-text path)) number > + caption-predicate org-html-standalone-image-predicate) > (unless desc > + (setq caption-predicate > + (if (org-element-property :caption destination) > + (lambda (elem &optional info) > + (org-element-property :caption elem)) > + (lambda (elem &optional info) > + (not (org-element-property :caption elem))))) > + (setq org-html-standalone-image-predicate caption-predicate) > (setq number (cond > ((org-html-standalone-image-p destination info) > (org-export-get-ordinal > (assoc 'link (org-element-contents destination)) > info 'link 'org-html-standalone-image-p)) > - (t (org-export-get-ordinal destination info)))) > + (t (org-export-get-ordinal > + destination info nil > caption-predicate)))) You don't need to change `org-html-link'. I think it already DTRT. > (setq desc (when number > (if (atom number) (number-to-string number) > (mapconcat 'number-to-string number "."))))) > @@ -3145,6 +3163,9 @@ contextual information." > (t > (let* ((label (org-element-property :name table)) > (caption (org-export-get-caption table)) > + (number (org-export-get-ordinal > + table info nil > + (lambda (tbl info) (org-element-property :caption tbl)))) See comment above. > - ("es" :default "Figura")) > + ("es" :default "Figura") > + ("ja" :html "図" :utf-8 "=E5=9B=B3")) > + ("Figure %d:" > + ("de" :default "Abbildung %d:") > + ("es" :default "Figura %d:") > + ("ja" :html "図%d:" :utf-8 "=E5=9B=B3%d:")) Maybe you should also provide a :default value, otherwise it will use "Figure %d:" for latex, texinfo, ascii... Also, I think it belong to a different patch. Would you mind splitting them? > ("Footnotes" > ("ca" :html "Peus de pàgina") > ("cs" :default "Pozn\xe1mky pod carou") > @@ -5312,7 +5317,8 @@ them." > ("de" :default "Tabelle %d") > ("es" :default "Tabla %d") > ("fr" > - :ascii "Tableau %d :" :default "Tableau n=C2=BA %d :" :latin1 "Tab= leau %d :")) > + :ascii "Tableau %d :" :default "Tableau n=C2=BA %d :" :latin1 "Tab= leau %d :") > + ("ja" :html "表%d:" :utf-8 "=E8=A1=A8%d:")) Ditto. Regards, --=20 Nicolas Goaziou