emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Problem with sectioning function for LaTeX export
@ 2010-04-18 10:05 Sebastian Hofer
  2010-04-27 15:44 ` Carsten Dominik
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Hofer @ 2010-04-18 10:05 UTC (permalink / raw)
  To: emacs-orgmode

Hi all,
I'm trying to write my own sectioning function for latex export of my 
CV. What it does is to read out some property of the given headline and 
pass it to a latex command:

(defun my-org-cv-sectioning (lvl heading)
   (let ((year)
         (formatlist)
         (cleanheading (substring-no-properties heading 1)))
     (with-current-buffer (org-find-base-buffer-visiting "cv.org")
       (let ((headingpoint (find-custom-id cleanheading)))
         (if headingpoint
             (progn
               (goto-char headingpoint)
               (setq year (org-entry-get nil "YEAR"))))))
     (setq formatlist (nth (- 1 lvl) my-org-cv-sectioning-list))
     (list cleanheading
           (format (car formatlist) (if year year "") cleanheading)
           (format (car (cdr formatlist)) (if year year "") cleanheading))))

The function find-custom-id returns the point of the heading, 
my-org-cv-sectioning list contains the customized latex commands. As you 
may see, I'm an elisp newbie, so excuse the coding style, or even 
better, make suggestions for improvements! There might be a much nicer 
way to read out the wanted properties (also cf. point 2 below), so if 
you have any suggestions on that, I would be glad to hear them!

Anyway, there are currently two problems:

- The function reads out the properties correctly, but the export 
command throws an error. So I guess I'm not getting the format of the 
output right, but I can't really make sense of the description in the 
org-export-latex-classes docstring. Currently the function is returning 
something like this: ("Heading" ("\section[year]{Heading}" 
"\section*[year]{Heading}")). Isn't this what it's supposed to look 
like? The error message is the following:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
   format(nil "Heading" "")
   org-export-latex-subcontent(<snipped>)
   org-export-latex-sub(<snipped>)
   org-export-latex-global(((<snipped>))))
   org-export-as-latex(nil nil nil "*Org LaTeX Export*")
   org-export-as-latex-to-buffer(nil)
   call-interactively(org-export-as-latex-to-buffer)
   org-export(nil)
   call-interactively(org-export nil nil)

- As you can see I am using org-find-base-buffer-visiting find the 
buffer of the org file, but of course its argument can't stay hardcoded 
like this. I could also use the org mapping function, but still I would 
need filename. Can someone give me a hint how to solve this in a nice way?

Thanks for any help and thanks to Carsten for his incredible work! I 
keep getting surprised be the capabilities of org-mode almost every day.
Cheers, Sebastian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Problem with sectioning function for LaTeX export
  2010-04-18 10:05 Sebastian Hofer
@ 2010-04-27 15:44 ` Carsten Dominik
  0 siblings, 0 replies; 4+ messages in thread
From: Carsten Dominik @ 2010-04-27 15:44 UTC (permalink / raw)
  To: Sebastian Hofer; +Cc: emacs-orgmode


On Apr 18, 2010, at 12:05 PM, Sebastian Hofer wrote:

> Hi all,
> I'm trying to write my own sectioning function for latex export of  
> my CV. What it does is to read out some property of the given  
> headline and pass it to a latex command:
>
> (defun my-org-cv-sectioning (lvl heading)
>  (let ((year)
>        (formatlist)
>        (cleanheading (substring-no-properties heading 1)))
>    (with-current-buffer (org-find-base-buffer-visiting "cv.org")
>      (let ((headingpoint (find-custom-id cleanheading)))
>        (if headingpoint
>            (progn
>              (goto-char headingpoint)
>              (setq year (org-entry-get nil "YEAR"))))))
>    (setq formatlist (nth (- 1 lvl) my-org-cv-sectioning-list))
>    (list cleanheading
>          (format (car formatlist) (if year year "") cleanheading)
>          (format (car (cdr formatlist)) (if year year "")  
> cleanheading))))
>
> The function find-custom-id returns the point of the heading, my-org- 
> cv-sectioning list contains the customized latex commands. As you  
> may see, I'm an elisp newbie, so excuse the coding style, or even  
> better, make suggestions for improvements! There might be a much  
> nicer way to read out the wanted properties (also cf. point 2  
> below), so if you have any suggestions on that, I would be glad to  
> hear them!
>
> Anyway, there are currently two problems:
>
> - The function reads out the properties correctly, but the export  
> command throws an error. So I guess I'm not getting the format of  
> the output right, but I can't really make sense of the description  
> in the org-export-latex-classes docstring. Currently the function is  
> returning something like this: ("Heading" ("\section[year]{Heading}"  
> "\section*[year]{Heading}")). Isn't this what it's supposed to look  
> like? The error message is the following:

I think it must be

("Heading" "\section[year]{%s}" "\section*[year]{%s}")

Note the %s for the heading, and also it i just one flat list of 3  
items.

And yes, this is not too well documented.

>
> Debugger entered--Lisp error: (wrong-type-argument stringp nil)
>  format(nil "Heading" "")
>  org-export-latex-subcontent(<snipped>)
>  org-export-latex-sub(<snipped>)
>  org-export-latex-global(((<snipped>))))
>  org-export-as-latex(nil nil nil "*Org LaTeX Export*")
>  org-export-as-latex-to-buffer(nil)
>  call-interactively(org-export-as-latex-to-buffer)
>  org-export(nil)
>  call-interactively(org-export nil nil)
>
> - As you can see I am using org-find-base-buffer-visiting find the  
> buffer of the org file, but of course its argument can't stay  
> hardcoded like this. I could also use the org mapping function, but  
> still I would need filename. Can someone give me a hint how to solve  
> this in a nice way?

Use
    (org-find-base-buffer-visiting org-current-export-file)

HTH

- Carsten

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Problem with sectioning function for LaTeX export
@ 2010-04-29 12:10 Sebastian Hofer
  2010-04-29 23:05 ` Sebastian Hofer
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Hofer @ 2010-04-29 12:10 UTC (permalink / raw)
  To: emacs-orgmode

Hi Carsten,
thanks for your reply!

At Tue, 27 Apr 2010 17:44:07 +0200,
Carsten Dominik wrote:
> I think it must be
> 
> ("Heading" "\section[year]{%s}" "\section*[year]{%s}")
> 
> Note the %s for the heading, and also it i just one flat list of 3  
> items.
> 
> And yes, this is not too well documented. 

I tried that actually but to no avail. I tracked down the problem to the following code in org-latex.el

(if (consp (cdr sec))
    (setq start (nth (if num 0 2) sec)
	  end (nth (if num 1 3) sec))
  (setq start (if num (car sec) (cdr sec))))

For a flat list as you suggested sec is ("\section[year]{%s}" "\section*[year]{%s}"). The thing is that then (consp (cdr sec)) evaluates to true, which I think is not the supposed behaviour. Replacing (cdr sec) by (cadr sec) would fix this. Is this a bug or just me being too stupid?

On another subject: Wouldn't it be nice if the properties of the current headline would be accessible by the sectioning function? I think that would proof very powerful to create customized export classes (together with customized latex commands). And I guess it would be quite easy to implement, right?

Anyway, thanks for your help (and of course for your great work on org-mode, I really love it!)
Sebastian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Problem with sectioning function for LaTeX export
  2010-04-29 12:10 Problem with sectioning function for LaTeX export Sebastian Hofer
@ 2010-04-29 23:05 ` Sebastian Hofer
  0 siblings, 0 replies; 4+ messages in thread
From: Sebastian Hofer @ 2010-04-29 23:05 UTC (permalink / raw)
  To: emacs-orgmode

Oh, nevermind. I figured it out,
(cons Heading (cons "\section[year]{%s}" "\section*[year]{%s}"))
solves the problem. I guess I really need to learn more about the 
different types of sequences in lisp. Sorry for that.

Cheers, Sebastian

On 29.04.10 14:10 Uhr, Sebastian Hofer wrote:
> Hi Carsten,
> thanks for your reply!
>
> At Tue, 27 Apr 2010 17:44:07 +0200,
> Carsten Dominik wrote:
>> I think it must be
>>
>> ("Heading" "\section[year]{%s}" "\section*[year]{%s}")
>>
>> Note the %s for the heading, and also it i just one flat list of 3
>> items.
>>
>> And yes, this is not too well documented.
>
> I tried that actually but to no avail. I tracked down the problem to the following code in org-latex.el
>
> (if (consp (cdr sec))
>      (setq start (nth (if num 0 2) sec)
> 	  end (nth (if num 1 3) sec))
>    (setq start (if num (car sec) (cdr sec))))
>
> For a flat list as you suggested sec is ("\section[year]{%s}" "\section*[year]{%s}"). The thing is that then (consp (cdr sec)) evaluates to true, which I think is not the supposed behaviour. Replacing (cdr sec) by (cadr sec) would fix this. Is this a bug or just me being too stupid?
>
> On another subject: Wouldn't it be nice if the properties of the current headline would be accessible by the sectioning function? I think that would proof very powerful to create customized export classes (together with customized latex commands). And I guess it would be quite easy to implement, right?
>
> Anyway, thanks for your help (and of course for your great work on org-mode, I really love it!)
> Sebastian
>
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-04-29 23:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-29 12:10 Problem with sectioning function for LaTeX export Sebastian Hofer
2010-04-29 23:05 ` Sebastian Hofer
  -- strict thread matches above, loose matches on Subject: below --
2010-04-18 10:05 Sebastian Hofer
2010-04-27 15:44 ` Carsten Dominik

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