emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* ODT export custom link colors?
@ 2011-12-14 17:34 Gary Oberbrunner
  2011-12-14 20:38 ` Christian Moe
  0 siblings, 1 reply; 5+ messages in thread
From: Gary Oberbrunner @ 2011-12-14 17:34 UTC (permalink / raw)
  To: Orgmode Mailing List

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

I use custom links like [[bgcolor:red][Warning!]] to add some color to my
documents.  I can export those colors to HTML and LaTeX like this:


(org-add-link-type
  "bgcolor"  nil
  (lambda (path desc format)
   (cond
    ((eq format 'html)
     (format"<span style=\"background-color:%s;\">%s</span>"  path desc))
    ((eq format 'latex)
     (format"\\colorbox{%s}{%s}"  path desc))
    (t
     (format"BGCOLOR LINK (%s): {%s}{%s}"  format path desc)))))

... but as you can see in the odt case I don't know what to put to get my
colors to come through.  Is there anything I can do there?  Is it some kind
of XML styling stanza?

(By the way, before I added my 't' case above, it returned nil, which
caused the odt exporter to blow up with an unhelpful error.  Would a patch
for that be considered too much of a corner-case?  I'd be happy to submit
one.)

-- 
-- Gary

[-- Attachment #2: Type: text/html, Size: 1173 bytes --]

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

* Re: ODT export custom link colors?
  2011-12-14 17:34 ODT export custom link colors? Gary Oberbrunner
@ 2011-12-14 20:38 ` Christian Moe
  2011-12-15  7:41   ` Jambunathan K
  0 siblings, 1 reply; 5+ messages in thread
From: Christian Moe @ 2011-12-14 20:38 UTC (permalink / raw)
  To: Gary Oberbrunner; +Cc: Orgmode Mailing List

Hi,

I'm not sure about this, because I don't really know the ODT spec, but 
I *think* you will have to define an ODT Character style for *each* 
color you want to use, using a consistent convention for naming these 
styles.

For instance, in the LibreOffice Styles and Formatting window, choose 
the Character styles tab, right-click on Default, select New. Name 
your style (e.g.) "Bgcolor red". Right-click it, select Modify, in the 
Background tab give it a red background.

Repeat for other colors you use, e.g. "Bgcolor blue", "Bgcolor yellow"...

Now, modify your custom link code as follows:

> (org-add-link-type
> "bgcolor"  nil
>    (lambda (path desc format)
>     (cond
>      ((eq format 'html)
>       (format"<span style=\"background-color:%s;\">%s</span>"  path desc))
>      ((eq format 'latex)
>       (format"\\colorbox{%s}{%s}"  path desc))
     ((eq format 'odt)
      (format "<text:span text:style-name=\"Bgcolor 
%s\">%s</text:span>" path desc))
>      (t
>       (format"BGCOLOR LINK (%s): {%s}{%s}"  format path desc)))))
>

(You can change the style-name in the format string to follow whatever 
naming convention you've adopted for your styles. If you want to call 
them simply "red", "blue" and so on, it would be text:style-name=\"%s\".)

(Judging from the manual, if you have space in your style names, like 
above, you should perhaps escape the spaces with _20_, but the 
"Bgcolor %s" above seems to work fine.)

Please report back if this works for you. If so, and depending on what 
Jambunathan might have to add, I'll look into updating the Worg examples.

> (By the way, before I added my 't' case above, it returned nil, which
> caused the odt exporter to blow up with an unhelpful error.  Would a
> patch for that be considered too much of a corner-case?  I'd be happy
> to submit one.)

I don't know what others think, but I think the habit of always 
providing one's custom links with an explicit fallback should be 
encouraged, if necessary by rude reminders from failing exporters...
:-)

hth,
Christian

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

* Re: ODT export custom link colors?
  2011-12-14 20:38 ` Christian Moe
@ 2011-12-15  7:41   ` Jambunathan K
  2011-12-15  9:03     ` Christian Moe
  0 siblings, 1 reply; 5+ messages in thread
From: Jambunathan K @ 2011-12-15  7:41 UTC (permalink / raw)
  To: mail; +Cc: Orgmode Mailing List, Gary Oberbrunner

Christian Moe <mail@christianmoe.com> writes:

> Hi,
>
> I'm not sure about this, because I don't really know the ODT spec, 

LibreOffice is my friend.

> For instance, in the LibreOffice Styles and Formatting window, choose
> the Character styles tab, right-click on Default, select New. Name
> your style (e.g.) "Bgcolor red". Right-click it, select Modify, in the
> Background tab give it a red background.

I usually put the cursor on the text that I am interested in, press F11
and switch to char styles or whatever category. The right style would be
highlighted which you can directly inherit from.

> Repeat for other colors you use, e.g. "Bgcolor blue", "Bgcolor yellow"...
>
> Now, modify your custom link code as follows:
>
>> (org-add-link-type
>> "bgcolor"  nil
>>    (lambda (path desc format)
>>     (cond
>>      ((eq format 'html)
>>       (format"<span style=\"background-color:%s;\">%s</span>"  path desc))
>>      ((eq format 'latex)
>>       (format"\\colorbox{%s}{%s}"  path desc))
>     ((eq format 'odt)
>      (format "<text:span text:style-name=\"Bgcolor
> %s\">%s</text:span>" path desc))
>>      (t
>>       (format"BGCOLOR LINK (%s): {%s}{%s}"  format path desc)))))
>>

The exact scenario you describe here is documented in the manual.

(info "(org) Creating one-off styles")
                                      ^ C-x C-e here 
Look at item 1.

The same node is here:
http://orgmode.org/org.html#Creating-one_002doff-styles

Instead of using an inline markup you can do something like this. 

#+begin_src emacs-lisp
(org-odt-format-fontify "This text is in red" "red-style")
#+end_src

It will mark the text in "red-style". You can similarly use this or this
for marking text in bold.

#+begin_src emacs-lisp
(org-odt-format-fontify "This text is in red" 'bold)
#+end_src

I believe you get the drift now.

Note: There are lot more convenience functions that start with
org-odt-format-* that I use internally to emit OpenDocument tags on the
go.

If you look at OrgOdtStyles.xml (C-h v org-odt-styles-dir) and you can
see a bunch of styles marked as "Org Agenda Styles". These are used for
marking TODO in red and DONE in green etc.

Copy & paste those styles, fix the name and background color and you are
done.

> (You can change the style-name in the format string to follow whatever
> naming convention you've adopted for your styles. If you want to call
> them simply "red", "blue" and so on, it would be
> text:style-name=\"%s\".)
>
> (Judging from the manual, if you have space in your style names, like
> above, you should perhaps escape the spaces with _20_, but the
> "Bgcolor %s" above seems to work fine.)
>
> Please report back if this works for you. If so, and depending on what
> Jambunathan might have to add, I'll look into updating the Worg
> examples.
>
>> (By the way, before I added my 't' case above, it returned nil, which
>> caused the odt exporter to blow up with an unhelpful error.  Would a
>> patch for that be considered too much of a corner-case?  I'd be happy
>> to submit one.)
>
> I don't know what others think, but I think the habit of always
> providing one's custom links with an explicit fallback should be
> encouraged, if necessary by rude reminders from failing exporters...
> :-)
>
> hth,
> Christian
>
>

-- 

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

* Re: ODT export custom link colors?
  2011-12-15  7:41   ` Jambunathan K
@ 2011-12-15  9:03     ` Christian Moe
  2011-12-20 22:01       ` Gary Oberbrunner
  0 siblings, 1 reply; 5+ messages in thread
From: Christian Moe @ 2011-12-15  9:03 UTC (permalink / raw)
  To: Jambunathan K; +Cc: Gary Oberbrunner, Orgmode Mailing List

On 12/15/11 8:41 AM, Jambunathan K wrote:
> I usually put the cursor on the text that I am interested in, press F11
> and switch to char styles or whatever category. The right style would be
> highlighted which you can directly inherit from.

Indeed, that's a better recipe. (On a Mac laptop keyboard, Cmd-T 
instead of F11.)

>
> The exact scenario you describe here is documented in the manual.
>
> (info "(org) Creating one-off styles")

The scenario was not mixing raw ODT XML in with Org, but using a 
custom link type to color text. The manual page you point to gives all 
the info one would need to figure out how to do it, and I should have 
given the reference. But the manual does not spell out exactly how to 
solve that scenario, so I thought that would be helpful.

> #+begin_src emacs-lisp
> (org-odt-format-fontify "This text is in red" "red-style")
> #+end_src
>
> It will mark the text in "red-style". You can similarly use this or this
> for marking text in bold.
>
> #+begin_src emacs-lisp
> (org-odt-format-fontify "This text is in red" 'bold)
> #+end_src

That's cool, but how do you suggest to use it? I tried it with 
=:exports results=, but that didn't work (the angle brackets got 
escaped).

But I probably misunderstood, and you meant to use it to generate the 
correct raw XML and then include the result in the text, with =@= 
signs added?

That works out of the box for the "bold" example, but not for 
"red-style" -- I assume we'd have to create that style first?

> If you look at OrgOdtStyles.xml (C-h v org-odt-styles-dir) and you can
> see a bunch of styles marked as "Org Agenda Styles". These are used for
> marking TODO in red and DONE in green etc.
>
> Copy&  paste those styles, fix the name and background color and you are
> done.

Thanks, that's helpful.

Yours,
Christian

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

* Re: ODT export custom link colors?
  2011-12-15  9:03     ` Christian Moe
@ 2011-12-20 22:01       ` Gary Oberbrunner
  0 siblings, 0 replies; 5+ messages in thread
From: Gary Oberbrunner @ 2011-12-20 22:01 UTC (permalink / raw)
  To: Orgmode Mailing List

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

Thanks guys -- I have it working.  I do wish there was a way to define odt
styles inline so I didn't have to edit my styles.xml but I guess that's
unavoidable (?).  I have the styles showing up in the odt style dialog, and
my inline odt code invokes it from my custom link type.  Thanks!

-- 
-- Gary

[-- Attachment #2: Type: text/html, Size: 348 bytes --]

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

end of thread, other threads:[~2011-12-20 22:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-14 17:34 ODT export custom link colors? Gary Oberbrunner
2011-12-14 20:38 ` Christian Moe
2011-12-15  7:41   ` Jambunathan K
2011-12-15  9:03     ` Christian Moe
2011-12-20 22:01       ` Gary Oberbrunner

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).