Вопрос

I'm exporting my org-mode file to LaTeX, and often use the C-c . timestamp as a top level heading as sort of a rolling diary.

However, when it exports to PDF, <2014-04-25 Fri> looks a little funny. Is there a general setting that would convert the timestamps to some kind of formatted date, like "Friday, April 25, 2014" or some other kind of common datestring format?

I looked here and understand that there are a couple ways of entering dates, but I imagine there must be output formatting, too. I see also that there is an export timestamp setting here,

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

But am unclear on what implementation would mean.

Это было полезно?

Решение

Try this:

(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))

Upd.: If you want to remove brackets <> from output string, you have to patch the function org-translate-time. Normal behaviour:

(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>"

With patched function like here 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"

The brackets <> are hardcoded in the function org-translate-time and you can't remove their by fixing org-time-stamp-custom-formats only.

Другие советы

Instead of patching org-translate-time, you can remove brackets by adding the following function to 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))

See http://endlessparentheses.com/better-time-stamps-in-org-export.html for more details.

The following works well for me. I like it, because it does not require filtering out "[]" or "<>" and choosing the target format is very simple. Do not forget to allow #+BIND by setting org-export-allow-bind-keywords to 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
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top