From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yoshinari Nomura Subject: Add figure/table numbers to HTML captions Date: Thu, 27 Jun 2013 19:52:26 +0900 (JST) Message-ID: <20130627.195226.131243714189666347.nom@cs.okayama-u.ac.jp> Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Thu_Jun_27_19_52_26_2013_770)--" Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:37120) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Us9os-0008CG-Cz for emacs-orgmode@gnu.org; Thu, 27 Jun 2013 06:53:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Us9oc-00027n-MP for emacs-orgmode@gnu.org; Thu, 27 Jun 2013 06:52:54 -0400 Received: from vintage.swlab.cs.okayama-u.ac.jp ([150.46.8.117]:61803) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Us9ob-00024Y-P7 for emacs-orgmode@gnu.org; Thu, 27 Jun 2013 06:52:38 -0400 Received: from localhost (unknown [172.21.23.5]) by vintage.swlab.cs.okayama-u.ac.jp (Postfix) with ESMTPSA id 8F2A92F93095 for ; Thu, 27 Jun 2013 19:52:31 +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: emacs-orgmode@gnu.org ----Next_Part(Thu_Jun_27_19_52_26_2013_770)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi all, 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'll be very happy if this feature is merged into the master branch. This is my first post to this list. Please teach me if we have some better way to submit the patch. Thanks. -- Yoshinari Nomura https://github.com/yoshinari-nomura Example: ----------------------------------------- #+TITLE: Add figure/table numbers to HTML captions #+LATEX_CLASS: article #+LANGUAGE: en #+OPTIONS: toc:nil * Figure Test See Figure[[fig:screenshot]] for screenshot. See Figure[[fig:manual]] for printed version of Org's manual. #+CAPTION: Org mode screen shot #+name: fig:screenshot [[http://orgmode.org/img/main.jpg]] This is org-mode logo: [[http://orgmode.org/img/org-mode-unicorn-logo.png]] (no caption, excluded from ordinal list). #+CAPTION: Org mode manual #+name: fig:manual [[http://orgmode.org/img/org-mode-7-network-theory.jpg]] * Table Test Table[[tab:phone]] shows phone numbers. Table[[tab:age]] shows age list. #+caption: Phones #+name: tab:phone | Name | Phone | Age | |-------+-------+-----| | Peter | 1234 | 17 | | Anna | 4321 | 25 | This is a plain table (no caption, excluded from ordinal list): | No. | Letter | |-----+--------| | 1 | A | | 2 | B | #+caption: Ages #+name: tab:age | Name | Age | Phone | |-------+-----+-------| | Peter | 17 | 1234 | | Anna | 25 | 4321 | ----------------------------------------- ----Next_Part(Thu_Jun_27_19_52_26_2013_770)-- Content-Type: Text/X-Patch; charset=utf-8 Content-Disposition: inline; filename="0001-Add-figure-table-numbers-to-HTML-captions.patch" Content-Transfer-Encoding: quoted-printable >From b406e083af930644017d84144554b992cf8a788f Mon Sep 17 00:00:00 2001 From: Yoshinari Nomura Date: Thu, 27 Jun 2013 18:15:36 +0900 Subject: [PATCH] Add figure/table numbers to HTML captions --- lisp/ox-html.el | 29 ++++++++++++++++++++++++++--- lisp/ox.el | 10 ++++++++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index a996b40..7217eab 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -2534,6 +2534,15 @@ Inline images can have these attributes: (parent (org-export-get-parent-element link)) (caption (org-export-data (org-export-get-caption parent) info)) (label (org-element-property :name parent))) + (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))) + (setq caption + (concat + (format (org-html--translate "Figure %d:" info) number) + " " caption)))) ;; 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)))) (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)))) (attributes (if (org-html-html5-p info) "" (org-html--make-attribute-string @@ -3183,7 +3204,9 @@ contextual information." (format (if org-html-table-caption-above "%s" "%s") - (org-export-data caption info))) + (concat + (format (org-html--translate "Table %d:" info) number) + " " (org-export-data caption info)))) (funcall table-column-specs table info) contents))))) =20 diff --git a/lisp/ox.el b/lisp/ox.el index fb56da4..1133f21 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -5265,7 +5265,12 @@ them." ("fr" :ascii "Equation" :default "=C3=89quation")) ("Figure" ("de" :default "Abbildung") - ("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:")) ("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:")) ("Table of Contents" ("ca" :html "Índex") ("cs" :default "Obsah") --=20 1.8.2.1 ----Next_Part(Thu_Jun_27_19_52_26_2013_770)----