all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Automatically escaping single spaces
@ 2013-03-18 13:40 Suvayu Ali
  2013-03-18 16:31 ` Marcin Borkowski
  2013-03-19  3:59 ` Aaron Ecay
  0 siblings, 2 replies; 5+ messages in thread
From: Suvayu Ali @ 2013-03-18 13:40 UTC (permalink / raw)
  To: Emacs Org mode

Hi Orgers,

I use double spaces to demarcate end of sentences
(sentence-end-double-space t).  Now when I use things like "e.g. " or
"Fig. ", Emacs understands it is not the end of sentence and does the
"right thing", say for filling.  However when I export a phrase like
that from Org, say to LaTeX, I have to be mindful and write something
like this instead: "e.g.\space{}"[1].  Although this works, it is very
distracting while writing and prone to human error.  I would like some
seamless way for Org to respect my sentence-end-double-space setting
while exporting and export single spaces as single spaces.

Can someone suggest someway to get this to work?  It would be even more
awesome if this can be included in Org, i.e. respect
sentence-end-double-space in exported text by default.

Thanks for any ideas.

Cheers,


Footnotes:

[1] I have (org-entities-user '(("space" "~" nil " " " " " " " "))) in
    my Org settings.

-- 
Suvayu

Open source is the future. It sets us free.

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

* Re: Automatically escaping single spaces
  2013-03-18 13:40 Automatically escaping single spaces Suvayu Ali
@ 2013-03-18 16:31 ` Marcin Borkowski
  2013-03-19  3:59 ` Aaron Ecay
  1 sibling, 0 replies; 5+ messages in thread
From: Marcin Borkowski @ 2013-03-18 16:31 UTC (permalink / raw)
  To: emacs-orgmode

Dnia 2013-03-18, o godz. 14:40:24
Suvayu Ali <fatkasuvayu+linux@gmail.com> napisał(a):

> Hi Orgers,
> 
> I use double spaces to demarcate end of sentences
> (sentence-end-double-space t).  Now when I use things like "e.g. " or
> "Fig. ", Emacs understands it is not the end of sentence and does the
> "right thing", say for filling.  However when I export a phrase like
> that from Org, say to LaTeX, I have to be mindful and write something
> like this instead: "e.g.\space{}"[1].  Although this works, it is very
> distracting while writing and prone to human error.  I would like some
> seamless way for Org to respect my sentence-end-double-space setting
> while exporting and export single spaces as single spaces.
> 
> Can someone suggest someway to get this to work?  It would be even
> more awesome if this can be included in Org, i.e. respect
> sentence-end-double-space in exported text by default.

Hi,

A simple workaround would be to use \frenchspacing in your LaTeX
document (which typographic authorities suggest anyway - at least
Bringhurst).  The thing is, the algorithm LaTeX uses to determine
whether a period ends a sentence or not is completely different from
Emacs' one: for the TeX parser, any number of spaces effectively
collapses into one (at least, if no special measures are taken).

Anyway, you may also try "e.g.\nbsp{}this" to get a nonbreakable
space.  I'd also suggest changing your org-entities-user so that \space
maps to either "\space" or "\ " in LaTeX - this way you get breakable
spaces, too.

As a feature request: what about including (1) \frenchspacing in the
exported LaTeX file by default and (2) "\ " mapped to "\ " in LaTeX
export?

Anyway, for all people interested in the subject (from both
typographical and TeXnical points of view), I'd strongly suggest reading
through e.g. http://tex.stackexchange.com/q/4705/5626 .

Best,

> 
> Thanks for any ideas.
> 
> Cheers,
> 
> 
> Footnotes:
> 
> [1] I have (org-entities-user '(("space" "~" nil " " " " " " " "))) in
>     my Org settings.
> 



-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Adam Mickiewicz University

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

* Re: Automatically escaping single spaces
  2013-03-18 13:40 Automatically escaping single spaces Suvayu Ali
  2013-03-18 16:31 ` Marcin Borkowski
@ 2013-03-19  3:59 ` Aaron Ecay
  2013-03-19 15:20   ` Ivan Andrus
  1 sibling, 1 reply; 5+ messages in thread
From: Aaron Ecay @ 2013-03-19  3:59 UTC (permalink / raw)
  To: Suvayu Ali; +Cc: Emacs Org mode

Hi Suvayu,

I’ve had on my list of rainy day ideas for a while writing a function
for org-export-filter-plain-text-functions that would implement
something like this.  It should be as simple as doing a text replace,
either on “. [^ ]” sequences in general or only spaces after a given
list of abbreviations.  The advantage of the second approach is that it
could catch the case where “e.g.” is at the end of a line in the org
document.  (You’d also have to remove the newline: translate “e.g.\nfoo”
into “e.g.\ foo”).  Another advantage to pre-specifying is that you might
want a non-breaking space in “Fig.~1” but a breakable space in “e.g.\ foo”;
so you could keep two lists.

-- 
Aaron Ecay

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

* Re: Automatically escaping single spaces
  2013-03-19  3:59 ` Aaron Ecay
@ 2013-03-19 15:20   ` Ivan Andrus
  2013-03-19 16:05     ` Rasmus
  0 siblings, 1 reply; 5+ messages in thread
From: Ivan Andrus @ 2013-03-19 15:20 UTC (permalink / raw)
  To: Emacs Org mode

Oops, forgot to reply to the list.

On Mar 18, 2013, at 9:59 PM, Aaron Ecay <aaronecay@gmail.com> wrote:

> Hi Suvayu,
> 
> I’ve had on my list of rainy day ideas for a while writing a function
> for org-export-filter-plain-text-functions that would implement
> something like this.  It should be as simple as doing a text replace,
> either on “. [^ ]” sequences in general or only spaces after a given
> list of abbreviations.  The advantage of the second approach is that it
> could catch the case where “e.g.” is at the end of a line in the org
> document.  (You’d also have to remove the newline: translate “e.g.\nfoo”
> into “e.g.\ foo”).  Another advantage to pre-specifying is that you might
> want a non-breaking space in “Fig.~1” but a breakable space in “e.g.\ foo”;
> so you could keep two lists.

FWIW, You shouldn't have to worry about newlines.  If Emacs is setup properly they should never appear except at sentence boundaries. Which is to say, autofill and fill-paragraph know not to break lines in the middle of a sentence after punctuation.  If the user adds a newline manually you can assume they meant it to be a new sentence.  IIRC the variable at play is `sentence-end-double-space'.

-Ivan

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

* Re: Automatically escaping single spaces
  2013-03-19 15:20   ` Ivan Andrus
@ 2013-03-19 16:05     ` Rasmus
  0 siblings, 0 replies; 5+ messages in thread
From: Rasmus @ 2013-03-19 16:05 UTC (permalink / raw)
  To: emacs-orgmode

Ivan Andrus <darthandrus@gmail.com> writes:

> Oops, forgot to reply to the list.
>
> On Mar 18, 2013, at 9:59 PM, Aaron Ecay <aaronecay@gmail.com> wrote:
>
>> Hi Suvayu,
>> 
>> I’ve had on my list of rainy day ideas for a while writing a function
>> for org-export-filter-plain-text-functions that would implement
>> something like this.  It should be as simple as doing a text replace,
>> either on “. [^ ]” sequences in general or only spaces after a given
>> list of abbreviations.  The advantage of the second approach is that it
>> could catch the case where “e.g.” is at the end of a line in the org
>> document.  (You’d also have to remove the newline: translate “e.g.\nfoo”
>> into “e.g.\ foo”).  Another advantage to pre-specifying is that you might
>> want a non-breaking space in “Fig.~1” but a breakable space in “e.g.\ foo”;
>> so you could keep two lists.
>
> FWIW, You shouldn't have to worry about newlines.  If Emacs is setup
> properly they should never appear except at sentence boundaries. Which
> is to say, autofill and fill-paragraph know not to break lines in the
> middle of a sentence after punctuation.  If the user adds a newline
> manually you can assume they meant it to be a new sentence.  IIRC the
> variable at play is `sentence-end-double-space'.


I use something like this:

#+BEGIN_SRC emacs-lisp
(defun rasmus/latex-filter-double-space (text backend info)
  "Tries to export \"S1. S2\" as \"S1.~S2\",
   while letting \"S1.  S2\" be exported without tilde"
  (when (memq backend '(beamer latex))
    (replace-regexp-in-string "\\(\\. \\)\\{1\\}\\([^ ]\\)" ".~\\2" text)))

(add-to-list 'org-export-filter-final-output-functions
             'rasmus/latex-filter-double-space)
#+END_SRC

The list approach sounds better, I guess. . .   Indeed it does not
catch end of line stuff.


Here's a test case

#+BEGIN_SRC org
#+NAME:ref
#+BEGIN_SRC emacs-lisp
  (replace-regexp "\\(\\. \\)\\{1\\}\\([^ ]\\)" ".~\\2")
#+END_SRC

* Test 
  fig. 1 isn't here.  Here is double  space.  Fig.
  2 does not work
  fig. [[ref]] is also works

#+END_SRC 

which translate to 

#+BEGIN_SRC latex
\section[Test]{Test}
\label{sec-1}
fig.~1 isn't here.  Here is double  space.  Fig.
2 does not work
fig.~\ref{ref} is also works
#+END_SRC

–Rasmus

-- 
Hvor meget poesi tror De kommer ud af et glas isvand?

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

end of thread, other threads:[~2013-03-19 16:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-18 13:40 Automatically escaping single spaces Suvayu Ali
2013-03-18 16:31 ` Marcin Borkowski
2013-03-19  3:59 ` Aaron Ecay
2013-03-19 15:20   ` Ivan Andrus
2013-03-19 16:05     ` Rasmus

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.