emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rasmus <rasmus@gmx.us>
To: emacs-orgmode@gnu.org
Subject: Re: small caps
Date: Thu, 29 Oct 2015 21:37:28 +0100	[thread overview]
Message-ID: <87mvv12yyf.fsf@gmx.us> (raw)
In-Reply-To: CAN_Dec92RNWQ743SvSUa0Nam1eCYns9raitRKmJnXmF+LWDjYQ@mail.gmail.com

Matt Price <moptop99@gmail.com> writes:

> do we have a syntax for the "small caps" text attribute in Org? If not,
> should we? It is available in odt, html, and latex, and is used in some

I use the following filter(s) (second one is not essential).

Example input:

    CO_2
    fOO
    Fo1O
    /FoO/

Example output:

     \textsc{co}\(_{\text{2}}\)
     f\textsc{oo}
     \textsc{f}o1\textsc{o}
     \emph{\textsc{f}o\textsc{o}}

For emph to play nice with textsc in latex use the slantsc package.


    (defun rasmus/org-guess-textsc (content backend info)
        "Automatically downcase and wrap all-caps words in textsc.
    The function is a bit slow...

    TODO: Make the function work with headlines, but without doing it
    on subsequent text.

    TODO: Add ODT support."
        (if (org-export-derived-backend-p backend 'latex 'html)
            (let* (case-fold-search
                   (latexp (org-export-derived-backend-p backend 'latex))
                   (wrap (if latexp "\\textsc{%s}"
                             "<span class=\"small-caps\">%s</span>")))
              (replace-regexp-in-string
               "\\w+"
               (lambda (str)
                 (if (or (string-equal str (downcase str))
                         (string-equal str (capitalize str)))
                     str
                   (replace-regexp-in-string
                    "[[:upper:]]+"
                    (lambda (x) (format wrap (downcase x)))
                    str t t)))
               content t t))
          content))

    (add-to-list 'org-export-filter-plain-text-functions
                 'rasmus/org-guess-textsc)

    (defun rasmus/org-guess-textsc-html-cleanup-title (content backend info)
      (when (org-export-derived-backend-p backend 'html)
        (replace-regexp-in-string
         "<title>\\(.*\\)</title>"
         (lambda (str0)
           (format
            "<title>%s</title>"
            (replace-regexp-in-string
             "<span class=\"small-caps\">\\(.*?\\)</span>"
             (lambda (str) (upcase (match-string 1 str)))
             (match-string 1 str0))))
         content)))

-- 
⠠⠵

  parent reply	other threads:[~2015-10-29 20:37 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-29 16:39 small caps Matt Price
2015-10-29 16:47 ` Nicolas Goaziou
2015-10-29 16:55   ` Thomas S. Dye
2015-10-29 20:17     ` Matt Price
2015-10-29 20:42       ` Thomas S. Dye
2015-10-30 13:10         ` Christian Moe
2015-10-31 16:16           ` Matt Price
2015-10-29 17:25   ` Aaron Ecay
2015-10-29 17:39     ` Thomas S. Dye
2015-10-29 17:46       ` Nicolas Goaziou
2015-10-29 17:44     ` Nicolas Goaziou
2015-10-29 20:37 ` Rasmus [this message]
2015-10-29 21:18 ` Robert Klein

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mvv12yyf.fsf@gmx.us \
    --to=rasmus@gmx.us \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).