emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* #+LABEL: in HTML export
@ 2010-03-28 20:29 Thomas S. Dye
  2010-03-29 12:20 ` Carsten Dominik
  0 siblings, 1 reply; 8+ messages in thread
From: Thomas S. Dye @ 2010-03-28 20:29 UTC (permalink / raw)
  To: emacs-orgmode list


[-- Attachment #1.1: Type: text/plain, Size: 1153 bytes --]

Aloha all,

I am working to create a single org-mode file that exports (almost)  
identically to HTML and LaTeX.  I haven't found a way to do this for  
cross-references to figures.  I'm wondering if it would be difficult  
to change the behavior of the LaTeX exporter to recognize and  
appropriately export the argument to #+LABEL:?

This line above an org-mode table:

#+LABEL: tab:xrf

is correctly and usefully exported to LaTeX as:

\label{tab:xrf}

A link in the org-mode file like this:

  [[tab:xrf][(table 2)]]

behaves as expected in the pdf file compiled from the LaTeX export.   
In situations where it is not difficult to live without LaTeX's cross- 
referencing facility, this is great.  (I know that it is possible to  
put \ref{tab:xrf} in the org-mode file and that this works beautifully  
in the LaTeX export, but it does nothing in the HTML export.)

The #+LABEL: tab:xrf doesn't appear in HTML export from the same org- 
mode file.  If it could appear there, perhaps like this:

<a name="tab:xrf" id="tab:xrf"></a>

then one org-mode file would correctly export these cross-references  
to both LaTeX and HTML.

All the best,
Tom


[-- Attachment #1.2: Type: text/html, Size: 1677 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: #+LABEL: in HTML export
  2010-03-28 20:29 #+LABEL: in HTML export Thomas S. Dye
@ 2010-03-29 12:20 ` Carsten Dominik
  2010-04-02 22:51   ` Baoqiu Cui
  0 siblings, 1 reply; 8+ messages in thread
From: Carsten Dominik @ 2010-03-29 12:20 UTC (permalink / raw)
  To: Thomas S. Dye; +Cc: emacs-orgmode list

Hi Thomas,

Are you talking about figures or about tables?

For figures, the label is attached to the figure as the id of
the div surrounding figure plus caption.  However, this only
works if you also specify a caption.  But I think that only
figures with caption should be targets for links.

For tables, I have just made a change so that the label
is inserted as an anchor just as you propose:

    <table border="2" cellspacing="0" cellpadding="6" rules="groups"  
frame="hsides">
    <a name="tab:yyy" id="tab:yyy"></a>
    <caption>This is a table</caption>

Finally, I am now converting \ref{xxx} macros into links
for the HTML backend.  One problem is that, so the same
\ref macro will lead to the figure in both backends.

Hope this helps.

- Carsten




On Mar 28, 2010, at 10:29 PM, Thomas S. Dye wrote:

> Aloha all,
>
> I am working to create a single org-mode file that exports (almost)  
> identically to HTML and LaTeX.  I haven't found a way to do this for  
> cross-references to figures.

Here you talk about figures

>  I'm wondering if it would be difficult to change the behavior of  
> the LaTeX exporter to recognize and appropriately export the  
> argument to #+LABEL:?
>
> This line above an org-mode table:
>
> #+LABEL: tab:xrf
>
> is correctly and usefully exported to LaTeX as:
>
> \label{tab:xrf}
>
> A link in the org-mode file like this:
>
>  [[tab:xrf][(table 2)]]
>
> behaves as expected in the pdf file compiled from the LaTeX export.   
> In situations where it is not difficult to live without LaTeX's  
> cross-referencing facility, this is great.  (I know that it is  
> possible to put \ref{tab:xrf} in the org-mode file and that this  
> works beautifully in the LaTeX export, but it does nothing in the  
> HTML export.)
>
> The #+LABEL: tab:xrf doesn't appear in HTML export from the same org- 
> mode file.  If it could appear there, perhaps like this:
>
> <a name="tab:xrf" id="tab:xrf"></a>
>
> then one org-mode file would correctly export these cross-references  
> to both LaTeX and HTML.
>
> All the best,
> Tom
>
> _______________________________________________
> 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

- Carsten

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: #+LABEL: in HTML export
  2010-03-29 12:20 ` Carsten Dominik
@ 2010-04-02 22:51   ` Baoqiu Cui
  2010-04-03  6:33     ` Carsten Dominik
  0 siblings, 1 reply; 8+ messages in thread
From: Baoqiu Cui @ 2010-04-02 22:51 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 265 bytes --]

Hi Carsten,

I've made corresponding changes in org-docbook.el to support this
feature in the DocBook exporter.  Please check the attached patch, in
which I also fixed a minor bug that was introduced in your recent change
of "new and better support for entities".


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: table-label.diff --]
[-- Type: text/x-patch, Size: 2597 bytes --]

diff --git a/lisp/org-docbook.el b/lisp/org-docbook.el
index 7c43211..700f1db 100644
--- a/lisp/org-docbook.el
+++ b/lisp/org-docbook.el
@@ -1259,13 +1259,13 @@ string, don't modify these."
   (if org-export-with-sub-superscripts
       (setq s (org-export-docbook-convert-sub-super s)))
   (if org-export-with-TeX-macros
-      (let ((start 0) wd rep ass)
+      (let ((start 0) wd rep)
 	(while (setq start (string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
 					 s start))
 	  (if (get-text-property (match-beginning 0) 'org-protected s)
 	      (setq start (match-end 0))
 	    (setq wd (match-string 1 s))
-	    (if (setq ass (org-entity-get-representation wd 'html))
+	    (if (setq rep (org-entity-get-representation wd 'html))
 		(setq s (replace-match rep t t s))
 	      (setq start (+ start (length wd))))))))
   s)
@@ -1349,18 +1349,33 @@ string, don't modify these."
 	(replace-match ""))))
 
 (defun org-export-docbook-finalize-table (table)
-  "Change TABLE to informaltable if caption does not exist.
+  "Clean up TABLE and turn it into DocBook format.
+This function adds a label to the table if it is available, and
+also changes TABLE to informaltable if caption does not exist.
 TABLE is a string containing the HTML code generated by
 `org-format-table-html' for a table in Org-mode buffer."
-  (if (string-match
-       "^<table \\(\\(.\\|\n\\)+\\)<caption></caption>\n\\(\\(.\\|\n\\)+\\)</table>"
-       table)
-      (replace-match (concat "<informaltable "
-			     (match-string 1 table)
-			     (match-string 3 table)
+  (let ((table-with-label label))
+    ;; Get the label if it exists, and move it into the <table> element.
+    (setq table-with-label
+	  (if (string-match
+	       "^<table \\(\\(.\\|\n\\)+\\)<a name=\"\\(.+\\)\" id=\".+\"></a>\n\\(\\(.\\|\n\\)+\\)</table>"
+	       table)
+	      (replace-match (concat "<table xml:id=\"" (match-string 3 table) "\" "
+				     (match-string 1 table)
+				     (match-string 4 table)
+				     "</table>")
+			     nil nil table)
+	    table))
+    ;; Change <table> into <informaltable> if caption does not exist.
+    (if (string-match
+	 "^<table \\(\\(.\\|\n\\)+\\)<caption></caption>\n\\(\\(.\\|\n\\)+\\)</table>"
+	 table-with-label)
+	(replace-match (concat "<informaltable "
+			     (match-string 1 table-with-label)
+			     (match-string 3 table-with-label)
 			     "</informaltable>")
-		     nil nil table)
-    table))
+		       nil nil table-with-label)
+      table-with-label)))
 
 ;; Note: This function is very similar to
 ;; org-export-html-convert-sub-super.  They can be merged in the future.

[-- Attachment #3: Type: text/plain, Size: 856 bytes --]


Carsten Dominik <carsten.dominik@gmail.com> writes:

> Hi Thomas,
>
> Are you talking about figures or about tables?
>
> For figures, the label is attached to the figure as the id of
> the div surrounding figure plus caption.  However, this only
> works if you also specify a caption.  But I think that only
> figures with caption should be targets for links.
>
> For tables, I have just made a change so that the label
> is inserted as an anchor just as you propose:
>
>    <table border="2" cellspacing="0" cellpadding="6" rules="groups"
> frame="hsides">
>    <a name="tab:yyy" id="tab:yyy"></a>
>    <caption>This is a table</caption>
>
> Finally, I am now converting \ref{xxx} macros into links
> for the HTML backend.  One problem is that, so the same
> \ref macro will lead to the figure in both backends.
>
> Hope this helps.

Thanks,

-- 
Baoqiu

[-- Attachment #4: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: Re: #+LABEL: in HTML export
  2010-04-02 22:51   ` Baoqiu Cui
@ 2010-04-03  6:33     ` Carsten Dominik
  2010-04-03  7:15       ` Baoqiu Cui
  0 siblings, 1 reply; 8+ messages in thread
From: Carsten Dominik @ 2010-04-03  6:33 UTC (permalink / raw)
  To: Baoqiu Cui; +Cc: emacs-orgmode

Hi Baoqiu,

I did apply the patch - by hand because the Emai program did wrap one  
or two lines.

Please check if everything went well.

Thanks!

- Carsten

On Apr 3, 2010, at 12:51 AM, Baoqiu Cui wrote:

> Hi Carsten,
>
> I've made corresponding changes in org-docbook.el to support this
> feature in the DocBook exporter.  Please check the attached patch, in
> which I also fixed a minor bug that was introduced in your recent  
> change
> of "new and better support for entities".
>
> diff --git a/lisp/org-docbook.el b/lisp/org-docbook.el
> index 7c43211..700f1db 100644
> --- a/lisp/org-docbook.el
> +++ b/lisp/org-docbook.el
> @@ -1259,13 +1259,13 @@ string, don't modify these."
>   (if org-export-with-sub-superscripts
>       (setq s (org-export-docbook-convert-sub-super s)))
>   (if org-export-with-TeX-macros
> -      (let ((start 0) wd rep ass)
> +      (let ((start 0) wd rep)
> 	(while (setq start (string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
> 					 s start))
> 	  (if (get-text-property (match-beginning 0) 'org-protected s)
> 	      (setq start (match-end 0))
> 	    (setq wd (match-string 1 s))
> -	    (if (setq ass (org-entity-get-representation wd 'html))
> +	    (if (setq rep (org-entity-get-representation wd 'html))
> 		(setq s (replace-match rep t t s))
> 	      (setq start (+ start (length wd))))))))
>   s)
> @@ -1349,18 +1349,33 @@ string, don't modify these."
> 	(replace-match ""))))
>
> (defun org-export-docbook-finalize-table (table)
> -  "Change TABLE to informaltable if caption does not exist.
> +  "Clean up TABLE and turn it into DocBook format.
> +This function adds a label to the table if it is available, and
> +also changes TABLE to informaltable if caption does not exist.
> TABLE is a string containing the HTML code generated by
> `org-format-table-html' for a table in Org-mode buffer."
> -  (if (string-match
> -       "^<table \\(\\(.\\|\n\\)+\\)<caption></caption>\n\\(\\(.\\|\n 
> \\)+\\)</table>"
> -       table)
> -      (replace-match (concat "<informaltable "
> -			     (match-string 1 table)
> -			     (match-string 3 table)
> +  (let ((table-with-label label))
> +    ;; Get the label if it exists, and move it into the <table>  
> element.
> +    (setq table-with-label
> +	  (if (string-match
> +	       "^<table \\(\\(.\\|\n\\)+\\)<a name=\"\\(.+\\)\" id=\".+ 
> \"></a>\n\\(\\(.\\|\n\\)+\\)</table>"
> +	       table)
> +	      (replace-match (concat "<table xml:id=\"" (match-string 3  
> table) "\" "
> +				     (match-string 1 table)
> +				     (match-string 4 table)
> +				     "</table>")
> +			     nil nil table)
> +	    table))
> +    ;; Change <table> into <informaltable> if caption does not exist.
> +    (if (string-match
> +	 "^<table \\(\\(.\\|\n\\)+\\)<caption></caption>\n\\(\\(.\\|\n\\)+\ 
> \)</table>"
> +	 table-with-label)
> +	(replace-match (concat "<informaltable "
> +			     (match-string 1 table-with-label)
> +			     (match-string 3 table-with-label)
> 			     "</informaltable>")
> -		     nil nil table)
> -    table))
> +		       nil nil table-with-label)
> +      table-with-label)))
>
> ;; Note: This function is very similar to
> ;; org-export-html-convert-sub-super.  They can be merged in the  
> future.
>
> Carsten Dominik <carsten.dominik@gmail.com> writes:
>
>> Hi Thomas,
>>
>> Are you talking about figures or about tables?
>>
>> For figures, the label is attached to the figure as the id of
>> the div surrounding figure plus caption.  However, this only
>> works if you also specify a caption.  But I think that only
>> figures with caption should be targets for links.
>>
>> For tables, I have just made a change so that the label
>> is inserted as an anchor just as you propose:
>>
>>   <table border="2" cellspacing="0" cellpadding="6" rules="groups"
>> frame="hsides">
>>   <a name="tab:yyy" id="tab:yyy"></a>
>>   <caption>This is a table</caption>
>>
>> Finally, I am now converting \ref{xxx} macros into links
>> for the HTML backend.  One problem is that, so the same
>> \ref macro will lead to the figure in both backends.
>>
>> Hope this helps.
>
> Thanks,
>
> -- 
> Baoqiu
> _______________________________________________
> 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

- Carsten

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Re: #+LABEL: in HTML export
  2010-04-03  6:33     ` Carsten Dominik
@ 2010-04-03  7:15       ` Baoqiu Cui
  2010-04-03  9:23         ` Carsten Dominik
  0 siblings, 1 reply; 8+ messages in thread
From: Baoqiu Cui @ 2010-04-03  7:15 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: emacs-orgmode, Baoqiu Cui

Carsten Dominik <carsten.dominik@gmail.com> writes:

> Hi Baoqiu,
>
> I did apply the patch - by hand because the Emai program did wrap one
> or two lines.
>
> Please check if everything went well.

Thanks for the quick action, Carsten!  Your patch applying was perfect,
and you actually fixed an indentation problem in my original patch. :-)

Thanks!

-- 
Baoqiu

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Re: #+LABEL: in HTML export
  2010-04-03  7:15       ` Baoqiu Cui
@ 2010-04-03  9:23         ` Carsten Dominik
  2010-04-03 16:46           ` Baoqiu Cui
  0 siblings, 1 reply; 8+ messages in thread
From: Carsten Dominik @ 2010-04-03  9:23 UTC (permalink / raw)
  To: Baoqiu Cui; +Cc: emacs-orgmode


On Apr 3, 2010, at 9:15 AM, Baoqiu Cui wrote:

> Carsten Dominik <carsten.dominik@gmail.com> writes:
>
>> Hi Baoqiu,
>>
>> I did apply the patch - by hand because the Emai program did wrap one
>> or two lines.
>>
>> Please check if everything went well.
>
> Thanks for the quick action, Carsten!  Your patch applying was  
> perfect,
> and you actually fixed an indentation problem in my original  
> patch. :-)

OK, good.  Thank you for your continued support of the docbook exporter.

If you really want to look into testing, check out

http://thread.gmane.org/gmane.emacs.orgmode/22689/focus=23131

and the links I provide in that thread.


- Carsten

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Re: #+LABEL: in HTML export
  2010-04-03  9:23         ` Carsten Dominik
@ 2010-04-03 16:46           ` Baoqiu Cui
  2010-04-04  6:53             ` Carsten Dominik
  0 siblings, 1 reply; 8+ messages in thread
From: Baoqiu Cui @ 2010-04-03 16:46 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: emacs-orgmode

Carsten Dominik <carsten.dominik@gmail.com> writes:

> On Apr 3, 2010, at 9:15 AM, Baoqiu Cui wrote:
>
>> Carsten Dominik <carsten.dominik@gmail.com> writes:
>>
>>> Hi Baoqiu,
>>>
>>> I did apply the patch - by hand because the Emai program did wrap one
>>> or two lines.
>>>
>>> Please check if everything went well.
>>
>> Thanks for the quick action, Carsten!  Your patch applying was
>> perfect,
>> and you actually fixed an indentation problem in my original
>> patch. :-)
>
> OK, good.  Thank you for your continued support of the docbook exporter.
>
> If you really want to look into testing, check out
>
> http://thread.gmane.org/gmane.emacs.orgmode/22689/focus=23131
>
> and the links I provide in that thread.

Thanks for the links, Carsten.

I did not notice the recent discussions about testing framework for
Org-mode.  Looks like some work is already done by different people.
I'll see what I can do starting from there.  (I was thinking about
regression test for different exporters only, which should be easier
than building a generic framework for testing all features of Org-mode.)

Thanks,

-- 
Baoqiu

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Re: #+LABEL: in HTML export
  2010-04-03 16:46           ` Baoqiu Cui
@ 2010-04-04  6:53             ` Carsten Dominik
  0 siblings, 0 replies; 8+ messages in thread
From: Carsten Dominik @ 2010-04-04  6:53 UTC (permalink / raw)
  To: Baoqiu Cui; +Cc: emacs-orgmode


On Apr 3, 2010, at 6:46 PM, Baoqiu Cui wrote:

> Carsten Dominik <carsten.dominik@gmail.com> writes:
>
>> On Apr 3, 2010, at 9:15 AM, Baoqiu Cui wrote:
>>
>>> Carsten Dominik <carsten.dominik@gmail.com> writes:
>>>
>>>> Hi Baoqiu,
>>>>
>>>> I did apply the patch - by hand because the Emai program did wrap  
>>>> one
>>>> or two lines.
>>>>
>>>> Please check if everything went well.
>>>
>>> Thanks for the quick action, Carsten!  Your patch applying was
>>> perfect,
>>> and you actually fixed an indentation problem in my original
>>> patch. :-)
>>
>> OK, good.  Thank you for your continued support of the docbook  
>> exporter.
>>
>> If you really want to look into testing, check out
>>
>> http://thread.gmane.org/gmane.emacs.orgmode/22689/focus=23131
>>
>> and the links I provide in that thread.
>
> Thanks for the links, Carsten.
>
> I did not notice the recent discussions about testing framework for
> Org-mode.  Looks like some work is already done by different people.
> I'll see what I can do starting from there.  (I was thinking about
> regression test for different exporters only, which should be easier
> than building a generic framework for testing all features of Org- 
> mode.)

That is correct.

- Carsten

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-04-04  6:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-28 20:29 #+LABEL: in HTML export Thomas S. Dye
2010-03-29 12:20 ` Carsten Dominik
2010-04-02 22:51   ` Baoqiu Cui
2010-04-03  6:33     ` Carsten Dominik
2010-04-03  7:15       ` Baoqiu Cui
2010-04-03  9:23         ` Carsten Dominik
2010-04-03 16:46           ` Baoqiu Cui
2010-04-04  6:53             ` Carsten Dominik

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).