* ignoreheading in LaTeX export
@ 2014-03-27 8:23 Alan Schmitt
2014-03-27 8:49 ` Nicolas Goaziou
2014-03-29 14:17 ` Marcin Borkowski
0 siblings, 2 replies; 10+ messages in thread
From: Alan Schmitt @ 2014-03-27 8:23 UTC (permalink / raw)
To: emacs-orgmode
Hello,
I need to ignore a heading during a LaTeX export (I don't want the
"section" command to be generated, but I need the text to be included;
the heading is there because the previous one is tagged with "export").
I found this solution:
https://stackoverflow.com/questions/10295177/is-there-an-equivalent-of-org-modes-b-ignoreheading-for-non-beamer-documents
Is it still the way to go?
Thanks,
Alan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: ignoreheading in LaTeX export
2014-03-27 8:23 ignoreheading in LaTeX export Alan Schmitt
@ 2014-03-27 8:49 ` Nicolas Goaziou
2014-03-27 10:23 ` Sebastien Vauban
2014-03-27 13:08 ` Alan Schmitt
2014-03-29 14:17 ` Marcin Borkowski
1 sibling, 2 replies; 10+ messages in thread
From: Nicolas Goaziou @ 2014-03-27 8:49 UTC (permalink / raw)
To: Alan Schmitt; +Cc: emacs-orgmode
Hello,
Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> I need to ignore a heading during a LaTeX export (I don't want the
> "section" command to be generated, but I need the text to be included;
> the heading is there because the previous one is tagged with "export").
> I found this solution:
>
> https://stackoverflow.com/questions/10295177/is-there-an-equivalent-of-org-modes-b-ignoreheading-for-non-beamer-documents
>
> Is it still the way to go?
You can use a hook or a filter to remove the headline. I would use
a hook in this case. See (info "(org) Advanced configuration"), the
first example, with an appropriate MATCH argument for `org-map-entries'.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: ignoreheading in LaTeX export
2014-03-27 8:49 ` Nicolas Goaziou
@ 2014-03-27 10:23 ` Sebastien Vauban
2014-03-27 10:48 ` Nicolas Goaziou
2014-03-27 13:08 ` Alan Schmitt
1 sibling, 1 reply; 10+ messages in thread
From: Sebastien Vauban @ 2014-03-27 10:23 UTC (permalink / raw)
To: emacs-orgmode-mXXj517/zsQ
Nicolas Goaziou wrote:
> Alan Schmitt <alan.schmitt-o/5/jSaJEHk+NdeTPqioyti2O/JbrIOy@public.gmane.org> writes:
>
>> I need to ignore a heading during a LaTeX export
>
> You can use a hook or a filter to remove the headline. I would use
> a hook in this case.
Could you explain why you would choose a hook? What's guiding your
choice?
Thanks!
> See (info "(org) Advanced configuration"), the first example, with an
> appropriate MATCH argument for `org-map-entries'.
Best regards,
Seb
--
Sebastien Vauban
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: ignoreheading in LaTeX export
2014-03-27 10:23 ` Sebastien Vauban
@ 2014-03-27 10:48 ` Nicolas Goaziou
0 siblings, 0 replies; 10+ messages in thread
From: Nicolas Goaziou @ 2014-03-27 10:48 UTC (permalink / raw)
To: Sebastien Vauban; +Cc: public-emacs-orgmode-mXXj517/zsQ
Sebastien Vauban <sva-news-D0wtAvR13HarG/iDocfnWg@public.gmane.org>
writes:
> Could you explain why you would choose a hook? What's guiding your
> choice?
The fact that I work in the Org buffer and can use `org-map-entries',
which trivializes the problem here. OTOH, a filter works at the LaTeX
code level and ignoreheading tag may be missing (removed by some other
filter, tags ignored, etc).
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: ignoreheading in LaTeX export
2014-03-27 8:49 ` Nicolas Goaziou
2014-03-27 10:23 ` Sebastien Vauban
@ 2014-03-27 13:08 ` Alan Schmitt
2014-03-27 13:28 ` Nicolas Goaziou
1 sibling, 1 reply; 10+ messages in thread
From: Alan Schmitt @ 2014-03-27 13:08 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: emacs-orgmode
Nicolas Goaziou <n.goaziou@gmail.com> writes:
> Hello,
>
> Alan Schmitt <alan.schmitt@polytechnique.org> writes:
>
>> I need to ignore a heading during a LaTeX export (I don't want the
>> "section" command to be generated, but I need the text to be included;
>> the heading is there because the previous one is tagged with "export").
>> I found this solution:
>>
>> https://stackoverflow.com/questions/10295177/is-there-an-equivalent-of-org-modes-b-ignoreheading-for-non-beamer-documents
>>
>> Is it still the way to go?
>
> You can use a hook or a filter to remove the headline. I would use
> a hook in this case. See (info "(org) Advanced configuration"), the
> first example, with an appropriate MATCH argument for `org-map-entries'.
Thanks a lot for the suggestion, here is what I ended up doing:
#+begin_src emacs-lisp
(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 ()
(when (member "ignoreheading" (org-get-tags-at nil t))
(lambda () (delete-region (point) (progn (forward-line) (point))))))))
(setq org-export-before-parsing-hook '(as/delete-ignored-heading))
#+end_src
It works great.
I have a followup question (purely from an aesthetic point of view, the
code works fine). I see that a label is still generated in the LaTeX
file (there is a "\label{sec-1}" with just the "\maketitle" above it).
Is it expected?
Thanks again,
Alan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: ignoreheading in LaTeX export
2014-03-27 13:08 ` Alan Schmitt
@ 2014-03-27 13:28 ` Nicolas Goaziou
2014-03-27 14:24 ` Alan Schmitt
0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Goaziou @ 2014-03-27 13:28 UTC (permalink / raw)
To: Alan Schmitt; +Cc: emacs-orgmode
Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> Thanks a lot for the suggestion, here is what I ended up doing:
>
> #+begin_src emacs-lisp
> (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 ()
> (when (member "ignoreheading" (org-get-tags-at nil t))
> (lambda () (delete-region (point) (progn (forward-line) (point))))))))
>
> (setq org-export-before-parsing-hook '(as/delete-ignored-heading))
> #+end_src
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"))
> I have a followup question (purely from an aesthetic point of view, the
> code works fine). I see that a label is still generated in the LaTeX
> file (there is a "\label{sec-1}" with just the "\maketitle" above it).
> Is it expected?
I don't think so. Though, after a quick test, I'm unable to reproduce
it. Do you have an ECM?
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: ignoreheading in LaTeX export
2014-03-27 13:28 ` Nicolas Goaziou
@ 2014-03-27 14:24 ` Alan Schmitt
2014-03-27 21:51 ` Rasmus
0 siblings, 1 reply; 10+ messages in thread
From: Alan Schmitt @ 2014-03-27 14:24 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: emacs-orgmode
Nicolas Goaziou <n.goaziou@gmail.com> 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
--8<---------------cut here---------------start------------->8---
* No Export :noexport:
test
* Heading 1 :ignoreheading:
foo
* Heading 2
bar
--8<---------------cut here---------------end--------------->8---
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.
>> I have a followup question (purely from an aesthetic point of view, the
>> code works fine). I see that a label is still generated in the LaTeX
>> file (there is a "\label{sec-1}" with just the "\maketitle" above it).
>> Is it expected?
>
> I don't think so. Though, after a quick test, I'm unable to reproduce
> it. Do you have an ECM?
It is indeed a problem with the stack-overflow solution and not with
yours. I was confused when trying things out.
Thanks,
Alan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: ignoreheading in LaTeX export
2014-03-27 14:24 ` Alan Schmitt
@ 2014-03-27 21:51 ` Rasmus
2014-03-29 9:48 ` Alan Schmitt
0 siblings, 1 reply; 10+ messages in thread
From: Rasmus @ 2014-03-27 21:51 UTC (permalink / raw)
To: emacs-orgmode
Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> Nicolas Goaziou <n.goaziou@gmail.com> 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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: ignoreheading in LaTeX export
2014-03-27 21:51 ` Rasmus
@ 2014-03-29 9:48 ` Alan Schmitt
0 siblings, 0 replies; 10+ messages in thread
From: Alan Schmitt @ 2014-03-29 9:48 UTC (permalink / raw)
To: Rasmus; +Cc: emacs-orgmode
Hi Rasmus,
Rasmus <rasmus@gmx.us> writes:
> 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.
Thank you for this suggestion.
I went back to my original problem (how to neatly fold away some setup
code at the beginning of the file) and I'm now using a solution that
seems to work well.
- The setup heading has a 'ignoreheading' tag (there is no longer
a 'noexport' tag).
- Code blocks inside have a ':exports none' header.
- The next block where I want to add some heading-less text also has
a 'ignoreheading' tag.
- I'm using the "before-parsing" hook to get rid of these headings.
Thanks again,
Alan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: ignoreheading in LaTeX export
2014-03-27 8:23 ignoreheading in LaTeX export Alan Schmitt
2014-03-27 8:49 ` Nicolas Goaziou
@ 2014-03-29 14:17 ` Marcin Borkowski
1 sibling, 0 replies; 10+ messages in thread
From: Marcin Borkowski @ 2014-03-29 14:17 UTC (permalink / raw)
To: emacs-orgmode
Dnia 2014-03-27, o godz. 09:23:06
Alan Schmitt <alan.schmitt@polytechnique.org> napisał(a):
> Hello,
>
> I need to ignore a heading during a LaTeX export (I don't want the
> "section" command to be generated, but I need the text to be included;
> the heading is there because the previous one is tagged with
> "export"). I found this solution:
>
> https://stackoverflow.com/questions/10295177/is-there-an-equivalent-of-org-modes-b-ignoreheading-for-non-beamer-documents
>
> Is it still the way to go?
Just my 2 cents: you could always go for a /really/ dirty hack and do
it on the LaTeX side. AFAIR, tags end up somewhere in the title of the
section, so you can /redefine/ the =\section= macro to recognize that
and do nothing in that case. This is most probably an overkill, but
the general rule (maybe) worth remembering would be: if you want to
tweak something with LaTeX export, it /might/ be possible that it would
be (a) doable and maybe even (b) reasonable to do it on the LaTeX side.
> Thanks,
>
> Alan
Hth,
--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Adam Mickiewicz University
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2014-03-29 14:17 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-27 8:23 ignoreheading in LaTeX export Alan Schmitt
2014-03-27 8:49 ` Nicolas Goaziou
2014-03-27 10:23 ` Sebastien Vauban
2014-03-27 10:48 ` Nicolas Goaziou
2014-03-27 13:08 ` Alan Schmitt
2014-03-27 13:28 ` Nicolas Goaziou
2014-03-27 14:24 ` Alan Schmitt
2014-03-27 21:51 ` Rasmus
2014-03-29 9:48 ` Alan Schmitt
2014-03-29 14:17 ` Marcin Borkowski
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.