* Wrapping section within LaTeX environment
@ 2015-12-13 14:00 Xavier Garrido
2015-12-14 1:39 ` John Kitchin
2015-12-16 3:41 ` Robert Klein
0 siblings, 2 replies; 6+ messages in thread
From: Xavier Garrido @ 2015-12-13 14:00 UTC (permalink / raw)
To: emacs-orgmode@gnu.org
Dear orgers,
I would like to wrap a given org section between =\begin,\end= LaTeX
environment. These sections are identified by a special tag :correction:
and to initiate the =\begin= flag I have basically no problem by using
the org-export-filter-headline-function filter. The problem comes when
I want to close the environment i.e. when another section starts. I have
try this piece of code
#+BEGIN_SRC emacs-lisp
(setq correction-flag nil)
(defun cpp-correction-headline (contents backend info)
(if (and (org-export-derived-backend-p backend 'latex)
(string-match "\\`.*correction.*\n" (downcase contents)))
(progn
(setq correction-flag t)
(replace-match "\\\\begin{correction}" nil nil contents)
)
(when correction-flag
(setq correction-flag nil)
(concat "\\end{correction}" contents))
)
)
(add-to-list 'org-export-filter-headline-functions
'cpp-correction-headline)
#+END_SRC
but I get several =\end{correction}= in the produced LaTeX file.
Actually this is much more a emacs-lisp related question since the
boolean =correction-flag= seems not to work and I don't know why (of
course I have very little knowledge in lisp). Can some emacs-lisp
experts helps me understand why the above code just does not work.
Thanks a lot,
Xavier
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Wrapping section within LaTeX environment
2015-12-13 14:00 Wrapping section within LaTeX environment Xavier Garrido
@ 2015-12-14 1:39 ` John Kitchin
2015-12-14 7:06 ` Xavier Garrido
2015-12-16 3:41 ` Robert Klein
1 sibling, 1 reply; 6+ messages in thread
From: John Kitchin @ 2015-12-14 1:39 UTC (permalink / raw)
To: Xavier Garrido; +Cc: emacs-orgmode@gnu.org
could you provide a brief example of what you want to happen?
i.e. are you looking for this:
* some heading :correction:
one line of content
to convert to this in LaTeX?
\begin{correction}
one line of content
\end{correction}
Xavier Garrido writes:
> Dear orgers,
>
> I would like to wrap a given org section between =\begin,\end= LaTeX
> environment. These sections are identified by a special tag :correction:
> and to initiate the =\begin= flag I have basically no problem by using
> the org-export-filter-headline-function filter. The problem comes when
> I want to close the environment i.e. when another section starts. I have
> try this piece of code
>
> #+BEGIN_SRC emacs-lisp
> (setq correction-flag nil)
> (defun cpp-correction-headline (contents backend info)
> (if (and (org-export-derived-backend-p backend 'latex)
> (string-match "\\`.*correction.*\n" (downcase contents)))
> (progn
> (setq correction-flag t)
> (replace-match "\\\\begin{correction}" nil nil contents)
> )
> (when correction-flag
> (setq correction-flag nil)
> (concat "\\end{correction}" contents))
> )
> )
> (add-to-list 'org-export-filter-headline-functions
> 'cpp-correction-headline)
> #+END_SRC
>
> but I get several =\end{correction}= in the produced LaTeX file.
> Actually this is much more a emacs-lisp related question since the
> boolean =correction-flag= seems not to work and I don't know why (of
> course I have very little knowledge in lisp). Can some emacs-lisp
> experts helps me understand why the above code just does not work.
>
> Thanks a lot,
> Xavier
--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Wrapping section within LaTeX environment
2015-12-14 1:39 ` John Kitchin
@ 2015-12-14 7:06 ` Xavier Garrido
2015-12-14 11:32 ` John Kitchin
0 siblings, 1 reply; 6+ messages in thread
From: Xavier Garrido @ 2015-12-14 7:06 UTC (permalink / raw)
To: John Kitchin; +Cc: emacs-orgmode@gnu.org
Le 14/12/2015 02:39, John Kitchin a écrit :
> could you provide a brief example of what you want to happen?
>
> i.e. are you looking for this:
>
> * some heading :correction:
> one line of content
>
> to convert to this in LaTeX?
>
> \begin{correction}
> one line of content
> \end{correction}
>
Exactly. Actually when I read your mail I realize that
=org-export-filter-headline-functions= filter not only give access to
the heading but to the whole content within the heading. So,
#+BEGIN_SRC emacs-lisp
(defun cpp-correction-headline (contents backend info)
(when (and (org-export-derived-backend-p backend 'latex)
(string-match "\\`.*correction.*\n" (downcase contents)))
(concat "\\begin{correction}" (replace-regexp-in-string
"\\`.*correction.*\n" "" contents) "\\end{correction}"))
)
(add-to-list 'org-export-filter-headline-functions
'cpp-correction-headline)
#+END_SRC
is doing what I want. So thanks for the insights and sorry for the noise.
Xavier
>
> Xavier Garrido writes:
>
>> Dear orgers,
>>
>> I would like to wrap a given org section between =\begin,\end= LaTeX
>> environment. These sections are identified by a special tag :correction:
>> and to initiate the =\begin= flag I have basically no problem by using
>> the org-export-filter-headline-function filter. The problem comes when
>> I want to close the environment i.e. when another section starts. I have
>> try this piece of code
>>
>> #+BEGIN_SRC emacs-lisp
>> (setq correction-flag nil)
>> (defun cpp-correction-headline (contents backend info)
>> (if (and (org-export-derived-backend-p backend 'latex)
>> (string-match "\\`.*correction.*\n" (downcase contents)))
>> (progn
>> (setq correction-flag t)
>> (replace-match "\\\\begin{correction}" nil nil contents)
>> )
>> (when correction-flag
>> (setq correction-flag nil)
>> (concat "\\end{correction}" contents))
>> )
>> )
>> (add-to-list 'org-export-filter-headline-functions
>> 'cpp-correction-headline)
>> #+END_SRC
>>
>> but I get several =\end{correction}= in the produced LaTeX file.
>> Actually this is much more a emacs-lisp related question since the
>> boolean =correction-flag= seems not to work and I don't know why (of
>> course I have very little knowledge in lisp). Can some emacs-lisp
>> experts helps me understand why the above code just does not work.
>>
>> Thanks a lot,
>> Xavier
>
> --
> Professor John Kitchin
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Wrapping section within LaTeX environment
2015-12-14 7:06 ` Xavier Garrido
@ 2015-12-14 11:32 ` John Kitchin
0 siblings, 0 replies; 6+ messages in thread
From: John Kitchin @ 2015-12-14 11:32 UTC (permalink / raw)
To: Xavier Garrido; +Cc: emacs-orgmode@gnu.org
Cool. You might want to change your string match to :correction: so you
don't inadvertently wrap a section with the word correction in the body
though. That seems like a possibility here.
Xavier Garrido writes:
> Le 14/12/2015 02:39, John Kitchin a écrit :
>> could you provide a brief example of what you want to happen?
>>
>> i.e. are you looking for this:
>>
>> * some heading :correction:
>> one line of content
>>
>> to convert to this in LaTeX?
>>
>> \begin{correction}
>> one line of content
>> \end{correction}
>>
>
> Exactly. Actually when I read your mail I realize that
> =org-export-filter-headline-functions= filter not only give access to
> the heading but to the whole content within the heading. So,
>
> #+BEGIN_SRC emacs-lisp
> (defun cpp-correction-headline (contents backend info)
> (when (and (org-export-derived-backend-p backend 'latex)
> (string-match "\\`.*correction.*\n" (downcase contents)))
> (concat "\\begin{correction}" (replace-regexp-in-string
> "\\`.*correction.*\n" "" contents) "\\end{correction}"))
> )
> (add-to-list 'org-export-filter-headline-functions
> 'cpp-correction-headline)
> #+END_SRC
>
> is doing what I want. So thanks for the insights and sorry for the noise.
>
> Xavier
>
>
>>
>> Xavier Garrido writes:
>>
>>> Dear orgers,
>>>
>>> I would like to wrap a given org section between =\begin,\end= LaTeX
>>> environment. These sections are identified by a special tag :correction:
>>> and to initiate the =\begin= flag I have basically no problem by using
>>> the org-export-filter-headline-function filter. The problem comes when
>>> I want to close the environment i.e. when another section starts. I have
>>> try this piece of code
>>>
>>> #+BEGIN_SRC emacs-lisp
>>> (setq correction-flag nil)
>>> (defun cpp-correction-headline (contents backend info)
>>> (if (and (org-export-derived-backend-p backend 'latex)
>>> (string-match "\\`.*correction.*\n" (downcase contents)))
>>> (progn
>>> (setq correction-flag t)
>>> (replace-match "\\\\begin{correction}" nil nil contents)
>>> )
>>> (when correction-flag
>>> (setq correction-flag nil)
>>> (concat "\\end{correction}" contents))
>>> )
>>> )
>>> (add-to-list 'org-export-filter-headline-functions
>>> 'cpp-correction-headline)
>>> #+END_SRC
>>>
>>> but I get several =\end{correction}= in the produced LaTeX file.
>>> Actually this is much more a emacs-lisp related question since the
>>> boolean =correction-flag= seems not to work and I don't know why (of
>>> course I have very little knowledge in lisp). Can some emacs-lisp
>>> experts helps me understand why the above code just does not work.
>>>
>>> Thanks a lot,
>>> Xavier
>>
>> --
>> Professor John Kitchin
>> Doherty Hall A207F
>> Department of Chemical Engineering
>> Carnegie Mellon University
>> Pittsburgh, PA 15213
>> 412-268-7803
>> @johnkitchin
>> http://kitchingroup.cheme.cmu.edu
>>
--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Wrapping section within LaTeX environment
2015-12-13 14:00 Wrapping section within LaTeX environment Xavier Garrido
2015-12-14 1:39 ` John Kitchin
@ 2015-12-16 3:41 ` Robert Klein
2015-12-16 8:48 ` Xavier Garrido
1 sibling, 1 reply; 6+ messages in thread
From: Robert Klein @ 2015-12-16 3:41 UTC (permalink / raw)
To: Xavier Garrido, emacs-orgmode@gnu.org
Hi
On 12/13/2015 03:00 PM, Xavier Garrido wrote:
> Dear orgers,
>
> I would like to wrap a given org section between =\begin,\end= LaTeX
> environment. These sections are identified by a special tag :correction:
> and to initiate the =\begin= flag I have basically no problem by using
> the org-export-filter-headline-function filter. The problem comes when
> I want to close the environment i.e. when another section starts. I have
> try this piece of code
>
> #+BEGIN_SRC emacs-lisp
> (setq correction-flag nil)
> (defun cpp-correction-headline (contents backend info)
> (if (and (org-export-derived-backend-p backend 'latex)
> (string-match "\\`.*correction.*\n" (downcase contents)))
> (progn
> (setq correction-flag t)
> (replace-match "\\\\begin{correction}" nil nil contents)
> )
> (when correction-flag
> (setq correction-flag nil)
> (concat "\\end{correction}" contents))
> )
> )
> (add-to-list 'org-export-filter-headline-functions
> 'cpp-correction-headline)
> #+END_SRC
If I read this right, you are writing the \end{correction} when the
headline function is called for the /following/ headline.
Then the (when...) should be outside the (if..) (because the
string-match condition isn't valid anymore).
Of course you still get issues when two consecutive sections are tagged
for correction -- and there has to be a follow-up heading to the one
tagged for correction.
Your code from your second mail does the job perfectly, but I've been
intrigued in figuring this one out :)
Best regards
Robert
>
> but I get several =\end{correction}= in the produced LaTeX file.
> Actually this is much more a emacs-lisp related question since the
> boolean =correction-flag= seems not to work and I don't know why (of
> course I have very little knowledge in lisp). Can some emacs-lisp
> experts helps me understand why the above code just does not work.
>
> Thanks a lot,
> Xavier
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Wrapping section within LaTeX environment
2015-12-16 3:41 ` Robert Klein
@ 2015-12-16 8:48 ` Xavier Garrido
0 siblings, 0 replies; 6+ messages in thread
From: Xavier Garrido @ 2015-12-16 8:48 UTC (permalink / raw)
To: Robert Klein, emacs-orgmode@gnu.org
Hi Robert,
Le 16/12/2015 04:41, Robert Klein a écrit :
> Hi
>
> On 12/13/2015 03:00 PM, Xavier Garrido wrote:
>> Dear orgers,
>>
>> I would like to wrap a given org section between =\begin,\end= LaTeX
>> environment. These sections are identified by a special tag :correction:
>> and to initiate the =\begin= flag I have basically no problem by using
>> the org-export-filter-headline-function filter. The problem comes when
>> I want to close the environment i.e. when another section starts. I have
>> try this piece of code
>>
>> #+BEGIN_SRC emacs-lisp
>> (setq correction-flag nil)
>> (defun cpp-correction-headline (contents backend info)
>> (if (and (org-export-derived-backend-p backend 'latex)
>> (string-match "\\`.*correction.*\n" (downcase contents)))
>> (progn
>> (setq correction-flag t)
>> (replace-match "\\\\begin{correction}" nil nil contents)
>> )
>> (when correction-flag
>> (setq correction-flag nil)
>> (concat "\\end{correction}" contents))
>> )
>> )
>> (add-to-list 'org-export-filter-headline-functions
>> 'cpp-correction-headline)
>> #+END_SRC
>
> If I read this right, you are writing the \end{correction} when the
> headline function is called for the /following/ headline.
>
> Then the (when...) should be outside the (if..) (because the
> string-match condition isn't valid anymore).
As far as I understand emacs-lisp, the (when ...) is within the else so
when the string match condition is not valid. That's why I do not
understand why this complicated filter was not working. Anyway, my
second try was much better and easier to understand (I also apply
suggestion from John to avoid inclusion of "correction" section title).
Thanks for having a look,
Xavier
--
|
|__ GARRIDO Xavier Laboratoire de l'Accélérateur Linéaire
/\ NEMO Université Paris-Sud 11
/--\ garrido@lal.in2p3.fr UMR 8607
| garrido@in2p3.fr Batiment 200
|__ +33 1.64.46.84.28 91898 Orsay Cedex, France
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-12-16 8:56 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-13 14:00 Wrapping section within LaTeX environment Xavier Garrido
2015-12-14 1:39 ` John Kitchin
2015-12-14 7:06 ` Xavier Garrido
2015-12-14 11:32 ` John Kitchin
2015-12-16 3:41 ` Robert Klein
2015-12-16 8:48 ` Xavier Garrido
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).