Good remainder :-)
Just a small addition...

On Sat, 11 Apr 2026 at 13:24, Christian Moe <[email protected]> wrote:

> Perry Smith <[email protected]> writes:
> > TL; DR — How is the color of individual words and phrases specified in
> > such a way that the Emacs buffer shows the color as well as the final
> > exported documents in HTML and PDF?
> (...)
> > My main objective is that the documentation in final form be available
> > on the web as HTML as well as offline preferable as PDF and EPUB.
> (...)
> > I would like to be able to have individual words and phrases colored
> > such as red and green. It would be nice that the proper color be shown
> > in the Emacs buffer as well as in the exported final result.
> >
> > I just assumed that Org mode would have some special sequence for
> > doing this but it seems it does not. (...)
>
> Hi, Perry,
>
> True, Org mode does not have a built-in syntax for coloring text. But it
> does afford several possible ways to do it, e.g. with a macro or a
> custom link type.
>
> The Org FAQ has example code for a custom 'color:' link type that
> exports text in arbitrary colors to HTML and LaTeX.
> https://orgmode.org/worg/org-faq.html#custom-colors-in-export
>
> By adding the example code to your init, you can do e.g.
>
> : The quick [[color:brown][fox]] jumped over the lazy dog
>
> to get the word 'fox' colored brown.
>
> I have just updated the code with a :face parameter to color the link
> accordingly in the buffer as well, but the web version of the FAQ isn't
> updating at the moment for some reason, so I include the listing here:
>
> #+BEGIN_SRC emacs-lisp
> (org-link-set-parameters
>  "color"
>  :follow
>  (lambda (path)
>    (message (concat "color "
>                     (progn (add-text-properties
>                             0 (length path)
>                             (list 'face `((t (:foreground ,path))))
>                             path) path))))
>  :export
>  (lambda (path desc format)
>    (cond
>     ((org-export-derived-backend-p format 'html)
>      (format "<span style=\"color:%s;\">%s</span>" path desc))
>     ((org-export-derived-backend-p format 'latex)
>      (format "{\\color{%s}%s}" path desc))))
>  :face
>   (lambda (path)
>     (list `(:foreground ,path))))
> #+END_SRC
>
> Color names differ across Emacs faces, LaTeX, and HTML, but this will
> work at least for the basic color names. One way to extend the range of
> compatible color names is using the header
> '\usepackage[x11names]{xcolor}' in LaTeX.
>
I add to my .emacs

#+BEGIN_SRC emacs-lisp
  (add-to-list 'org-latex-packages-alist '("" "xcolor"))
#+END_SRC

And then I can
#+LATEX_CLASS_PRE: \PassOptionsToPackage{x11names}{xcolor}
which will also work nicely with beamer presentations, where the xcolor
package is added silently and usepackage doesn't have any effect.

And in case you need this for presentations too, don't forget to check for
the beamer backend:

    ((org-export-derived-backend-p format 'beamer)
     (format "{\\color{%s}%s}" path desc)))
    ((org-export-derived-backend-p format 'latex)
     (format "{\\color{%s}%s}" path desc))))

Well, just a matter of taste, but I use "\\textcolor{%s}{%s}" as the format
string. But that's more a matter of taste and ways of working in the last
20 years ;-)

Discussion has been going on for some time on adding a new extensible
> syntax ('special inline blocks') that might be useful for this sort of
> thing, but for now custom link types are a convenient way.
>
> Regards,
> Christian
>

Just my .2 cents, /PA


-- 
Fragen sind nicht da, um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler

"Sagen's Paradeiser" (ORF: Als Radiohören gefährlich war) => write BE!
Year 2 of the New Koprocracy

Reply via email to