emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Richard Stanton <rhstanton@berkeley.edu>
To: John Kitchin <jkitchin@andrew.cmu.edu>
Cc: orgmode <emacs-orgmode@gnu.org>
Subject: Re: Trouble producing nicely aligned org tables from emacs-jupyter code blocks using latest org version
Date: Wed, 18 May 2022 14:12:19 -0700	[thread overview]
Message-ID: <09EF74F5-8C39-4773-9407-E65A46E2FE3B@berkeley.edu> (raw)
In-Reply-To: <CAJ51ETrdmpMrJMuMEoc0YtVOQdGT30d6V3FCyBcxThoACXkwdw@mail.gmail.com>

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

A bit more experimenting shows that asynchronous execution is actually a part of my original problem. By default, I have jupyter-python blocks running asynchronously. In that case, the tables don’t format quite right, as I noted. But if I add the header ":async nil", the table comes out fine. Table formatting is OK in python blocks with or without asynchronous execution. 

> On May 18, 2022, at 2:00 PM, John Kitchin <jkitchin@andrew.cmu.edu> wrote:
> 
> I would guess it could. I don't do anything asynchronous, and I am not sure when org-babel-after-execute-hook runs, if it is immediately there is no table to clean up I suppose. It is not necessary to run on  a subtree, but on a very large document you probably don't want to do org-element-parse often.
> 
> 
> John
> 
> -----------------------------------
> Professor John Kitchin (he/him/his)
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu <http://kitchingroup.cheme.cmu.edu/>
> 
> 
> 
> On Wed, May 18, 2022 at 4:57 PM Richard Stanton <rhstanton@berkeley.edu <mailto:rhstanton@berkeley.edu>> wrote:
> Thanks for the suggestion, John. I’ve tried playing around with this, and am I right that it seems to have trouble when execution is asynchronous?
> 
>> On May 18, 2022, at 1:16 PM, John Kitchin <jkitchin@andrew.cmu.edu <mailto:jkitchin@andrew.cmu.edu>> wrote:
>> 
>> I use a function in an after execute hook for this: https://github.com/jkitchin/scimax/blob/master/scimax-org.el#L205 <https://github.com/jkitchin/scimax/blob/master/scimax-org.el#L205>
>> 
>> This works on a subtree, which has been fine for me. You could adapt it to only work in the results section.
>> 
>> John
>> 
>> -----------------------------------
>> Professor John Kitchin (he/him/his)
>> Doherty Hall A207F
>> Department of Chemical Engineering
>> Carnegie Mellon University
>> Pittsburgh, PA 15213
>> 412-268-7803
>> @johnkitchin
>> http://kitchingroup.cheme.cmu.edu <http://kitchingroup.cheme.cmu.edu/>
>> 
>> 
>> 
>> On Wed, May 18, 2022 at 4:07 PM Richard Stanton <rhstanton@berkeley.edu <mailto:rhstanton@berkeley.edu>> wrote:
>> I’m running Emacs 28.1 under macOS 12.4 and want to create tables from Python code blocks that can be exported to either LaTeX or HTML. The simplest way to do this seems to be to generate the output as an org table, and using the built-in version of org (9.4.6 (9.4.6-798-g738759.dirty-elpaplus @ /Users/stanton/.emacs.d/elpa/org-plus-contrib-20210929/)), this works fine using either a python or emacs-jupyter code block:
>> 
>> #+begin_src jupyter-python
>> [
>>     ["Wide a", "b", "c"],
>>     None,
>>     [1, 2, 3],
>>     [4, 5, 6],
>>     None,
>>     [7, 8, 9]
>> ]
>> #+end_src
>> 
>> #+RESULTS:
>> | Wide a | b | c |
>> |--------+---+---|
>> |      1 | 2 | 3 |
>> |      4 | 5 | 6 |
>> |--------+---+---|
>> |      7 | 8 | 9 |
>> 
>> #+begin_src python 
>> return [
>>     ["Wide a", "b", "c"],
>>     None,
>>     [1, 2, 3],
>>     [4, 5, 6],
>>     None,
>>     [7, 8, 9]
>> ]
>> #+end_src
>> 
>> #+RESULTS:
>> | Wide a | b | c |
>> |--------+---+---|
>> |      1 | 2 | 3 |
>> |      4 | 5 | 6 |
>> |--------+---+---|
>> |      7 | 8 | 9 |
>> 
>> 
>> To use the latest version of org, I change just two lines in my init.el from
>> 
>> (straight-use-package '(org :type built-in))
>> (straight-use-package '(org-contrib :type built-in))
>> 
>> to
>> 
>> (straight-use-package '(org :type git :repo "https://code.orgmode.org/bzg/org-mode.git <https://code.orgmode.org/bzg/org-mode.git>"))
>> (straight-use-package '(org-contrib :type git :repo "https://git.sr.ht/~bzg/org-contrib <https://git.sr.ht/~bzg/org-contrib>”))
>> 
>> Having done this, the python block still works fine, but the horizontal lines in the jupyter-python block are no longer properly aligned with the text:
>> 
>> #+begin_src jupyter-python
>> [
>>     ["Wide a", "b", "c"],
>>     None,
>>     [1, 2, 3],
>>     [4, 5, 6],
>>     None,
>>     [7, 8, 9]
>> ]
>> #+end_src
>> 
>> #+RESULTS:
>> | Wide a | b | c |
>> |---+---+---|
>> | 1 | 2 | 3 |
>> | 4 | 5 | 6 |
>> |---+---+---|
>> | 7 | 8 | 9 |
>> 
>> #+begin_src python 
>> return [
>>     ["Wide a", "b", "c"],
>>     None,
>>     [1, 2, 3],
>>     [4, 5, 6],
>>     None,
>>     [7, 8, 9]
>> ]
>> #+end_src
>> 
>> #+RESULTS:
>> | Wide a | b | c |
>> |--------+---+---|
>> |      1 | 2 | 3 |
>> |      4 | 5 | 6 |
>> |--------+---+---|
>> |      7 | 8 | 9 |
>> 
>> By the way, the org version loaded this time is 9.5.3 (9.5.3-g277897 @ /Users/stanton/.emacs.d/straight/build/org/).
>> 
>> The table exports OK, but isn’t much fun to look at in the org file itself.
>> 
>> Since I like to use emacs-jupyter, any suggestions would be appreciated. I know this worked fine just a few weeks ago.
>> 
>> Thanks!
>> 
>> Richard Stanton
>> 
>> 
>> 
>> 
>> 
> 


[-- Attachment #2: Type: text/html, Size: 8700 bytes --]

  reply	other threads:[~2022-05-18 21:13 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-18 20:05 Trouble producing nicely aligned org tables from emacs-jupyter code blocks using latest org version Richard Stanton
2022-05-18 20:16 ` John Kitchin
2022-05-18 20:56   ` Richard Stanton
2022-05-18 21:00     ` John Kitchin
2022-05-18 21:12       ` Richard Stanton [this message]
2022-05-19 13:37         ` Ihor Radchenko
2022-05-19 18:16           ` Richard H. Stanton
2022-05-19 19:22             ` Richard H. Stanton
2022-05-20  8:57               ` Ihor Radchenko
2022-05-22 13:05                 ` Richard Stanton
2022-05-26  4:27                   ` Ihor Radchenko
2022-05-26  8:42                     ` Richard Stanton
2022-05-19 23:22             ` Mark Barton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=09EF74F5-8C39-4773-9407-E65A46E2FE3B@berkeley.edu \
    --to=rhstanton@berkeley.edu \
    --cc=emacs-orgmode@gnu.org \
    --cc=jkitchin@andrew.cmu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).