emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Org not preserving Python indent levels on LaTex export due to tabs
@ 2014-02-01 23:56 James Ryland Miller
  2014-02-02  7:49 ` Nicolas Goaziou
  0 siblings, 1 reply; 9+ messages in thread
From: James Ryland Miller @ 2014-02-01 23:56 UTC (permalink / raw)
  To: emacs-orgmode

I'm having trouble with getting python source=code blocks to export to
LaTeX properly. I've figured out what's going wrong: the exporter is
inserting tab characters on lines with 2 or more indentation levels in
python. If I use org to export to .tex first, and then untabify the
.tex files, the indent levels are preserved (assuming the tabs
correctly lined up with the corresponding python in the first place,
which many times they don't).

Here's a test.org file:

* Heading 1

LaTeX export does not work on python src blocks with more than 2
levels of indentation.

For example (4 spaces per indent level, not tabs):

#+BEGIN_SRC python -n
      def foo(x):
          print("Hi: %s" % x)
          if x == "James":
              print("James is the best!")
          else:
              return x
#+END_SRC

The above should be indented properly. But it isn't. The resulting
.tex file has tabs on the second indent level lines and the tab
doesn't even line up with the 4 spaces per tab either. Any ideas how
to get rid of this? If I run a =C-x h M-x untabify= on the .tex file,
then it exports just fine. But I don't /want/ to do that each and
every time I export my org files.

Here's the verbatim portion of the generated LaTeX source:

#+BEGIN_SRC latex -n

\begin{verbatim}
1  def foo(x):
2      print("Hi: %s" % x)
3      if x == "James":
4   print("James is the best!")
5      else:
6   return x
\end{verbatim}
#+END_SRC

Note: lines 4 and 6 in the =\begin{verbatim}= blocks.

Line 4 is "4[space][space][tab]print("James...")"  How do I get org to export
with all spaces and no tabs for verbatims in LaTeX?

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

* Re: Org not preserving Python indent levels on LaTex export due to tabs
  2014-02-01 23:56 Org not preserving Python indent levels on LaTex export due to tabs James Ryland Miller
@ 2014-02-02  7:49 ` Nicolas Goaziou
  2014-02-02 17:32   ` James Ryland Miller
                     ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Nicolas Goaziou @ 2014-02-02  7:49 UTC (permalink / raw)
  To: James Ryland Miller; +Cc: emacs-orgmode

Hello,

James Ryland Miller <james.ryland.miller@gmail.com> writes:

> I'm having trouble with getting python source=code blocks to export to
> LaTeX properly. I've figured out what's going wrong: the exporter is
> inserting tab characters on lines with 2 or more indentation levels in
> python. If I use org to export to .tex first, and then untabify the
> .tex files, the indent levels are preserved (assuming the tabs
> correctly lined up with the corresponding python in the first place,
> which many times they don't).

Try to set `org-src-preserve-indentation' to a non-nil value (on a very
recent Org) or add a "-i" flag to you source block:

  #+BEGIN_SRC python -n -i
  ...
  #+END_SRC

This should prevent Org from touching indentation within the block.


Regards,

-- 
Nicolas Goaziou

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

* Re: Org not preserving Python indent levels on LaTex export due to tabs
  2014-02-02  7:49 ` Nicolas Goaziou
@ 2014-02-02 17:32   ` James Ryland Miller
  2014-02-02 18:05     ` John Hendy
  2014-02-03 13:08   ` Sebastien Vauban
  2014-02-14  0:32   ` Samuel Wales
  2 siblings, 1 reply; 9+ messages in thread
From: James Ryland Miller @ 2014-02-02 17:32 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

Thank you! That worked perfectly. Is '-i' not in the docs?

On Sun, Feb 2, 2014 at 1:49 AM, Nicolas Goaziou <n.goaziou@gmail.com> wrote:
> Hello,
>
> James Ryland Miller <james.ryland.miller@gmail.com> writes:
>
>> I'm having trouble with getting python source=code blocks to export to
>> LaTeX properly. I've figured out what's going wrong: the exporter is
>> inserting tab characters on lines with 2 or more indentation levels in
>> python. If I use org to export to .tex first, and then untabify the
>> .tex files, the indent levels are preserved (assuming the tabs
>> correctly lined up with the corresponding python in the first place,
>> which many times they don't).
>
> Try to set `org-src-preserve-indentation' to a non-nil value (on a very
> recent Org) or add a "-i" flag to you source block:
>
>   #+BEGIN_SRC python -n -i
>   ...
>   #+END_SRC
>
> This should prevent Org from touching indentation within the block.
>
>
> Regards,
>
> --
> Nicolas Goaziou

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

* Re: Org not preserving Python indent levels on LaTex export due to tabs
  2014-02-02 17:32   ` James Ryland Miller
@ 2014-02-02 18:05     ` John Hendy
  0 siblings, 0 replies; 9+ messages in thread
From: John Hendy @ 2014-02-02 18:05 UTC (permalink / raw)
  To: James Ryland Miller; +Cc: emacs-orgmode, Nicolas Goaziou

I think it was very recently added (i.e. yesterday) due to this thread
about a very similar (same) issue:
- http://www.mail-archive.com/emacs-orgmode@gnu.org/msg81203.html

I'd love to update Worg/documentation to include it... out of
curiosity, where were you looking for it to be documented? That way, I
can add it to the most intuitive/popular location.


Thanks,
John

On Sun, Feb 2, 2014 at 11:32 AM, James Ryland Miller
<james.ryland.miller@gmail.com> wrote:
> Thank you! That worked perfectly. Is '-i' not in the docs?
>
> On Sun, Feb 2, 2014 at 1:49 AM, Nicolas Goaziou <n.goaziou@gmail.com> wrote:
>> Hello,
>>
>> James Ryland Miller <james.ryland.miller@gmail.com> writes:
>>
>>> I'm having trouble with getting python source=code blocks to export to
>>> LaTeX properly. I've figured out what's going wrong: the exporter is
>>> inserting tab characters on lines with 2 or more indentation levels in
>>> python. If I use org to export to .tex first, and then untabify the
>>> .tex files, the indent levels are preserved (assuming the tabs
>>> correctly lined up with the corresponding python in the first place,
>>> which many times they don't).
>>
>> Try to set `org-src-preserve-indentation' to a non-nil value (on a very
>> recent Org) or add a "-i" flag to you source block:
>>
>>   #+BEGIN_SRC python -n -i
>>   ...
>>   #+END_SRC
>>
>> This should prevent Org from touching indentation within the block.
>>
>>
>> Regards,
>>
>> --
>> Nicolas Goaziou
>

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

* Re: Org not preserving Python indent levels on LaTex export due to tabs
  2014-02-02  7:49 ` Nicolas Goaziou
  2014-02-02 17:32   ` James Ryland Miller
@ 2014-02-03 13:08   ` Sebastien Vauban
  2014-02-03 14:56     ` Bastien
  2014-02-14  0:32   ` Samuel Wales
  2 siblings, 1 reply; 9+ messages in thread
From: Sebastien Vauban @ 2014-02-03 13:08 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Nicolas Goaziou wrote:
> James Ryland Miller <james.ryland.miller-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>
>> I'm having trouble with getting python source=code blocks to export to
>> LaTeX properly. I've figured out what's going wrong: the exporter is
>> inserting tab characters on lines with 2 or more indentation levels in
>> python. If I use org to export to .tex first, and then untabify the
>> .tex files, the indent levels are preserved (assuming the tabs
>> correctly lined up with the corresponding python in the first place,
>> which many times they don't).
>
> Try to set `org-src-preserve-indentation' to a non-nil value (on a very
> recent Org) or add a "-i" flag to you source block:
>
>   #+BEGIN_SRC python -n -i
>   ...
>   #+END_SRC
>
> This should prevent Org from touching indentation within the block.

Again (as for `org-src-fontify-natively'), shouldn't this be true by
default?

Best regards,
  Seb

-- 
Sebastien Vauban

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

* Re: Org not preserving Python indent levels on LaTex export due to tabs
  2014-02-03 13:08   ` Sebastien Vauban
@ 2014-02-03 14:56     ` Bastien
  0 siblings, 0 replies; 9+ messages in thread
From: Bastien @ 2014-02-03 14:56 UTC (permalink / raw)
  To: Sebastien Vauban; +Cc: public-emacs-orgmode-mXXj517/zsQ



Hi Sébastien,

"Sebastien Vauban" <sva-news-D0wtAvR13HarG/iDocfnWg@public.gmane.org>
writes:

> Again (as for `org-src-fontify-natively'), shouldn't this be true by
> default?

I don't know for other people, but the default value is good for me.

-- 
 Bastien

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

* Re: Org not preserving Python indent levels on LaTex export due to tabs
  2014-02-02  7:49 ` Nicolas Goaziou
  2014-02-02 17:32   ` James Ryland Miller
  2014-02-03 13:08   ` Sebastien Vauban
@ 2014-02-14  0:32   ` Samuel Wales
  2014-02-16 10:11     ` Nicolas Goaziou
  2 siblings, 1 reply; 9+ messages in thread
From: Samuel Wales @ 2014-02-14  0:32 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: James Ryland Miller, emacs-orgmode

i can't seem to find the -i flag in the manual.  perhaps i used the
wrong search term?  i looked in literal examples and in working with
source code.  i am using maint.

also:

  - is there another flag to set org-src-preserve-indentation to nil?
  - will -i still work if org-src.preserve-indentation is t?

thanks.

i'd be happy with a fixed 2-space indentation, but that is not
possible in current org.  i find org-src-preserve-indentation to cause
more issues than it improves, so i am going to transition to it being
t, which feels safer even though it is not the default and does not
have the 2 spaces.

samuel


On 2/2/14, Nicolas Goaziou <n.goaziou@gmail.com> wrote:
> Hello,
>
> James Ryland Miller <james.ryland.miller@gmail.com> writes:
>
>> I'm having trouble with getting python source=code blocks to export to
>> LaTeX properly. I've figured out what's going wrong: the exporter is
>> inserting tab characters on lines with 2 or more indentation levels in
>> python. If I use org to export to .tex first, and then untabify the
>> .tex files, the indent levels are preserved (assuming the tabs
>> correctly lined up with the corresponding python in the first place,
>> which many times they don't).
>
> Try to set `org-src-preserve-indentation' to a non-nil value (on a very
> recent Org) or add a "-i" flag to you source block:
>
>   #+BEGIN_SRC python -n -i
>   ...
>   #+END_SRC
>
> This should prevent Org from touching indentation within the block.
>
>
> Regards,
>
> --
> Nicolas Goaziou
>
>


-- 
The Kafka Pandemic: http://thekafkapandemic.blogspot.com

The disease DOES progress.  MANY people have died from it.  ANYBODY can get it.

Denmark: free Karina Hansen NOW.

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

* Re: Org not preserving Python indent levels on LaTex export due to tabs
  2014-02-14  0:32   ` Samuel Wales
@ 2014-02-16 10:11     ` Nicolas Goaziou
  2014-03-15  6:43       ` Bastien
  0 siblings, 1 reply; 9+ messages in thread
From: Nicolas Goaziou @ 2014-02-16 10:11 UTC (permalink / raw)
  To: Samuel Wales; +Cc: James Ryland Miller, emacs-orgmode

Hello,

Samuel Wales <samologist@gmail.com> writes:

> i can't seem to find the -i flag in the manual.  perhaps i used the
> wrong search term?  i looked in literal examples and in working with
> source code.  i am using maint.

Indeed. It doesn't appear in the manual.

I don't use it. Maybe Someone using it can provide a patch for it.

> also:
>
>   - is there another flag to set org-src-preserve-indentation to nil?
>   - will -i still work if org-src.preserve-indentation is t?

No.

> i'd be happy with a fixed 2-space indentation, but that is not
> possible in current org.  i find org-src-preserve-indentation to cause
> more issues than it improves, so i am going to transition to it being
> t, which feels safer even though it is not the default and does not
> have the 2 spaces.

FWIW, I'm happy with `org-src-preserve-indentation' set to nil.

Anyway, if you think `org-src-preserve-indentation' needs improvement,
please provide a description (or ECM) of what you expect it to do.


Regards,

-- 
Nicolas Goaziou

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

* Re: Org not preserving Python indent levels on LaTex export due to tabs
  2014-02-16 10:11     ` Nicolas Goaziou
@ 2014-03-15  6:43       ` Bastien
  0 siblings, 0 replies; 9+ messages in thread
From: Bastien @ 2014-03-15  6:43 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: James Ryland Miller, emacs-orgmode

Hi,

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

> Indeed. It doesn't appear in the manual.
>
> I don't use it. Maybe Someone using it can provide a patch for it.

I added one sentence about -i in the manual.

Thanks,

-- 
 Bastien

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

end of thread, other threads:[~2014-03-15  6:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-01 23:56 Org not preserving Python indent levels on LaTex export due to tabs James Ryland Miller
2014-02-02  7:49 ` Nicolas Goaziou
2014-02-02 17:32   ` James Ryland Miller
2014-02-02 18:05     ` John Hendy
2014-02-03 13:08   ` Sebastien Vauban
2014-02-03 14:56     ` Bastien
2014-02-14  0:32   ` Samuel Wales
2014-02-16 10:11     ` Nicolas Goaziou
2014-03-15  6:43       ` Bastien

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