emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Avoid escaping braces in LaTeX export?
@ 2013-06-07 17:26 Richard Lawrence
  2013-06-07 18:45 ` Marcin Borkowski
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Lawrence @ 2013-06-07 17:26 UTC (permalink / raw)
  To: emacs-orgmode

Hi all,

I'm wondering if there is a way to prevent the LaTeX exporter from
escaping "{" and "}" characters.  There are export options to control
the behavior of a number of other special characters, but I don't see
any way to control export of braces in the documentation.  Am I just
missing it?  If not, I'd like to request this as a feature.

Here's my use case.  I often create new commands in LaTeX to abstract
over some common pattern so I can easily type it and change it later if
necessary.  For example, when taking notes on readings, I have a command
that makes its argument into an `inline comment' (basically an aside to
myself) defined as follows:

#+LATEX_HEADER: \newcommand{\ic}[1]{{\footnotesize [~#1~]}}

Then in my notes I have things like:

 Marcus' point is more subtle, though, than that the substitutional
 reading validates these inferences or theorems while the objectual
 reading does not.  \ic{This would not persuade Quine, for example: the
 failure of existential generalization in modal contexts is for Quine a
 reason to reject quantified modal logic, rather than give the
 existential quantifier a different reading.}  

The new exporter exports this as:

 Marcus' point is more subtle, though, than that the substitutional
 reading validates these inferences or theorems while the objectual
 reading does not.  \ic\{This would not persuade Quine, for example: the
 failure of existential generalization in modal contexts is for Quine a
 reason to reject quantified modal logic, rather than give the
 existential quantifier a different reading.\} 

with the braces wrapping the argument for my custom command escaped.
This breaks the custom command in the export.

I can't test it at the moment, but I believe the old exporter did not
escape these braces, as I used this command regularly and it compiled
correctly.

I would like to be able to get the old behavior back.  I don't mind
manually escaping braces when necessary, because I almost always do not
want them escaped.  I understand if this is not a reasonable default,
but it would be nice for me if it were something I could set on an
#+OPTIONS line.  If others are interested in this, I can look into
creating a patch.

(By the way, it looks like there was a patch for a similar issue in
commit c6fd49726f2eaf417361b190b37e2d8ffb5864fc, but that is from April
2009 and therefore would apply to the old exporter.)

Thanks for your insights!

-- 
Best,
Richard

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

* Re: Avoid escaping braces in LaTeX export?
  2013-06-07 17:26 Avoid escaping braces in LaTeX export? Richard Lawrence
@ 2013-06-07 18:45 ` Marcin Borkowski
  2013-06-07 21:27   ` Richard Lawrence
  0 siblings, 1 reply; 6+ messages in thread
From: Marcin Borkowski @ 2013-06-07 18:45 UTC (permalink / raw)
  To: emacs-orgmode

Dnia 2013-06-07, o godz. 10:26:31
Richard Lawrence <richard.lawrence@berkeley.edu> napisał(a):

> Here's my use case.  I often create new commands in LaTeX to abstract
> over some common pattern so I can easily type it and change it later
> if necessary.  For example, when taking notes on readings, I have a
> command that makes its argument into an `inline comment' (basically
> an aside to myself) defined as follows:
> 
> #+LATEX_HEADER: \newcommand{\ic}[1]{{\footnotesize [~#1~]}}
> 
> Then in my notes I have things like:
> 
>  Marcus' point is more subtle, though, than that the substitutional
>  reading validates these inferences or theorems while the objectual
>  reading does not.  \ic{This would not persuade Quine, for example:
> the failure of existential generalization in modal contexts is for
> Quine a reason to reject quantified modal logic, rather than give the
>  existential quantifier a different reading.}  

Quick and dirty workaround (untested):

#+LATEX_HEADER: \def\ic!#1!{{\footnotesize [~#1~]}}

Marcus' point is more subtle, though, than that the substitutional
reading validates these inferences or theorems while the objectual
reading does not.  \ic!This would not persuade Quine, for example:
the failure of existential generalization in modal contexts is for
Quine a reason to reject quantified modal logic, rather than give the
existential quantifier a different reading.!

Of course, you may do \def\ic(#1){...}, \def\ic~#1~{...} etc.  The
"delimiter" characters may not appear in the argument, though (nesting
is not supported!).

This is very un-LaTeX-y (it is much lower-level TeX syntax), but it is
occasionaly useful (and heavily used by LaTeX itself, btw - this is
used among others for delimiting optional arguments).

Hth,

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

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

* Re: Avoid escaping braces in LaTeX export?
  2013-06-07 18:45 ` Marcin Borkowski
@ 2013-06-07 21:27   ` Richard Lawrence
  2013-06-08 14:35     ` Eric S Fraga
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Lawrence @ 2013-06-07 21:27 UTC (permalink / raw)
  To: emacs-orgmode

Marcin Borkowski <mbork@wmi.amu.edu.pl> writes:

> Dnia 2013-06-07, o godz. 10:26:31
> Richard Lawrence <richard.lawrence@berkeley.edu> napisał(a):
>
>> Here's my use case.  I often create new commands in LaTeX to abstract
>> over some common pattern so I can easily type it and change it later
>> if necessary.  For example, when taking notes on readings, I have a
>> command that makes its argument into an `inline comment' (basically
>> an aside to myself) defined as follows:
>> 
>> #+LATEX_HEADER: \newcommand{\ic}[1]{{\footnotesize [~#1~]}}
>> 

> Quick and dirty workaround (untested):
>
> #+LATEX_HEADER: \def\ic!#1!{{\footnotesize [~#1~]}}
>
> Of course, you may do \def\ic(#1){...}, \def\ic~#1~{...} etc.  The
> "delimiter" characters may not appear in the argument, though (nesting
> is not supported!).
>
> This is very un-LaTeX-y (it is much lower-level TeX syntax), but it is
> occasionaly useful (and heavily used by LaTeX itself, btw - this is
> used among others for delimiting optional arguments).

Hmm, that does work for this case, thanks!  

Still, this won't work directly for cases where I have loaded a LaTeX
package that provides a command which uses curly braces.  (I could
redefine such commands, as above, but that could get real ugly, real
fast...).  It seems like this a general problem that the exporter should
have a way to handle.

-- 
Best,
Richard

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

* Re: Avoid escaping braces in LaTeX export?
  2013-06-07 21:27   ` Richard Lawrence
@ 2013-06-08 14:35     ` Eric S Fraga
  2013-06-08 17:45       ` Richard Lawrence
  0 siblings, 1 reply; 6+ messages in thread
From: Eric S Fraga @ 2013-06-08 14:35 UTC (permalink / raw)
  To: Richard Lawrence; +Cc: emacs-orgmode

Richard Lawrence <richard.lawrence@berkeley.edu> writes:


[...]

> Still, this won't work directly for cases where I have loaded a LaTeX
> package that provides a command which uses curly braces.  (I could
> redefine such commands, as above, but that could get real ugly, real
> fast...).  It seems like this a general problem that the exporter should
> have a way to handle.

Org is not latex, for better or for worse.  However, it does allow you
to mix the two in various ways.  The inline approach is limited to
{text} that is on the same line.  You could try using visual-line-mode
and have all paragraphs be single lines.

Alternative, you could try (untested):

blah blah blah
#+LATEX: \ic{
some text for the inline comment
#+LATEX: }
more blah

HTH,
eric

-- 
: Eric S Fraga, GnuPG: 0xC89193D8FFFCF67D
: in Emacs 24.3.50.1 and Org release_8.0.3-193-g334581

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

* Re: Avoid escaping braces in LaTeX export?
  2013-06-08 14:35     ` Eric S Fraga
@ 2013-06-08 17:45       ` Richard Lawrence
  2013-06-09  7:37         ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Lawrence @ 2013-06-08 17:45 UTC (permalink / raw)
  To: emacs-orgmode

Eric S Fraga <e.fraga@ucl.ac.uk> writes:

> Richard Lawrence <richard.lawrence@berkeley.edu> writes:
> Org is not latex, for better or for worse.  However, it does allow you
> to mix the two in various ways.  The inline approach is limited to
> {text} that is on the same line.  You could try using visual-line-mode
> and have all paragraphs be single lines.
>
> Alternative, you could try (untested):
>
> blah blah blah
> #+LATEX: \ic{
> some text for the inline comment
> #+LATEX: }
> more blah

Thanks, Eric; that works, too.

I think for now the best thing is for me to put longer comments in a
custom environment.  Then I can use Org's block syntax, and have other
export backends do the right thing, if I ever use them instead of LaTeX.

I did dig into the exporter code a bit, so in case anyone is bitten by a
similar issue that doesn't have a ready workaround, the places to look
seem to be:
  - org-element.el:org-element-latex-or-entity-successor.  This is where
    LaTeX fragments are identified.  (As Eric notes, multi-line commands
    will not have their arguments parsed as part of a latex-fragment;
    instead, the argument and surrounding braces are parsed as text in
    the surrounding paragraph.) 
  - ox-latex.el:org-latex-plain-text.  This is where special characters
    that don't get parsed as part of a LaTeX fragment are
    protected/escaped.

I still think it might be nice if each of the protections in
org-latex-plain-text could be toggled via an #+OPTIONS keyword, since
more often than not, I find that characters are escaped in LaTeX export
when I would prefer they weren't.  But that might be a peculiar fact
about how I use Org.  Since for now I don't require this behavior, I'm
not going to try to implement it myself, but if anyone else would also
find it useful, let me know and I will take a stab at writing a patch.

Thanks, all, for the help!

-- 
Best,
Richard

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

* Re: Avoid escaping braces in LaTeX export?
  2013-06-08 17:45       ` Richard Lawrence
@ 2013-06-09  7:37         ` Nicolas Goaziou
  0 siblings, 0 replies; 6+ messages in thread
From: Nicolas Goaziou @ 2013-06-09  7:37 UTC (permalink / raw)
  To: Richard Lawrence; +Cc: emacs-orgmode

Hello,

Richard Lawrence <richard.lawrence@berkeley.edu> writes:

> Eric S Fraga <e.fraga@ucl.ac.uk> writes:
>
>> Richard Lawrence <richard.lawrence@berkeley.edu> writes:
>> Org is not latex, for better or for worse.  However, it does allow you
>> to mix the two in various ways.  The inline approach is limited to
>> {text} that is on the same line.  You could try using visual-line-mode
>> and have all paragraphs be single lines.
>>
>> Alternative, you could try (untested):
>>
>> blah blah blah
>> #+LATEX: \ic{
>> some text for the inline comment
>> #+LATEX: }
>> more blah
>
> Thanks, Eric; that works, too.
>
> I think for now the best thing is for me to put longer comments in a
> custom environment.  Then I can use Org's block syntax, and have other
> export backends do the right thing, if I ever use them instead of LaTeX.
>
> I did dig into the exporter code a bit, so in case anyone is bitten by a
> similar issue that doesn't have a ready workaround, the places to look
> seem to be:
>   - org-element.el:org-element-latex-or-entity-successor.  This is where
>     LaTeX fragments are identified.  (As Eric notes, multi-line commands
>     will not have their arguments parsed as part of a latex-fragment;
>     instead, the argument and surrounding braces are parsed as text in
>     the surrounding paragraph.) 
>   - ox-latex.el:org-latex-plain-text.  This is where special characters
>     that don't get parsed as part of a LaTeX fragment are
>     protected/escaped.
>
> I still think it might be nice if each of the protections in
> org-latex-plain-text could be toggled via an #+OPTIONS keyword, since
> more often than not, I find that characters are escaped in LaTeX export
> when I would prefer they weren't.  But that might be a peculiar fact
> about how I use Org.  Since for now I don't require this behavior, I'm
> not going to try to implement it myself, but if anyone else would also
> find it useful, let me know and I will take a stab at writing a patch.
>
> Thanks, all, for the help!

As Eric said, Org format is not LaTeX, and I would add that Org mode is
not Auctex mode. You can already write raw LaTeX code with appropriate
markers. There's no point in allowing more LaTeX code without markers.


Regards,

-- 
Nicolas Goaziou

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

end of thread, other threads:[~2013-06-09  7:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-07 17:26 Avoid escaping braces in LaTeX export? Richard Lawrence
2013-06-07 18:45 ` Marcin Borkowski
2013-06-07 21:27   ` Richard Lawrence
2013-06-08 14:35     ` Eric S Fraga
2013-06-08 17:45       ` Richard Lawrence
2013-06-09  7:37         ` Nicolas Goaziou

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