emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] ignoreheading in LaTeX export


From: Rasmus
Subject: Re: [O] ignoreheading in LaTeX export
Date: Thu, 27 Mar 2014 22:51:27 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Alan Schmitt <address@hidden> writes:

> Nicolas Goaziou <address@hidden> writes:
>
>> I suggest to use the dedicated MATCH argument for `org-map-entries':
>>
>>   (defun as/delete-ignored-heading (backend)
>>       "Remove every headline with a tag `ignoreheading' in the
>>     current buffer. BACKEND is the export back-end being used, as
>>     a symbol."
>>       (org-map-entries
>>        (lambda () (delete-region (point) (progn (forward-line) (point))))
>>        "+ignoreheading"))
>
> Thank you, this works, with a big caveat (which makes this approach
> broken for me): with the following ECM
>
> * No Export                                                        :noexport:
>
> test
>
> * Heading 1                                                   :ignoreheading:
>
> foo
>
> * Heading 2
>
> bar
>
> the text under "Heading 1" is no longer present. I suspect the heading is
> removed before the ":noexport:" is processed, which captures the text as
> well (which is bad: the reason for the heading in the first place is to
> end the ":noexport:" block). I went back to the stack-overflow
> suggestion.

This is why you would want to use a filter rather than a hook
(i.e. you only want to retain the Org structure when exporting).
Here's a slightly modified version of the filter I use.  It sucks, but
ignoreheading is quite hard to get right, especially outside of LaTeX.
Note the comment in the first defun!  If you are unhappy with that
limitation you can use a regexp to look for ignoreheading in the first
line of org-ignoreheading function.  I think I even have an old
version somewhere that uses a regexp.

(defun rasmus/get-org-headline-string-element  (headline backend info)
  "Return the org element representation of an element.

Will NOT work with headlines like this one, that has no text-properties

* =verb="
  (let ((prop-point (next-property-change 0 headline)))
    (if prop-point (plist-get (text-properties-at prop-point headline) 
:parent))))
      

(defun rasmus/org-latex-ignoreheading (headline backend info)
  "Strip headline from HEADLINE if it has tag ignoreheading.

Somewhat broken for ascii. . .
"
  (when (org-export-derived-backend-p backend 'latex 'ascii)
    (let ((tags
           (org-element-property :tags
                                 (rasmus/get-org-headline-string-element 
headline backend info))))
      (when (and tags (member-ignore-case "ignoreheading" tags))
        (string-match "\\`.*\n.*\n" headline)
        (replace-match "" nil nil headline)))))

(add-to-list 'org-export-filter-headline-functions
               'rasmus/org-latex-ignoreheading)


—Rasmus

-- 
Sådan en god dansk lagereddike kan man slet ikke bruge mere




reply via email to

[Prev in Thread] Current Thread [Next in Thread]