Re: [O] small caps

2015-10-31 Thread Matt Price
On Oct 30, 2015 09:09, "Christian Moe"  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:$1@@
>
> Already in 400 {{{sc(bc)}}}, the Greeks...
>
>
> That's for a quick example; better to use  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


Re: [O] small caps

2015-10-30 Thread Christian Moe

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:$1@@

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


That's for a quick example; better to use  or
something and put the CSS in a separate stylesheet, of course.

Yours,
Christian



Re: [O] small caps

2015-10-29 Thread Nicolas Goaziou
Hello,

Matt Price  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



Re: [O] small caps

2015-10-29 Thread Thomas S . Dye
Aloha Aaron,

Aaron Ecay  writes:

> Hi Nicolas,
>
> 2015ko urriak 29an, Nicolas Goaziou-ek idatzi zuen:
>> 
>> Hello,
>> 
>> Matt Price  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



Re: [O] small caps

2015-10-29 Thread Aaron Ecay
Hi Nicolas,

2015ko urriak 29an, Nicolas Goaziou-ek idatzi zuen:
> 
> Hello,
> 
> Matt Price  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



Re: [O] small caps

2015-10-29 Thread Nicolas Goaziou
Aaron Ecay  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,



Re: [O] small caps

2015-10-29 Thread Thomas S . Dye
Aloha Matt,

Nicolas Goaziou  writes:

> Hello,
>
> Matt Price  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 "%s"))
  (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 "%s"
   (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



Re: [O] small caps

2015-10-29 Thread Matt Price
Tom,

Am I right that this should turn
{sc hello}

into

hello

?

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  wrote:

> Aloha Matt,
>
> Nicolas Goaziou  writes:
>
> > Hello,
> >
> > Matt Price  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 "%s"))
>   (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 "%s"
>(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
>


Re: [O] small caps

2015-10-29 Thread Robert Klein
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 "%s"
 desc))
((equal path "it")
 (format "%s" desc))
((equal path "bf")
 (format "%s" desc))
((equal path "tt")
 (format "%s" desc))
(t (format "%s" desc
  ;; "" )))
  ((eq format 'latex)
   (format "\\text%s{%s}" path desc))
  ((eq format 'odt)
   (cond
((equal path "sc")
 (format "hello" 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



Re: [O] small caps

2015-10-29 Thread Rasmus
Matt Price  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}"
 "%s")))
  (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
 "\\(.*\\)"
 (lambda (str0)
   (format
"%s"
(replace-regexp-in-string
 "\\(.*?\\)"
 (lambda (str) (upcase (match-string 1 str)))
 (match-string 1 str0
 content)))

-- 
⠠⠵




Re: [O] small caps

2015-10-29 Thread Thomas S . Dye
Aloha Matt,

Matt Price  writes:

> Tom,
>
> Am I right that this should turn
> {sc hello}
>
> into
>
> hello
>
> ?
>
> 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



Re: [O] small caps

2015-10-29 Thread Nicolas Goaziou
Hello,

Thomas S. Dye  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