Clojure 1.5 print-table, org-mode babel, and org-mode HTML gen

349 vistas
Ir al primer mensaje no leído

Mark C

no leída,
1 mar 2013, 11:29:17 p.m.1/3/13
para clo...@googlegroups.com
Sorry in advance if this doesn't turn out to be a clojure-specific problem, but this seemed like a reasonable place to ask..

Context: I'm a heavy org-mode user, so Mike Fogus' recent "usesthis" post mentioning org-mode babel was quite interesting. I got babel working fine (for clojure, elisp, sh) then recalled that print-table in Clojure 1.5 outputs in org-mode compatible table format. Awesome. So naturally I'd like to generate nice looking tables using something like:

#+begin_src clojure :exports both
    (with-out-str (print-table [{:a 1 :b 2 :c 3} {:b 5 :a 7 :c "dog"}]))
#+end_src


(Using with-out-str is needed because print-table of course returns nil)

But what I get when generating HTML (via "C-c C-e b") is not a table, but the literal text of the table markup. I.e. compiling the above source block yeilds:

#+RESULTS: clojure-org-table
:
: | :a |  :c | :b |
: |----+-----+----|
: |  1 |   3 |  2 |
: |  7 | dog |  5 |


This makes sense. But how might one go about getting an HTML table generated?

I can edit the results show above and add some attributes before HTML generation, e.g.

#+CAPTION: This is a table with lines around and between cells
#+ATTR_HTML: border="2" rules="all" frame="border"
| :a |  :c | :b |
|----+-----+----|
|  1 |   3 |  2 |
|  7 | dog |  5 |


This yields a nice looking table in HTML, but I would like to eliminate this manual step. Any ideas??

Thanks,
Mark

greg r

no leída,
2 mar 2013, 10:18:18 a.m.2/3/13
para clo...@googlegroups.com
Try adding

:results value raw

 to your options.
Here is what the org manual says:

The results are interpreted as raw Org mode code and are inserted directly
into the buffer. If the results look like a table they will be aligned as such by Org mode.

org is a fantastic environment for playing with Clojure.  I've got a lot done with it.

Regards,
Greg

Mark C

no leída,
2 mar 2013, 11:52:07 p.m.2/3/13
para clo...@googlegroups.com
Worked like a charm. Thanks!

Babel is fun. I really like the idea of being able to code in multiple languages in one document - and have return values from one feed another. And I just found out you can include TeX too - just starting to play with that. I'd love to hear more about how you use clojure and org mode together.

Mark

greg r

no leída,
3 mar 2013, 6:03:51 p.m.3/3/13
para clo...@googlegroups.com
Here's a little project I worked on:

https://github.com/Greg-R/incanterchartcustom

I'm just now learning git, so I hope the files are intact in the repository.  I cloned to another machine and they appear to be OK.

The Incanter chart PDF document shows what is possible with regard to documenting code and showing a nice export result.
The repository also includes the source .org file.  In theory, if you have everything set up correctly you can reproduce the
PDF document exactly.  Since it is generating PDF charts, there are lots of side-effects and whatever directory you are running
in will get filled up with the chart files.  I used LaTeX snippets within the org file to include the chart graphics in the exported tex
file and thus the eventual PDF.

I don't use C-c C-e p.  This doesn't always work, and I prefer C-c C-e l which exports the .tex file only.  I open the .tex file with
the Texworks application which has worked really well for me for editing LaTeX documents.  Texworks has the ability to jump between
the PDF and the .tex file and vice-versa, which makes troubleshooting much easier.

I did a bunch of data processing for work using org, Clojure, and Incanter to produce reports in PDF.  I created several Leiningen projects
to attack various aspects of the data manipulation.  Then within Clojure code blocks in org, the various namespaces are used to process
data at the appropriate points in the document.  None of the output was inserted directly into the org file.  That turned out to be impractical
as some of the generated documents were hundreds of pages long.  The Clojure/Incanter code chunks generated .tex files which were included
in the exported output via LaTeX code blocks.  Really in this case the org-babel system operated more as a document/code organizer than
as a programming system.  But what an organizer it is!!!  I saved hundreds, maybe thousands of man hours of manual document generating.

There were several technologies to learn to get it all to work in harmony:

Clojure
Incanter
Emacs (24.2) (including some Elisp in the .emacs file)
org
babel
Leiningen
LaTeX
Texworks
nrepl (this will require some extra stuff in the .emacs file to get babel to work)

It took a lot of work, but I think the org-babel system is really worth it!

Regards,
Greg

Gary Johnson

no leída,
4 mar 2013, 2:25:42 p.m.4/3/13
para clo...@googlegroups.com
+1 for org-babel. I put together an example project solving the Potter Kata on github several months ago, so if someone is looking for some examples of how you might do LP with org-babel, take a look at it here:

  https://github.com/lambdatronic/org-babel-example

  Happy hacking,
    ~Gary

Mark C

no leída,
4 mar 2013, 4:25:23 p.m.4/3/13
para clo...@googlegroups.com
Very cool. Great looking doc! I just installed LaTeX and TeXworks so it's off to play. (Other than incanter I already have the rest working, including nrepl -  though I have to start up nrepl with nrepl-jack-in. Is that what you were planning on doing? It would be cool to have it launched by the first compile!).


On Sunday, March 3, 2013 6:03:51 PM UTC-5, greg r wrote:

Mark C

no leída,
4 mar 2013, 4:36:22 p.m.4/3/13
para clo...@googlegroups.com
This is a very helpful example. Along similar lines, I was thinking it would be cool to have a document of 4clojure problems/solutions/tests. I haven't used tangle/weave yet, which would be pretty useful for that. I think it would be a great learning resource to create an org-based book of "best of" idiomatic Clojure solutions to all 4clojure (or Euler) problems and solutions. As long as you don't get too mired in what constitutes "best" :)

Btw, it would be interesting to see the resulting pdf from you Kata doc..

M.

greg r

no leída,
5 mar 2013, 7:37:29 a.m.5/3/13
para clo...@googlegroups.com
I think I was wrong about the extra elisp code required for nrepl to evaluate babel Clojure code blocks.  This was from last year:

https://groups.google.com/forum/?fromgroups=#!searchin/nrepl-el/babel/nrepl-el/txLYH9tH6AU/hj0NkyF8YZ8J

I checked my .emacs file and the extra code for clojure babel is commented out, so the later versions of nrepl must have this feature included.
Too many months ago, I really need to put better notes and comments in my .emacs file!

Greg

Dave Kincaid

no leída,
5 mar 2013, 9:57:02 a.m.5/3/13
para clo...@googlegroups.com
Comments in your .emacs file? That's blasphemy!
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos