Define org mode macro with line breaks

前端 未结 4 1670
后悔当初
后悔当初 2021-02-07 07:20

It is possible to define a macro in an org file as follow:

#+MACRO: macroname 

Is it possi

4条回答
  •  北恋
    北恋 (楼主)
    2021-02-07 07:37

    Not only is this possible, it's quite easy to do. You just need to be creative about how you insert the newline. I make use of Org Babel to hack the macros. The following works for me:

    #+MACRO: newline   src_emacs-lisp[:results raw]{"\n"}
    #+MACRO: macroname line 1 of macro {{{newline}}}line 2 of macro
    

    So, given this document:

    #+MACRO: newline    src_emacs-lisp[:results raw]{"\n"}
    #+MACRO: macroname line 1 of macro {{{newline}}}line 2 of macro
    
    {{{macroname}}}
    

    Exporting to Org mode gives the following

    # Created 2015-11-03 Tue 15:27
    #+TITLE: 
    #+AUTHOR:
    #+MACRO: newline    src_emacs-lisp[:results raw]{"\n"}
    #+MACRO: macroname line 1 of macro {{{newline}}}line 2 of macro
    
    line 1 of macro 
    line 2 of macro
    

    You just have to be aware that some export formats will transform that newline to a single line when it wraps the text. So, you probably want something like this to get two paragraphs:

    #+MACRO: newline   src_emacs-lisp[:results raw]{"\n"}
    #+MACRO: macroname line 1 of macro {{{newline}}} {{{newline}}}line 2 of macro
    

提交回复
热议问题