On 2015-09-22, at 22:17, Marcin Borkowski <mb...@mbork.pl> wrote:

> On 2015-09-14, at 16:42, Dan Griswold <kc5...@gmail.com> wrote:
>
>> How should I mark in org mode that I want a space following a period
>> concluding an abbreviation to be seen by LaTeX as an interword space?
>
> #+LATEX_HEADER: \frenchspacing
>
> and never worry again.
>
> OTOH, it would be relatively easy to write a filter which converts Emacs
> rules wrt. spaces (single/double space) into LaTeX ones.

And here it is:

--8<---------------cut here---------------start------------->8---
;; Convert single spaces after periods etc. to "\ " when exporting to LaTeX

(defun my-latex-filter-nonfrenchspacing (text backend info)
  "Convert single spaces after dots to \"\ \"."
  (when (and (org-export-derived-backend-p backend 'latex)
             sentence-end-double-space)
    (replace-regexp-in-string
     (concat "\\(" sentence-end-base "\\)"
             "[ \u00a0]\\([^ \t\u00a0\n]\\)")
     "\\1\\\\ \\2" text)))

(add-to-list 'org-export-filter-plain-text-functions
             'my-latex-filter-nonfrenchspacing)
--8<---------------cut here---------------end--------------->8---

It is a bit simplistic (after all, I wrote it just now in 15 minutes),
but it seems to work fine.  It makes a few assumptions, though.  One of
them is that you don't mess with sentence-end-base too much: I assumed
that there are no non-shy groups there.  (By default there are not, and
I don't see any reason for them to be there, but what do I know.)  Also,
I assume that for the period to /not/ end the sentence, it should be
followed by one space and something non-spacey.

Probably the biggest drawback is that non-breaking spaces get converted
to breaking ones.  However, if you care about those, you can always
use the filter given in the example for filters in the Org manual, and
make sure it runs before the above one.  (TeX considers tildes as
normal-sized spaces.)

Also, note that while Emacs' way of differentiating between
a sentence-ending period and a non-sentence-ending period are fairly
simple, (La)TeX's rules are a bit more complicated (look up "space
factor" in The TeXbook).  For instance, LaTeX assumes that a period
after a capital letter /never/ ends the sentence, and you have to use \@
before such period to change that.  The algorithm TeX uses is really
clever, and can be (ab)used in funny ways to do funny stuff in
low-level, hackish TeX ways (been there, done that - for instance, when
I once reimplemented the theorem-like environments, I used space factor
to make sure that if a theorem begins with an enumeration, it looks
fine.  The "standard" LaTeX implementation of theorem-like environments
is kind of crazy, even if it works in typical cases.  Try typesetting
a theorem with a long optional argument in a narrow column and see what
happens, for instance.).

TL;DR: just use \frenchspacing.  Everyone will be happier.

Hth,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University

Reply via email to