用换行符定义组织模式宏 [英] Define org mode macro with line breaks
问题描述
可以在 org
定义宏> 文件如下:
It is possible to define a macro in an org
file as follow:
#+MACRO: macroname <here comes the body of the macro>
是否可以定义包含换行符的宏?即,类似于:
Is it possible to define a macro that contains line breaks? I.e., something like:
#+MACRO: macroname line 1 of macro
line 2 of macro
特别是这个宏会被展开为
In particular, this macro will be expanded to
line 1 of macro
line 2 of macro
我的动机是有一个宏可以扩展为包含两个段落的文本块.
My motivation is to have a macro that expands to a block of text which contains, for instance, two paragraphs.
推荐答案
这不仅是可能的,而且很容易做到.你只需要成为关于如何插入换行符的创意.我使用 Org Babel 来破解宏.以下对我有用:
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
因此,鉴于此文档:
#+MACRO: newline src_emacs-lisp[:results raw]{"\n"}
#+MACRO: macroname line 1 of macro {{{newline}}}line 2 of macro
{{{macroname}}}
导出到 Org 模式给出以下内容
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
这篇关于用换行符定义组织模式宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!