【发布时间】:2013-02-23 03:36:14
【问题描述】:
我正在以 org 模式编写文档。是否可以对分布在文档中的练习使用计数器而不是自己编号?我将其导出为 HTML 和 PDF(通过 LaTeX)。示例:
* First chapter
Blabla.
Exercise 1.
* Second chapter.
Blabla
Exercise 2.
* Third chapter.
Exercise 3.
Exercise 4.
【问题讨论】:
我正在以 org 模式编写文档。是否可以对分布在文档中的练习使用计数器而不是自己编号?我将其导出为 HTML 和 PDF(通过 LaTeX)。示例:
* First chapter
Blabla.
Exercise 1.
* Second chapter.
Blabla
Exercise 2.
* Third chapter.
Exercise 3.
Exercise 4.
【问题讨论】:
我在 org-mode 中使用动态块解决了这个问题。
在我的 init.el 中,我定义了以下内容:
(setf exercise-counter 0)
(defun org-dblock-write:reset-exercise-counter (params)
(setf exercise-counter 0))
(defun org-dblock-write:exercise (params)
(incf exercise-counter)
(insert (concat "Exercise " (int-to-string exercise-counter) ".")))
在我的文档顶部我重置了计数器:
#+BEGIN: reset-counter
#+END
在文档中展开我现在可以这样说:
#+BEGIN: exercise
#+END
Blablabla.
#+BEGIN: exercise
#+END
Blablabla.
调用org-update-all-dblocks 后,将插入正确的号码。
如果有什么可以改进的,欢迎提出建议。
导出时如何自动调用org-update-all-dblocks?
回答:像这样:(add-hook 'org-export-first-hook 'org-update-all-dblocks)
【讨论】: