Hi all,

I am writing a custom parse tree filter that does the following (LaTeX
backend): if a heading has the ':font:' property, the content of that
heading is enclosed in a LaTeX group. If the property is ':fontfeature:',
then the content is enclosed in a different group. The filter works fine
when all the headings are at the same level. But with different levels,
it does not returns the expected result. It's evident that I'm doing
something catastrophically wrong :-). I wonder if anyone could put me on
the track of the origin of my error...

Below, the offender function and a sample. Thanks in advance!

Best regards,

Juan Manuel 

#+BIND: org-export-filter-parse-tree-functions 
(my-custom-filters/fontspec-headline)
#+begin_src emacs-lisp :exports results :results none
  (defun my-custom-filters/fontspec-headline (tree backend info)
    (when (org-export-derived-backend-p backend 'latex)
      (org-element-map tree 'headline
        (lambda (hl)
          (cond ((org-element-property :FONT hl)
                 (let* ((font (org-element-property :FONT hl))
                        (contents (org-element-interpret-data 
(org-element-contents hl)))
                        (contents-new (concat
                                       "@@latex:{\\fontspec{@@"
                                       (replace-regexp-in-string 
"\s*\\(\\[.+\\]\\)\s*" "" font)
                                       "@@latex:}%@@\n"
                                       (if (string-match "\\(\\[.+\\]\\)" font)
                                           (concat "@@latex:" (match-string 1 
font) "%@@\n\n")
                                         "\n")
                                       contents
                                       "\n@@latex:}@@")))
                   (org-element-set-contents hl (with-temp-buffer
                                                  (insert contents-new)
                                                  (org-element-parse-buffer)))))
                ((org-element-property :FONTFEATURE hl)
                 (let* ((fontfeature (org-element-property :FONTFEATURE hl))
                        (contents (org-element-interpret-data 
(org-element-contents hl)))
                        (contents-new (concat
                                       "@@latex:{\\addfontfeature{@@"
                                       fontfeature
                                       "@@latex:}%@@\n"
                                       contents
                                       "\n@@latex:}@@")))
                   (org-element-set-contents hl (with-temp-buffer
                                                  (insert contents-new)
                                                  
(org-element-parse-buffer)))))))
        info)
      tree))
#+end_src

* Minion Pro
  :PROPERTIES:
  :font: Minion Pro [Style=Historic,Color=teal]
  :END:

Lorem ipsum dolor.

** Lowercase Numbers
   :PROPERTIES:
   :fontfeature: Numbers=Lowercase
   :END:

Lorem ipsum dolor 1234567890.

*** Letter Space
    :PROPERTIES:
    :fontfeature: LetterSpace=14.6
    :END:

Lorem ipsum dolor 1234567890.

Reply via email to