emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* LaTeX-export: letters after $..$ turn off math-mode
@ 2012-02-06 18:32 Daniel Schoepe
  2012-02-06 19:23 ` Achim Gratz
  0 siblings, 1 reply; 10+ messages in thread
From: Daniel Schoepe @ 2012-02-06 18:32 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi,

I have the following issue: If I write something like `$n$th' in an org
file and then export it to LaTeX, it will produce `\$n\$th', whereas I
would like it to export this as `$n$th'. Is there some way I can disable
escaping of dollar signs entirely (Leaving it to me to escape them, when
I don't use them as math-mode delimiters)?

I did not find any option to that end in the documentation, but it's of
course possible that I just overlooked it.

Cheers,
Daniel


[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]

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

* Re: LaTeX-export: letters after $..$ turn off math-mode
  2012-02-06 18:32 LaTeX-export: letters after $..$ turn off math-mode Daniel Schoepe
@ 2012-02-06 19:23 ` Achim Gratz
  0 siblings, 0 replies; 10+ messages in thread
From: Achim Gratz @ 2012-02-06 19:23 UTC (permalink / raw)
  To: emacs-orgmode

Daniel Schoepe <daniel@schoepe.org> writes:
> I have the following issue: If I write something like `$n$th' in an org
> file and then export it to LaTeX, it will produce `\$n\$th', whereas I
> would like it to export this as `$n$th'. Is there some way I can disable
> escaping of dollar signs entirely (Leaving it to me to escape them, when
> I don't use them as math-mode delimiters)?

Using proper LaTeX math delimiters instead of that TeXism works nicely:
\(n\)th (the other TeXism, $n${}th also doesn't work).  In an UTF-8
document, a zero-width space would probably work too, but that's
devious.


HTH,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Factory and User Sound Singles for Waldorf Blofeld:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds

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

* Re: LaTeX-export: letters after $..$ turn off math-mode
@ 2013-02-04 11:51 Greg Minshall
  2013-02-15 22:04 ` Bastien
  0 siblings, 1 reply; 10+ messages in thread
From: Greg Minshall @ 2013-02-04 11:51 UTC (permalink / raw)
  To: emacs-orgmode

hi.  this was on the list a year ago (see below).

i'd like to plead the case of allowing the user to suppress dollar-sign
behavior (or, force dollar-signs to mean math-mode).

the main reason is convenience: when trying to quickly write up
thoughts, typing "$ a = b^2 $" is just that much more convenient/easier
than typing "\( a = b^2 \)".  (maybe because the former uses half the
number of "off-home-row" keys?  maybe just because my fingers are
programmed to do this?)

second, (this is rhetoric) why privilege the dollar currency?  third
(more rhetoric), there are certainly many communities that believe that
$..$ is equivalent to \(..\), so new users will continually show up thus
programmed.

so, if there were a way of disabling the current dollar sign processing,
that would be great!

cheers, Greg
----
http://lists.gnu.org/archive/html/emacs-orgmode/2012-02/msg00269.html
----
> Daniel Schoepe <address@hidden> writes:
>> I have the following issue: If I write something like `$n$th' in an
>> org file and then export it to LaTeX, it will produce `\$n\$th',
>> whereas I would like it to export this as `$n$th'. Is there some way
>> I can disable escaping of dollar signs entirely (Leaving it to me to
>> escape them, when I don't use them as math-mode delimiters)?

> Using proper LaTeX math delimiters instead of that TeXism works
> nicely: \(n\)th (the other TeXism, $n${}th also doesn't work).  In an
> UTF-8 document, a zero-width space would probably work too, but that's
> devious.

> HTH,
> Achim.

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

* Re: LaTeX-export: letters after $..$ turn off math-mode
  2013-02-04 11:51 Greg Minshall
@ 2013-02-15 22:04 ` Bastien
  2013-02-16  7:25   ` Nicolas Goaziou
  0 siblings, 1 reply; 10+ messages in thread
From: Bastien @ 2013-02-15 22:04 UTC (permalink / raw)
  To: Greg Minshall; +Cc: emacs-orgmode

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

Hi Greg,

Greg Minshall <minshall@umich.edu> writes:

> i'd like to plead the case of allowing the user to suppress dollar-sign
> behavior (or, force dollar-signs to mean math-mode).

I'm attaching a patch that introduces `org-latex-escape-chars' which
would allow you to bind it to something different for each buffer --
e.g., without the dollar sign.

Nicolas, let me know if this looks okay for you.

Thanks,


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: ox-latex-escape-char.patch --]
[-- Type: text/x-patch, Size: 1098 bytes --]

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 9d5b5c5..805eeb7 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -510,6 +510,14 @@ default we use here encompasses both."
   :group 'org-export-latex
   :type 'string)
 
+(defcustom org-latex-escape-chars "%$#&{}~^_"
+  "Characters to escape.
+Each character in this string will be escaped.
+E.g., _ will be escaped into \_."
+  :group 'org-export-latex
+  :version "24.3"
+  :type 'string)
+
 
 ;;;; Tables
 
@@ -1942,8 +1950,11 @@ TEXT is the string to transcode.  INFO is a plist holding
 contextual information."
   (let ((specialp (plist-get info :with-special-strings))
 	(output text))
-    ;; Protect %, #, &, $, ~, ^, _,  { and }.
-    (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" output)
+    ;; Protect characters from `org-latex-escape-chars', i.e.,
+    ;; %, #, &, $, ~, ^, _, { and } by default.
+    (while (string-match
+	    (concat "\\([^\\]\\|^\\)\\([" org-latex-escape-chars "]\\)")
+	    output)
       (setq output
 	    (replace-match
 	     (format "\\%s" (match-string 2 output)) nil t output 2)))

[-- Attachment #3: Type: text/plain, Size: 14 bytes --]


-- 
 Bastien

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

* Re: LaTeX-export: letters after $..$ turn off math-mode
  2013-02-15 22:04 ` Bastien
@ 2013-02-16  7:25   ` Nicolas Goaziou
  2013-02-16 11:48     ` Nicolas Goaziou
  2013-02-16 14:32     ` Bastien
  0 siblings, 2 replies; 10+ messages in thread
From: Nicolas Goaziou @ 2013-02-16  7:25 UTC (permalink / raw)
  To: Bastien; +Cc: Greg Minshall, emacs-orgmode

Hello,

Bastien <bzg@altern.org> writes:

> Greg Minshall <minshall@umich.edu> writes:
>
>> i'd like to plead the case of allowing the user to suppress dollar-sign
>> behavior (or, force dollar-signs to mean math-mode).
>
> I'm attaching a patch that introduces `org-latex-escape-chars' which
> would allow you to bind it to something different for each buffer --
> e.g., without the dollar sign.
>
> Nicolas, let me know if this looks okay for you.

I think this solution is not appropriate.

Even if you patch latex back-end, the rest of Org still doesn't
recognize the construct as a math snippet. So, this would be a mere
hack.

A correct solution would be to modify `org-latex-regexps' so math
snippets can be followed by a letter. But you may find yourself opening
a can of worm. Getting there regexps right is difficult, as can probably
testify Carsten.

IMO, I would call that an Org limitation. Org is not LaTeX, even if it
provides many LaTeX facilities. Also, the OP's problem can be solved in
many ways under Emacs. For example, I use "mt" (both "m" and "t" are on
my home row) as a snippet to insert "\(\)" in an Org buffer and put
point inside.


Regards,

-- 
Nicolas Goaziou

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

* Re: LaTeX-export: letters after $..$ turn off math-mode
  2013-02-16  7:25   ` Nicolas Goaziou
@ 2013-02-16 11:48     ` Nicolas Goaziou
  2013-02-16 16:33       ` Nick Dokos
  2013-02-16 14:32     ` Bastien
  1 sibling, 1 reply; 10+ messages in thread
From: Nicolas Goaziou @ 2013-02-16 11:48 UTC (permalink / raw)
  To: Bastien; +Cc: Greg Minshall, emacs-orgmode

Completing myself,

> IMO, I would call that an Org limitation. Org is not LaTeX, even if it
> provides many LaTeX facilities. Also, the OP's problem can be solved in
> many ways under Emacs. For example, I use "mt" (both "m" and "t" are on
> my home row) as a snippet to insert "\(\)" in an Org buffer and put
> point inside.

I would even go further. The following text has been in documentation
for years:

   * Text within the usual LaTeX math delimiters.  To avoid conflicts
     with currency specifications, single `$' characters are only
     recognized as math delimiters if the enclosed text contains at
     most two line breaks, is directly attached to the `$' characters
     with no whitespace in between, and if the closing `$' is followed
     by whitespace, punctuation or a dash.  For the other delimiters,
     there is no such restriction, so when in doubt, use `\(...\)' as
     inline math delimiters.

and so has been this excerpt from `org-inside-LaTeX-fragment-p'
docstring:

   Even though the matchers for math are configurable, this function assumes
   that \\begin, \\(, \\[, and $$ are always used.  Only the single dollar
   delimiters are skipped when they have been removed by customization.

   This function does a reasonably good job, but can locally be fooled by
   for example currency specifications.  For example it will assume being in
   inline math after \"$22.34\".  The LaTeX fragment formatter will only format
   fragments that are properly closed, but during editing, we have to live
   with the uncertainty caused by missing closing delimiters.

We cannot afford two maintain two implementations, one of them being
frail, of the _same concept_. It's way better to focus on one of them,
and make sure it is solid. It also means a slightly lighter Org, and
less code to debug, which is always good.

Thus, I suggest to announce that $ (both $ and $$, even though $$ don't
have problems /per se/) symbols for should be avoided. Then, in a year
or so, we can remove them completely from code base.


Regards,

-- 
Nicolas Goaziou

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

* Re: LaTeX-export: letters after $..$ turn off math-mode
  2013-02-16  7:25   ` Nicolas Goaziou
  2013-02-16 11:48     ` Nicolas Goaziou
@ 2013-02-16 14:32     ` Bastien
  2013-02-16 15:26       ` Rasmus
  1 sibling, 1 reply; 10+ messages in thread
From: Bastien @ 2013-02-16 14:32 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Greg Minshall, emacs-orgmode

Hi Nicolas,

Nicolas Goaziou <n.goaziou@gmail.com> writes:

> IMO, I would call that an Org limitation. 

I'm fine with the current limitation -- if that's just one email
per year, I think we can handle this :)

FWIW I'm not in favor of removing the ability to inline $x^2$
and to deprecate the use of $ completely.  If this flexibility
is not too problematic (from a maintainance point of view), I'd
say it's fine to keep it.

Thanks,

-- 
 Bastien

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

* Re: LaTeX-export: letters after $..$ turn off math-mode
  2013-02-16 14:32     ` Bastien
@ 2013-02-16 15:26       ` Rasmus
  0 siblings, 0 replies; 10+ messages in thread
From: Rasmus @ 2013-02-16 15:26 UTC (permalink / raw)
  To: emacs-orgmode

Bastien <bzg@altern.org> writes:

> FWIW I'm not in favor of removing the ability to inline $x^2$
> and to deprecate the use of $ completely.  If this flexibility
> is not too problematic (from a maintainance point of view), I'd
> say it's fine to keep it.

While I agree that \(·\) is the preferred and Rightᵀᴹ delimiter pair I
almost always use $·$ in place if I can get away with it.  Thus, if
the maintenance cost is low I would prefer if it stayed.

Using the patch posted by Nicolas last week (i.e. (re)introducing
org-highlight-latex-and-special) there's even visual feedback as to
when Org will correctly identify $·$.

/If/ a mechanism existed to easily use \(·\) I would be all for
ditching $·$ as it clearly inferior (legacy documents can quickly be
fixed via a regexp replacement, if needed).  For instance, in ESS
there is ess-smart-underscore where, depending on the context,
pressing "_" will usually do the right thing.  For Instance $ could
insert \(·\) or $ first (depending on the variable
org-export-care-about-usd).  On region it would always put it inside
\(·\).  But it might be messy, I'm not really sure. 

–Rasmus

-- 
C is for Cookie

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

* Re: LaTeX-export: letters after $..$ turn off math-mode
  2013-02-16 11:48     ` Nicolas Goaziou
@ 2013-02-16 16:33       ` Nick Dokos
  2013-02-16 16:45         ` Nick Dokos
  0 siblings, 1 reply; 10+ messages in thread
From: Nick Dokos @ 2013-02-16 16:33 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Greg Minshall, Bastien, emacs-orgmode

Nicolas Goaziou <n.goaziou@gmail.com> wrote:

> ...
> Thus, I suggest to announce that $ (both $ and $$, even though $$ don't
> have problems /per se/) symbols for should be avoided. Then, in a year
> or so, we can remove them completely from code base.
> 

Agree. Also $$ may not cause problems to org, but according to Lamport
(see p. 233 of Lamport (2nd ed)) it does not work properly in LaTeX.

Nick

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

* Re: LaTeX-export: letters after $..$ turn off math-mode
  2013-02-16 16:33       ` Nick Dokos
@ 2013-02-16 16:45         ` Nick Dokos
  0 siblings, 0 replies; 10+ messages in thread
From: Nick Dokos @ 2013-02-16 16:45 UTC (permalink / raw)
  To: Nicolas Goaziou, Greg Minshall, Bastien, emacs-orgmode

Nick Dokos <nicholas.dokos@hp.com> wrote:

> Nicolas Goaziou <n.goaziou@gmail.com> wrote:
> 
> > ...
> > Thus, I suggest to announce that $ (both $ and $$, even though $$ don't
> > have problems /per se/) symbols for should be avoided. Then, in a year
> > or so, we can remove them completely from code base.
> > 
> 
> Agree. Also $$...$$ may not cause problems to org, but according to Lamport
> (see p. 233 of Lamport (2nd ed)) it does not work properly in LaTeX.
> 

See also

    http://www.tex.ac.uk/cgi-bin/texfaq2html?label=dolldoll

for some details.

Nick

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

end of thread, other threads:[~2013-02-16 16:46 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-06 18:32 LaTeX-export: letters after $..$ turn off math-mode Daniel Schoepe
2012-02-06 19:23 ` Achim Gratz
  -- strict thread matches above, loose matches on Subject: below --
2013-02-04 11:51 Greg Minshall
2013-02-15 22:04 ` Bastien
2013-02-16  7:25   ` Nicolas Goaziou
2013-02-16 11:48     ` Nicolas Goaziou
2013-02-16 16:33       ` Nick Dokos
2013-02-16 16:45         ` Nick Dokos
2013-02-16 14:32     ` Bastien
2013-02-16 15:26       ` Rasmus

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