5

I want to use org to make a Beamer slide like this:

 --------------------------------
|                                |
|   some text                    |
|                                |
|   --------------------         |
|  |  code              |        |
|   --------------------         |
|                                |
|   more text                    |
|                                |
 --------------------------------

But if I attempt this in org-mode, like the following:

* More Complex Example
  some text

*** library.py         :B_block:
    #+begin_src python
    code
    #+end_src

  more text

...the output looks like this:

 --------------------------------
|                                |
|   some text                    |
|                                |
|   --------------------         |
|  |  code              |        |
|  |  more text         |        |
|   --------------------         |
|                                |
|                                |
 --------------------------------

How do I put more text on the same slide, but outside of the code block?

Timm
  • 1,549
  • 12
  • 23
Alex Shroyer
  • 627
  • 4
  • 12

2 Answers2

7

You need to use a "closing" heading:

***                                                       :B_ignoreheading:
:PROPERTIES:
:BEAMER_env: ignoreheading
:END:

Hence, your example should look like this:

* More Complex Example
  some text

*** library.py         :B_block:
    #+begin_src python
    code
    #+end_src
***                                                       :B_ignoreheading:
:PROPERTIES:
:BEAMER_env: ignoreheading
:END:

more text

See https://github.com/fniessen/refcard-org-beamer#end-of-block.

Timm
  • 1,549
  • 12
  • 23
  • I speculated that I needed some way of making an "invisible" heading but didn't know what to search for. This works, thank you. – Alex Shroyer Oct 25 '18 at 18:22
3

It's a pity that it's not mentioned in the manual nor in the tutorial, since it's a more natural mapping of constructs from org to beamer, but you can use special org blocks (avoiding the boilerplate of subsectioning with its drawers and everything) as defined here. For example:

Some text...

#+BEGIN_theorem
...
#+END_theorem

...text continues here

Then you may prefer to use subsections only for columns or nested structure and blocks for simple "boxes" in your frame.

You can also alter the AST tree a bit if you prefer:

#+BEGIN_theorem Hahn-Banach
...
#+END_theorem

to

#+ATTR_LATEX :options [Hahn-Banach]
#+BEGIN_theorem
...
#+END_theorem

Here is a generic filter that will honour #+ATTR_xxx in case it's present for the current backend but will default to the argument of the special block otherwise:

(defun my-org-special-block-filter (tree backend _symbol)
  (pcase-let ((`(,prop ,fmt)
               (cond ((org-export-derived-backend-p backend 'latex)
                      '(:attr_latex ":options %s")))))
    (when prop
      (org-element-map tree 'special-block
        (lambda (element)
          (unless (org-element-property prop element)
            (save-excursion
              (goto-char (org-element-property :begin element))
              (when (looking-at "[ \t]*#\\+begin_\\S-+[ \t]+\\([^\n]+\\)")
                (let ((attr (format fmt (match-string-no-properties 1))))
                  (org-element-put-property element prop (list attr))))))
          nil)))))

Finally, you can add some font locking to highlight semantically relevant items. As a starter:

(font-lock-add-keywords 'org-mode
  '(("[ \t]*\\(#\\+\\(BEGIN\\|END\\)_\\(\\S-+\\)\\)[ \t]*\\([^\n:]*\\)"
     (1 '(:foreground "#5a5b5a" :background "#292b2b") t) ; directive
     (3 '(:foreground "#81a2be" :background "#292b2b") t) ; kind
     (4 '(:foreground "#c5c8c6") t))) ; title
  t)

Here is an example of the overall result:

enter image description here

memeplex
  • 399
  • 2
  • 4
  • Do you know what I could do if I want a footnote in the special org block title, ie: #+ATTR_LATEX: :options {In [fn:1] it is stated:} #+BEGIN_alertblock This clearly indicates that the use of an FIR model ... #+END_alertblock [fn:1] Subspace-Based System, 1996 Here the footnote is not resolved. If I use the subsectioning it works: *** In [fn:1] it is stated: :B_alertblock: :PROPERTIES: :BEAMER_env: alertblock :END: This clearly indicates that the use of an FIR model ... *** :B_ignoreheading: :PROPERTIES: :BEAMER_env: ignoreheading :END: [fn:1] Subspace-Based System, 1996 Which transl – Paw Dec 05 '18 at 11:03