导出时的组织模式时间戳格式



我正在将组织模式文件导出到LaTeX,并且经常使用C-c .时间戳作为顶级标题,就像滚动日记一样。

然而,当它导出为PDF时,<2014-04-25 Fri>看起来有点滑稽。是否有一个通用设置可以将时间戳转换为某种格式的日期,如"2014年4月25日星期五"或其他常见的日期字符串格式?

我看了一下这里,知道有几种输入日期的方法,但我想也必须有输出格式。我还看到这里有一个导出时间戳设置,

<:
Toggle inclusion of any time/date active/inactive stamps (org-export-with-timestamps). 

但我不清楚实施意味着什么。

试试这个:

(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来移除它们。

您可以通过向org-export-filter-timestamp-functions添加以下函数来移除括号,而不是修补org-translate-time

(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了解更多详细信息。

以下内容对我来说很好。我喜欢它,因为它不需要过滤掉"[]"或"<>",而且选择目标格式非常简单。不要忘记通过将org-export-allow-bind-keywords设置为t来允许#+BIND

#+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

相关内容

  • 没有找到相关文章

最新更新