我将我的org-mode文件导出到LaTeX,并经常使用C-c .
时间戳作为顶级标题作为滚动日记。
但是,当它导出为PDF时,<2014-04-25 Fri>
看起来有点滑稽。是否有将时间戳转换为某种格式化日期的常规设置,例如&#34; 2014年4月25日星期五和#34;或其他一些常见的日期字符串格式?
我查看here并了解有几种输入日期的方法,但我想也必须有输出格式。我还看到导出时间戳设置here,
<:
Toggle inclusion of any time/date active/inactive stamps (org-export-with-timestamps).
但不清楚实施意味着什么。
答案 0 :(得分:5)
试试这个:
(let ((org-time-stamp-custom-formats
'("<%A, %B %d, %Y>" . "<%A, %B %d, %Y %H:%M>"))
(org-display-custom-times 't))
(org-latex-export-to-latex))
更新:如果要从输出字符串中删除括号<>
,则必须修补函数org-translate-time
。正常行为:
(let ((org-time-stamp-custom-formats
'("<%A, %B %d, %Y>" . "<%A, %B %d, %Y %H:%M>"))
(org-display-custom-times 't))
(org-translate-time "<2014-04-29 Tu.>")) => "<Tuesday, April 29, 2014>"
使用补丁功能,例如https://gist.github.com/boykov/11387660
(let ((org-time-stamp-custom-formats
'("<%A, %B %d, %Y>" . "<%A, %B %d, %Y %H:%M>"))
(org-display-custom-times 't))
(org-translate-time "<2014-04-29 Tu.>")) => "Tuesday, April 29, 2014"
括号<>
在org-translate-time
函数中是硬编码的,您只能通过修复org-time-stamp-custom-formats
来删除它们。
答案 1 :(得分:5)
您可以通过将以下函数添加到org-translate-time
来删除括号,而不是修补org-export-filter-timestamp-functions
:
(defun org-export-filter-timestamp-remove-brackets (timestamp backend info)
"removes relevant brackets from a timestamp"
(cond
((org-export-derived-backend-p backend 'latex)
(replace-regexp-in-string "[<>]\\|[][]" "" timestamp))
((org-export-derived-backend-p backend 'html)
(replace-regexp-in-string "&[lg]t;\\|[][]" "" timestamp))))
(eval-after-load 'ox '(add-to-list
'org-export-filter-timestamp-functions
'org-export-filter-timestamp-remove-brackets))
有关详细信息,请参阅http://endlessparentheses.com/better-time-stamps-in-org-export.html。
答案 2 :(得分:1)
以下内容适合我。我喜欢它,因为它不需要过滤掉“ []”或“ <>”,并且选择目标格式非常简单。通过将#+BIND
设置为org-export-allow-bind-keywords
,不要忘记允许t
。
#+BIND: org-latex-inactive-timestamp-format "%s"
#+BIND: org-latex-active-timestamp-format "%s"
#+BIND: org-export-filter-timestamp-functions (tmp-f-timestamp)
#+BEGIN_SRC emacs-lisp :exports results :results none
(defun tmp-f-timestamp (s backend info)
(cond
((org-export-derived-backend-p backend 'latex)
(let ((ts (org-timestamp-format (org-timestamp-from-string s) "%Y-%m-%d")))
(format "\\fbox{\\textbf{%s}} " ts)
))
(t s)))
#+END_SRC