Server Bug Fix: How to output an octave array as a org-mode table?

Original Source Link

I am trying to output a matlab/octave array as an org-mode table. So for an array/matrix like

a =[ 1 2; 3 4; 5 6];

I’d like to have a 3 by 2 org-mode table. I tried to just echo the array a as if in matlab, but it does not work. I am wondering how to make the output work.

More specifically, for an input array:

#+name: test-data
#+begin_src octave :session test_case :exports both
  a =[ 1 2; 3 4; 5 6];
#+end_src

#+RESULTS: test-data
: org_babel_eoe

I can generate its size as a table:

#+NAME: test-output-size
#+BEGIN_SRC octave :session test_case :results value :colnames yes :hline yes
  size(a)
#+END_SRC

#+RESULTS: test-output-size
| 3 | 2 |

But when I tried to print the array a itself as a table, I got no output:

#+NAME: test-output-value
#+BEGIN_SRC octave :session test_case :results value :colnames yes :hline yes
  a
#+END_SRC

#+RESULTS: test-output-value
: org_babel_eoe

I also tried disp(), to no avail. So my question is:

What is the proper way to output an array as a table?

(This is with the Emacs 26 in Ubuntu 20.04 LTS)

Octave is peculiar (or maybe ob-octave is peculiar). In particular, the name ans seems to have special meaning. Try this:

#+name: test-data
#+begin_src octave :session test_case :exports both
  a =[ 1 2; 3 4; 5 6];
  ans = a
#+end_src

#+RESULTS: test-data
| 1 | 2 |
| 3 | 4 |
| 5 | 6 |

You can ask for the results to be the output (the default is value) and then use the disp option you already tried; place this

:results output

on the begin_src line.

Tagged : /

Server Bug Fix: Is it possible to organize the capture templates selection screen?

Original Source Link

enter image description here

As it can be seen above, I have around fifteen capture templates. I think this list may grow or shrink, but in the case that it grows, is there any way to make it more segmented?

Like dividing it across some categories, just for visual organization. Something like:

Notes

  • books

  • web pages

  • miscellaneous

  • articles

  • uni notes

Media

  • movie

  • game

  • book

Actions

  • goals

  • tasks

  • weekly review

Writing

  • new post

  • thesis

  • journaling

Or even dividing it horizontally instead of vertically. And so forth and so on.

Yes, this degree of organization could be reached through diminishing the number of capture templates and further customizing them to make them more specific, but then I would have to stack them in the same file. And since I use Emacs mostly for writing, my org files tend to get huge very quickly and I like to spread them out to avoid making things a mess.

Is this setup somehow feasible?

There are a couple of options for this, to me the easiest way is grouping templates using the built-in mechanism.

My way to use capture templates is based in memory muscle rather than digging a long menu, so how the menu is displayed should be concise in case I don’t recall what key was for something. I do call capture using F12, then if I want to insert a note I’ll use n and, let’s say b if it’s about a book.

So, to achieve this if you look for org-capture-templates documentation:

keys         The keys that will select the template, as a string, characters
             only, for example "a" for a template to be selected with a
             single key, or "bt" for selection with two keys.  When using
             several keys, keys using the same prefix key must be together
             in the list and preceded by a 2-element entry explaining the
             prefix key, for example

                     ("b" "Templates for marking stuff to buy") ```

meaning that you can use n to group notes as heading and using two chars keys nb, nm, nw, na for books, miscelanea, work and articles – you should also follow the other conditions.

So something like this in your template definition:

("n" "Notes")
("nb" "Notes about books"    <your template definition here>)
("nm" "Misc notes"           <your template definition here>)
("nw" "Work notes"           <your template definition here>)
("na" "Notes about articles" <your template definition here>)

Will give you a n submenu which unfolds in a new menu once pressed. Calling capture templates will look like this:

... <other capture templates>
[b]    Books to read 
[n]... Notes
... <other capture templates>

and pressing n will lead to:

n [b]  Notes about books
n [m]  Misc notes
n [w]  Work notes
n [a]  Notes about articles

You can do it in your init file or using customize interface. Of course there is more about this in the documentation.

Tagged : / / / /

Server Bug Fix: Export only headlines of a certain level

Original Source Link

This one is pretty straightforward. I’m translating in emacs org-mode, and my workflow looks a bit like this:

* Source text sentence

** Translation of source text sentence

* Another source text sentence

** The translation of that other sentence

What I’d like to do is take all (and only) second level headlines (which are my translations) and copy them into a separate document. Is this possible, or am I thinking too outside the box?

Thanks!

Another approach is to delete all non-level-2 entries before
parsing the export buffer. This is different to what @gregoryg is
proposing in that it also skips the body/text directly following
non-level-2 headings. No need to use tags.

(defun export-translation (backend)
  (org-map-entries
   (lambda ()
     (unless (= (org-current-level) 2)
       (let ((beg (line-beginning-position))
             (end (or (save-excursion
                        (outline-next-heading))
                      (point-max))))
         (delete-region beg end))))))

You can add this function to org-export-before-parsing-hook as a
file variable by adding the following line to the beginning of
the Org document.

# -*- org-export-before-parsing-hook: export-translation -*-

Now to also skip the contents of level-2 entries, use:

(defun export-translation (backend)
  (save-excursion
    (goto-char (point-max))
    (while (re-search-backward org-complex-heading-regexp nil t)
      (let ((beg (save-excursion
                   (when (= (org-current-level) 2)
                     (forward-line))
                   (point)))
            (end (or (save-excursion
                       (outline-next-heading))
                     (point-max))))
        (delete-region beg end)))))

You can use ox-extra functions from the org-plus-contrib package.

This would require you to tag all top-level headlines with the “ignore” tag.

(require 'ox-org) ; if exporting to Org Mode
(require 'ox-extra)
(ox-extras-activate '(ignore-headlines))

After tagging your top-level headlines, export to a plain text or Org file, e.g. C-c C-e O o

You can cancel your filter with

(ox-extras-deactivate '(ignore-headlines))

As @NickD points out, this method removes the headlines only – it will still export any text under that headline.

Tagged :