emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* small caps
@ 2015-10-29 16:39 Matt Price
  2015-10-29 16:47 ` Nicolas Goaziou
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Matt Price @ 2015-10-29 16:39 UTC (permalink / raw)
  To: Org Mode

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

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
bibliographic styles.

m

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

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

* Re: small caps
  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 17:25   ` Aaron Ecay
  2015-10-29 20:37 ` Rasmus
  2015-10-29 21:18 ` Robert Klein
  2 siblings, 2 replies; 13+ messages in thread
From: Nicolas Goaziou @ 2015-10-29 16:47 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode

Hello,

Matt Price <moptop99@gmail.com> writes:

> do we have a syntax for the "small caps" text attribute in Org?

No, we don't.

> If not, should we?

We cannot have a syntax for everything. A macro can probably replace
missing syntax. Also, you can hijack some emphasis marker (e.g., "+")
and have it do small caps in back-ends that support it (through
a filter, or a dedicated customization, e.g.
`org-latex-text-markup-alist').

Regards,

-- 
Nicolas Goaziou

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

* Re: small caps
  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 17:25   ` Aaron Ecay
  1 sibling, 1 reply; 13+ messages in thread
From: Thomas S. Dye @ 2015-10-29 16:55 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org Mode

Aloha Matt,

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Hello,
>
> Matt Price <moptop99@gmail.com> writes:
>
>> do we have a syntax for the "small caps" text attribute in Org?
>
> No, we don't.
>

I've been using this export filter, written by Eric Schulte.  It works
fine for my uses.

**** Eric Schulte's filter for HTML small caps

#+name: es-small-caps
#+begin_src emacs-lisp
;;; "sc" links for the \sc{} latex command
(defun org-export-html-small-caps (string backend channel)
  (when (org-export-derived-backend-p backend 'html)
    (let ((rx "{\\\\sc ")
          (fmt "<span style=\"font-variant:small-caps;\">%s</span>"))
      (with-temp-buffer
        (insert string)
        (goto-char (point-min))
        (while (re-search-forward rx nil t)
          (let* ((start (match-beginning 0))
                 (end (progn (goto-char start)
                             (forward-sexp)
                             (point)))
                 (content (buffer-substring (+ start 5) (- end 1))))
            (delete-region start end)
            (goto-char start)
            (insert (format fmt content))))
        (buffer-string)))))

(add-to-list 'org-export-filter-final-output-functions
             'org-export-html-small-caps)

(defun org-export-latex-sc (tree backend info)
  "Handle sc: links for latex export."
  (org-element-map tree 'link
    (lambda (object)
      (when (equal (org-element-property :type object) "sc")
        (org-element-insert-before
         (cond
          ((org-export-derived-backend-p backend 'latex)
           (list 'latex-fragment
                 (list :value (format "{\\sc %s}"
                                      (org-element-property :path object))
                       :post-blank (org-element-property
                                    :post-blank object))))
          ((org-export-derived-backend-p backend 'html)
           (list 'export-snippet
                 (list :back-end "html"
                       :value
                       (format "<span class=\"sc\">%s</span>"
                               (org-element-property :path object))
                       :post-blank
                       (org-element-property :post-blank object))))
          (:otherwise
           (error "unsupported backend for `org-export-latex-sc'")))
         object)
        (org-element-extract-element object))))
  tree)

(org-add-link-type "sc")

(add-hook 'org-export-filter-parse-tree-functions
          'org-export-latex-sc)

#+end_src

hth,
Tom

-- 
Thomas S. Dye
http://www.tsdye.com

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

* Re: small caps
  2015-10-29 16:47 ` Nicolas Goaziou
  2015-10-29 16:55   ` Thomas S. Dye
@ 2015-10-29 17:25   ` Aaron Ecay
  2015-10-29 17:39     ` Thomas S. Dye
  2015-10-29 17:44     ` Nicolas Goaziou
  1 sibling, 2 replies; 13+ messages in thread
From: Aaron Ecay @ 2015-10-29 17:25 UTC (permalink / raw)
  To: Nicolas Goaziou, Matt Price; +Cc: Org Mode

Hi Nicolas,

2015ko urriak 29an, Nicolas Goaziou-ek idatzi zuen:
> 
> Hello,
> 
> Matt Price <moptop99@gmail.com> writes:
> 
>> do we have a syntax for the "small caps" text attribute in Org?
> 
> No, we don't.
> 
>> If not, should we?
> 
> We cannot have a syntax for everything. A macro can probably replace
> missing syntax. 

This is true.  But small-caps are meaningful in a variety of contexts,
and they are not a truly new syntax (requiring extra code in the parser),
but rather can be handled exactly as the other emphasis markers.  (They
would require support from the exporters of course.)

There’s also no rush.  Maybe we could revisit the question of adding
small caps after the emphasis changes you indicated in the roadmap
thread are decided on.  Those might change the cost:benefit evaluation
for adding this feature.

(FWIW, I’d be in favor of the addition unless some major new consideration
is introduced by the emphasis changes.  A good proportion of the documents
I write in Org use small caps somehow.  It would be good to know for how
many other users that is the case.)

-- 
Aaron Ecay

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

* Re: small caps
  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
  1 sibling, 1 reply; 13+ messages in thread
From: Thomas S. Dye @ 2015-10-29 17:39 UTC (permalink / raw)
  To: Aaron Ecay; +Cc: Org Mode, Nicolas Goaziou

Aloha Aaron,

Aaron Ecay <aaronecay@gmail.com> writes:

> Hi Nicolas,
>
> 2015ko urriak 29an, Nicolas Goaziou-ek idatzi zuen:
>> 
>> Hello,
>> 
>> Matt Price <moptop99@gmail.com> writes:
>> 
>>> do we have a syntax for the "small caps" text attribute in Org?
>> 
>> No, we don't.
>> 
>>> If not, should we?
>> 
>> We cannot have a syntax for everything. A macro can probably replace
>> missing syntax. 
>
> This is true.  But small-caps are meaningful in a variety of contexts,
> and they are not a truly new syntax (requiring extra code in the parser),
> but rather can be handled exactly as the other emphasis markers.  (They
> would require support from the exporters of course.)
>
> There’s also no rush.  Maybe we could revisit the question of adding
> small caps after the emphasis changes you indicated in the roadmap
> thread are decided on.  Those might change the cost:benefit evaluation
> for adding this feature.
>
> (FWIW, I’d be in favor of the addition unless some major new consideration
> is introduced by the emphasis changes.  A good proportion of the documents
> I write in Org use small caps somehow.  It would be good to know for how
> many other users that is the case.)

I use them in almost all my archaeology writing where it is conventional
to make AD, BC, and BP small caps.

All the best,
Tom

-- 
Thomas S. Dye
http://www.tsdye.com

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

* Re: small caps
  2015-10-29 17:25   ` Aaron Ecay
  2015-10-29 17:39     ` Thomas S. Dye
@ 2015-10-29 17:44     ` Nicolas Goaziou
  1 sibling, 0 replies; 13+ messages in thread
From: Nicolas Goaziou @ 2015-10-29 17:44 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode

Aaron Ecay <aaronecay@gmail.com> writes:

> This is true.  But small-caps are meaningful in a variety of contexts,
> and they are not a truly new syntax (requiring extra code in the
> parser),

Of course they do. You need to introduce yet another emphasis marker.


Regards,

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

* Re: small caps
  2015-10-29 17:39     ` Thomas S. Dye
@ 2015-10-29 17:46       ` Nicolas Goaziou
  0 siblings, 0 replies; 13+ messages in thread
From: Nicolas Goaziou @ 2015-10-29 17:46 UTC (permalink / raw)
  To: Thomas S. Dye; +Cc: Aaron Ecay, Org Mode

Hello,

Thomas S. Dye <tsd@tsdye.com> writes:

> I use them in almost all my archaeology writing where it is conventional
> to make AD, BC, and BP small caps.

I assume you are using PDF output. You can modify
`org-latex-text-markup-alist' or use

  #+MACRO: ad \textsc{ad}

and so on.


Regards,

-- 
Nicolas Goaziou

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

* Re: small caps
  2015-10-29 16:55   ` Thomas S. Dye
@ 2015-10-29 20:17     ` Matt Price
  2015-10-29 20:42       ` Thomas S. Dye
  0 siblings, 1 reply; 13+ messages in thread
From: Matt Price @ 2015-10-29 20:17 UTC (permalink / raw)
  Cc: Org Mode

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

Tom,

Am I right that this should turn
{sc hello}

into

<span style=\"font-variant:small-caps;\">hello</span>

?

If so, it doesn't seem to be working for me so far.  Thanks,
m


On Thu, Oct 29, 2015 at 12:55 PM, Thomas S. Dye <tsd@tsdye.com> wrote:

> Aloha Matt,
>
> Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>
> > Hello,
> >
> > Matt Price <moptop99@gmail.com> writes:
> >
> >> do we have a syntax for the "small caps" text attribute in Org?
> >
> > No, we don't.
> >
>
> I've been using this export filter, written by Eric Schulte.  It works
> fine for my uses.
>
> **** Eric Schulte's filter for HTML small caps
>
> #+name: es-small-caps
> #+begin_src emacs-lisp
> ;;; "sc" links for the \sc{} latex command
> (defun org-export-html-small-caps (string backend channel)
>   (when (org-export-derived-backend-p backend 'html)
>     (let ((rx "{\\\\sc ")
>           (fmt "<span style=\"font-variant:small-caps;\">%s</span>"))
>       (with-temp-buffer
>         (insert string)
>         (goto-char (point-min))
>         (while (re-search-forward rx nil t)
>           (let* ((start (match-beginning 0))
>                  (end (progn (goto-char start)
>                              (forward-sexp)
>                              (point)))
>                  (content (buffer-substring (+ start 5) (- end 1))))
>             (delete-region start end)
>             (goto-char start)
>             (insert (format fmt content))))
>         (buffer-string)))))
>
> (add-to-list 'org-export-filter-final-output-functions
>              'org-export-html-small-caps)
>
> (defun org-export-latex-sc (tree backend info)
>   "Handle sc: links for latex export."
>   (org-element-map tree 'link
>     (lambda (object)
>       (when (equal (org-element-property :type object) "sc")
>         (org-element-insert-before
>          (cond
>           ((org-export-derived-backend-p backend 'latex)
>            (list 'latex-fragment
>                  (list :value (format "{\\sc %s}"
>                                       (org-element-property :path object))
>                        :post-blank (org-element-property
>                                     :post-blank object))))
>           ((org-export-derived-backend-p backend 'html)
>            (list 'export-snippet
>                  (list :back-end "html"
>                        :value
>                        (format "<span class=\"sc\">%s</span>"
>                                (org-element-property :path object))
>                        :post-blank
>                        (org-element-property :post-blank object))))
>           (:otherwise
>            (error "unsupported backend for `org-export-latex-sc'")))
>          object)
>         (org-element-extract-element object))))
>   tree)
>
> (org-add-link-type "sc")
>
> (add-hook 'org-export-filter-parse-tree-functions
>           'org-export-latex-sc)
>
> #+end_src
>
> hth,
> Tom
>
> --
> Thomas S. Dye
> http://www.tsdye.com
>

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

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

* Re: small caps
  2015-10-29 16:39 small caps Matt Price
  2015-10-29 16:47 ` Nicolas Goaziou
@ 2015-10-29 20:37 ` Rasmus
  2015-10-29 21:18 ` Robert Klein
  2 siblings, 0 replies; 13+ messages in thread
From: Rasmus @ 2015-10-29 20:37 UTC (permalink / raw)
  To: emacs-orgmode

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

-- 
⠠⠵

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

* Re: small caps
  2015-10-29 20:17     ` Matt Price
@ 2015-10-29 20:42       ` Thomas S. Dye
  2015-10-30 13:10         ` Christian Moe
  0 siblings, 1 reply; 13+ messages in thread
From: Thomas S. Dye @ 2015-10-29 20:42 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode

Aloha Matt,

Matt Price <moptop99@gmail.com> writes:

> Tom,
>
> Am I right that this should turn
> {sc hello}
>
> into
>
> <span style=\"font-variant:small-caps;\">hello</span>
>
> ?
>
> If so, it doesn't seem to be working for me so far.  Thanks,
> m

Sorry, I forgot to give an example.  I use it like this [[sc:ad][AD]].

The advantage of a link over a macro is that the link should export
correctly to both LaTeX and HTML.

If you intend to export to a single backend, then Nicolas' suggestion to
use a macro is simpler.

All the best,
Tom
-- 
Thomas S. Dye
http://www.tsdye.com

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

* Re: small caps
  2015-10-29 16:39 small caps Matt Price
  2015-10-29 16:47 ` Nicolas Goaziou
  2015-10-29 20:37 ` Rasmus
@ 2015-10-29 21:18 ` Robert Klein
  2 siblings, 0 replies; 13+ messages in thread
From: Robert Klein @ 2015-10-29 21:18 UTC (permalink / raw)
  To: moptop99; +Cc: emacs-orgmode

Hi,

Matt Price wrote:
> 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
> bibliographic styles. 


You can add a link type, e.g.:

#+begin_src emacs-lisp
  (org-add-link-type
   "fm" nil
   (lambda (path desc format)
     (cond
      ((eq format 'html)
       (cond
        ((equal path "sc")
         (format "<span style=\"font-variant:small-caps;\">%s</span>"
                 desc))
        ((equal path "it")
         (format "<em>%s</em>" desc))
        ((equal path "bf")
         (format "<strong>%s</strong>" desc))
        ((equal path "tt")
         (format "<kbd>%s</kbd>" desc))
        (t (format "%s" desc))))
      ;; "</span>" )))
      ((eq format 'latex)
       (format "\\text%s{%s}" path desc))
      ((eq format 'odt)
       (cond
        ((equal path "sc")
         (format "<span style=\"font-variant:small-caps;\">hello</span>" desc))
        ;; more code for it, bf, tt etc.
        ))
      (t Y))))
#+end_src

The odt stuff I typed right into this mail, so it probably doesn't
word out of the box. (don't ask me about the "(t Y)" at the end; don't
know...)

Anyway, now you can use small capitals as [[fm:sc][ad]] and you get
"ad" in small caps.

For my documents I set the following macros for small capitals and
teletype:

#+Macro: sc [[fm:sc][$1]]
#+Macro: tt [[fm:tt][$1]]

Now you can use the macros like {{{sc(ad)}}} or {{{sc(Text in Small
Caps)}}}. Note, the uppercase letters will remain uppercase.

Best regards
Robert

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

* Re: small caps
  2015-10-29 20:42       ` Thomas S. Dye
@ 2015-10-30 13:10         ` Christian Moe
  2015-10-31 16:16           ` Matt Price
  0 siblings, 1 reply; 13+ messages in thread
From: Christian Moe @ 2015-10-30 13:10 UTC (permalink / raw)
  To: Thomas S. Dye; +Cc: Org Mode


Thomas S. Dye writes:

> Sorry, I forgot to give an example.  I use it like this [[sc:ad][AD]].
>
> The advantage of a link over a macro is that the link should export
> correctly to both LaTeX and HTML.
>
> If you intend to export to a single backend, then Nicolas' suggestion to
> use a macro is simpler.

Though you could support multiple backends with a macro, too, you just
need to use lots of @'s. E.g.:


#+MACRO: sc @@latex:\textsc{$1}@@@@html:<span style="font-variant:
 small-caps;">$1</span>@@

Already in 400 {{{sc(bc)}}}, the Greeks...


That's for a quick example; better to use <span class="smallcaps"> or
something and put the CSS in a separate stylesheet, of course.

Yours,
Christian

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

* Re: small caps
  2015-10-30 13:10         ` Christian Moe
@ 2015-10-31 16:16           ` Matt Price
  0 siblings, 0 replies; 13+ messages in thread
From: Matt Price @ 2015-10-31 16:16 UTC (permalink / raw)
  Cc: Org Mode

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

On Oct 30, 2015 09:09, "Christian Moe" <mail@christianmoe.com> wrote:
>
>
> Thomas S. Dye writes:
>
> > Sorry, I forgot to give an example.  I use it like this [[sc:ad][AD]].
> >
> > The advantage of a link over a macro is that the link should export
> > correctly to both LaTeX and HTML.
> >
> > If you intend to export to a single backend, then Nicolas' suggestion to
> > use a macro is simpler.
>
> Though you could support multiple backends with a macro, too, you just
> need to use lots of @'s. E.g.:
>
>
> #+MACRO: sc @@latex:\textsc{$1}@@@@html:<span style="font-variant:
>  small-caps;">$1</span>@@
>
> Already in 400 {{{sc(bc)}}}, the Greeks...
>
>
> That's for a quick example; better to use <span class="smallcaps"> or
> something and put the CSS in a separate stylesheet, of couse

thanks everyone for all the suggestions, I will try out a few of them and
decide which seems most natural for me. But in any event I've learned a bit
about macros and custom links, which has been great.

Matt
>
> Yours,
> Christian

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

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

end of thread, other threads:[~2015-10-31 16:16 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2015-10-29 21:18 ` Robert Klein

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