emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Including source when exporting in PDF
@ 2012-01-04 21:29 Frozenlock
  2012-01-06  7:45 ` Eric Schulte
  0 siblings, 1 reply; 12+ messages in thread
From: Frozenlock @ 2012-01-04 21:29 UTC (permalink / raw)
  To: emacs-orgmode

I am a strong advocate in keeping the source of everything.

However,  a source can easily be lost if it doesn't follow the document.
In LaTeX, there's a package to attach a file to a PDF (like when you
attach a file to an email).
By doing so, the source will follow the PDF even if the common reader
have no clue what it's for, or even how to use it.

Here is how I attach my org source to every document I export to PDF:

--8<---------------cut here---------------start------------->8---

;; Include the source file for every exported PDF (org-mode)
(eval-after-load "org-exp"
  '(defadvice org-export-as-latex (around org-export-add-source-pdf activate)
     "Add the source (org file) to the resulting pdf file"
     (let ((filename (buffer-name)))
       ad-do-it ;do the function
       (let ((latex-buffer ad-return-value))
	 (set-buffer latex-buffer)
	 (while (re-search-forward "\\\\usepackage{.+}" nil t)); go to the
end of packages
	 (insert "\n\\usepackage{attachfile2}"); the package needed to attach files
	 (when (re-search-forward "\\\\end{document}" nil t)
	   (forward-line -1)
	   (insert
	    (concat
	     "\\vfill\n"
	     "\\footnotesize\n"
	     "The source of this document is an Org-Mode file attached here:"
	     "\n\\attachfile"
	     "{" filename "}")))
	 (save-buffer)))))

--8<---------------cut here---------------end--------------->8---

This is by no mean a patch, but rather a quick hack. Perhaps someone
with a working knowledge of the org-export could find a way to add a
source option?


Cheers!

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

* Re: Including source when exporting in PDF
  2012-01-04 21:29 Including source when exporting in PDF Frozenlock
@ 2012-01-06  7:45 ` Eric Schulte
  2012-01-11 15:28   ` Rainer M Krug
  0 siblings, 1 reply; 12+ messages in thread
From: Eric Schulte @ 2012-01-06  7:45 UTC (permalink / raw)
  To: Frozenlock; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1765 bytes --]

Frozenlock <frozenlock@gmail.com> writes:

> I am a strong advocate in keeping the source of everything.
>
> However,  a source can easily be lost if it doesn't follow the document.
> In LaTeX, there's a package to attach a file to a PDF (like when you
> attach a file to an email).
> By doing so, the source will follow the PDF even if the common reader
> have no clue what it's for, or even how to use it.
>

This sounds like a great Reproducible Research practice.

>
> Here is how I attach my org source to every document I export to PDF:
>
> ;; Include the source file for every exported PDF (org-mode)
> (eval-after-load "org-exp"
>   '(defadvice org-export-as-latex (around org-export-add-source-pdf activate)
>      "Add the source (org file) to the resulting pdf file"
>      (let ((filename (buffer-name)))
>        ad-do-it ;do the function
>        (let ((latex-buffer ad-return-value))
> 	 (set-buffer latex-buffer)
> 	 (while (re-search-forward "\\\\usepackage{.+}" nil t)); go to the
> end of packages
> 	 (insert "\n\\usepackage{attachfile2}"); the package needed to attach files
> 	 (when (re-search-forward "\\\\end{document}" nil t)
> 	   (forward-line -1)
> 	   (insert
> 	    (concat
> 	     "\\vfill\n"
> 	     "\\footnotesize\n"
> 	     "The source of this document is an Org-Mode file attached here:"
> 	     "\n\\attachfile"
> 	     "{" filename "}")))
> 	 (save-buffer)))))
>
>
> This is by no mean a patch, but rather a quick hack. Perhaps someone
> with a working knowledge of the org-export could find a way to add a
> source option?
>

I think this practice may not actually require any changes to the
Org-mode core.  The attached small Org-mode file will attach itself to
pdf exports using only features already present in Org-mode.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: with-the-source.org --]
[-- Type: text/x-org, Size: 189 bytes --]

#+Title: this has the source included
#+Author: Eric Schulte
#+LaTeX_Header: \usepackage{attachfile2}

A tiny latex file with the source attached.
#+LaTeX: \attachfile{with-the-source.org}

[-- Attachment #3: Type: text/plain, Size: 95 bytes --]


Thanks for sharing this idea!

>
>
> Cheers!
>

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

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

* Re: Including source when exporting in PDF
  2012-01-06  7:45 ` Eric Schulte
@ 2012-01-11 15:28   ` Rainer M Krug
  2012-01-12  2:06     ` Frozenlock
  0 siblings, 1 reply; 12+ messages in thread
From: Rainer M Krug @ 2012-01-11 15:28 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode, Frozenlock

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 06/01/12 08:45, Eric Schulte wrote:
> Frozenlock <frozenlock@gmail.com> writes:
> 
>> I am a strong advocate in keeping the source of everything.
>> 
>> However,  a source can easily be lost if it doesn't follow the
>> document. In LaTeX, there's a package to attach a file to a PDF
>> (like when you attach a file to an email). By doing so, the
>> source will follow the PDF even if the common reader have no clue
>> what it's for, or even how to use it.
>> 
> 
> This sounds like a great Reproducible Research practice.
> 
>> 
>> Here is how I attach my org source to every document I export to
>> PDF:
>> 
>> ;; Include the source file for every exported PDF (org-mode) 
>> (eval-after-load "org-exp" '(defadvice org-export-as-latex
>> (around org-export-add-source-pdf activate) "Add the source (org
>> file) to the resulting pdf file" (let ((filename (buffer-name))) 
>> ad-do-it ;do the function (let ((latex-buffer ad-return-value)) 
>> (set-buffer latex-buffer) (while (re-search-forward
>> "\\\\usepackage{.+}" nil t)); go to the end of packages (insert
>> "\n\\usepackage{attachfile2}"); the package needed to attach
>> files (when (re-search-forward "\\\\end{document}" nil t) 
>> (forward-line -1) (insert (concat "\\vfill\n" "\\footnotesize\n" 
>> "The source of this document is an Org-Mode file attached here:" 
>> "\n\\attachfile" "{" filename "}"))) (save-buffer)))))
>> 
>> 
>> This is by no mean a patch, but rather a quick hack. Perhaps
>> someone with a working knowledge of the org-export could find a
>> way to add a source option?
>> 
> 
> I think this practice may not actually require any changes to the 
> Org-mode core.  The attached small Org-mode file will attach itself
> to pdf exports using only features already present in Org-mode.

Following this idea - how can I easily attach all files created by
tangling? Is there a programmatic way, without having to specify them
manually?

Thanks,

Rainer


> 
> 
> 
> 
> 
> Thanks for sharing this idea!
> 
>> 
>> 
>> Cheers!
>> 
> 


- -- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      Rainer@krugs.de

Skype:      RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk8NqqwACgkQoYgNqgF2egro/wCfTlVxaVNR1/5395UC8wWrL9Ku
jhIAn3f3Lud1aFrHz1uzo7SlFH+CsmFi
=wU4r
-----END PGP SIGNATURE-----

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

* Re: Including source when exporting in PDF
  2012-01-11 15:28   ` Rainer M Krug
@ 2012-01-12  2:06     ` Frozenlock
  2012-01-12  9:11       ` Rainer M Krug
  0 siblings, 1 reply; 12+ messages in thread
From: Frozenlock @ 2012-01-12  2:06 UTC (permalink / raw)
  To: R.M.Krug; +Cc: emacs-orgmode, Eric Schulte

To include multiple files, I export all of the required files before
the PDF creation and zip them. This way, I only need to include a
single zip file.

#+BEGIN_SRC emacs-lisp :exports none
;; various exports
 (save-window-excursion
      (org-export-as-ascii org-export-headline-levels))
    (save-window-excursion
      (org-export-as-html org-export-headline-levels))

;;zip the required files
(let ((filename (file-name-sans-extension (file-name-nondirectory
(buffer-file-name)))))
      (shell-command
       (concat "zip " filename ".zip "
               (mapconcat '(lambda (arg) arg)
                (remove-if
                 '(lambda (filename)
                    (string-match "\\.$\\|\\.pdf$\\|\\.atfi$\\|#" filename))
                 (directory-files (file-name-directory (buffer-file-name))))
                " "))))
#+END_SRC

(I've added this code in a babel block to evaluate just before the PDF export.)

As you can see, I make sure I don't include a previous PDF, or any
other useless file.

If you wish to add only a single type of file, simply replace
"remove-if" by "remove-if-not" and change the value in the
string-match function. For example, "\\.$\\|\\.pdf$\\|\\.atfi$\\|#"
would become "\\.lisp$" to include all your exported lisp files.

Hope this helps!


By the way, I can't get the code block to be evaluated automatically
when I export to PDF, any clue on how to do that?



On Wed, Jan 11, 2012 at 10:28 AM, Rainer M Krug <r.m.krug@gmail.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 06/01/12 08:45, Eric Schulte wrote:
>> Frozenlock <frozenlock@gmail.com> writes:
>>
>>> I am a strong advocate in keeping the source of everything.
>>>
>>> However,  a source can easily be lost if it doesn't follow the
>>> document. In LaTeX, there's a package to attach a file to a PDF
>>> (like when you attach a file to an email). By doing so, the
>>> source will follow the PDF even if the common reader have no clue
>>> what it's for, or even how to use it.
>>>
>>
>> This sounds like a great Reproducible Research practice.
>>
>>>
>>> Here is how I attach my org source to every document I export to
>>> PDF:
>>>
>>> ;; Include the source file for every exported PDF (org-mode)
>>> (eval-after-load "org-exp" '(defadvice org-export-as-latex
>>> (around org-export-add-source-pdf activate) "Add the source (org
>>> file) to the resulting pdf file" (let ((filename (buffer-name)))
>>> ad-do-it ;do the function (let ((latex-buffer ad-return-value))
>>> (set-buffer latex-buffer) (while (re-search-forward
>>> "\\\\usepackage{.+}" nil t)); go to the end of packages (insert
>>> "\n\\usepackage{attachfile2}"); the package needed to attach
>>> files (when (re-search-forward "\\\\end{document}" nil t)
>>> (forward-line -1) (insert (concat "\\vfill\n" "\\footnotesize\n"
>>> "The source of this document is an Org-Mode file attached here:"
>>> "\n\\attachfile" "{" filename "}"))) (save-buffer)))))
>>>
>>>
>>> This is by no mean a patch, but rather a quick hack. Perhaps
>>> someone with a working knowledge of the org-export could find a
>>> way to add a source option?
>>>
>>
>> I think this practice may not actually require any changes to the
>> Org-mode core.  The attached small Org-mode file will attach itself
>> to pdf exports using only features already present in Org-mode.
>
> Following this idea - how can I easily attach all files created by
> tangling? Is there a programmatic way, without having to specify them
> manually?
>
> Thanks,
>
> Rainer
>
>
>>
>>
>>
>>
>>
>> Thanks for sharing this idea!
>>
>>>
>>>
>>> Cheers!
>>>
>>
>
>
> - --
> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
> Biology, UCT), Dipl. Phys. (Germany)
>
> Centre of Excellence for Invasion Biology
> Stellenbosch University
> South Africa
>
> Tel :       +33 - (0)9 53 10 27 44
> Cell:       +33 - (0)6 85 62 59 98
> Fax :       +33 - (0)9 58 10 27 44
>
> Fax (D):    +49 - (0)3 21 21 25 22 44
>
> email:      Rainer@krugs.de
>
> Skype:      RMkrug
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.11 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk8NqqwACgkQoYgNqgF2egro/wCfTlVxaVNR1/5395UC8wWrL9Ku
> jhIAn3f3Lud1aFrHz1uzo7SlFH+CsmFi
> =wU4r
> -----END PGP SIGNATURE-----

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

* Re: Including source when exporting in PDF
  2012-01-12  2:06     ` Frozenlock
@ 2012-01-12  9:11       ` Rainer M Krug
  2012-01-12 13:54         ` Frozenlock
  0 siblings, 1 reply; 12+ messages in thread
From: Rainer M Krug @ 2012-01-12  9:11 UTC (permalink / raw)
  To: Frozenlock; +Cc: emacs-orgmode, Eric Schulte

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 12/01/12 03:06, Frozenlock wrote:
> To include multiple files, I export all of the required files
> before the PDF creation and zip them. This way, I only need to
> include a single zip file.

Good idea.

> 
> #+BEGIN_SRC emacs-lisp :exports none ;; various exports 
> (save-window-excursion (org-export-as-ascii
> org-export-headline-levels)) (save-window-excursion 
> (org-export-as-html org-export-headline-levels))
> 
> ;;zip the required files (let ((filename (file-name-sans-extension
> (file-name-nondirectory (buffer-file-name))))) (shell-command 
> (concat "zip " filename ".zip " (mapconcat '(lambda (arg) arg) 
> (remove-if '(lambda (filename) (string-match
> "\\.$\\|\\.pdf$\\|\\.atfi$\\|#" filename)) (directory-files
> (file-name-directory (buffer-file-name)))) " ")))) #+END_SRC
> 
> (I've added this code in a babel block to evaluate just before the
> PDF export.)

I actually did not want to fiddle with the file names, as it is to
easy to forget some: this concerns in my case literate programming of
a simulation model in R, resul;ting in several files of different
extensions - it is to easy to forget one.

If I tangle, I get all the names of the tangled files, but I do not
know how I can feed them into the zip file.

> 
> As you can see, I make sure I don't include a previous PDF, or any 
> other useless file.

True.

> 
> If you wish to add only a single type of file, simply replace 
> "remove-if" by "remove-if-not" and change the value in the 
> string-match function. For example,
> "\\.$\\|\\.pdf$\\|\\.atfi$\\|#" would become "\\.lisp$" to include
> all your exported lisp files.
> 
> Hope this helps!
> 
> 
> By the way, I can't get the code block to be evaluated
> automatically when I export to PDF, any clue on how to do that?

I assume, it is caused by the :exports none - so no evaluation is done
on export. Try changing it to :exports result and then generate an
empty result, or a list of files included in the zip file.

Cheers,

Rainer


> 
> 
> 
> On Wed, Jan 11, 2012 at 10:28 AM, Rainer M Krug
> <r.m.krug@gmail.com> wrote: On 06/01/12 08:45, Eric Schulte wrote:
>>>> Frozenlock <frozenlock@gmail.com> writes:
>>>> 
>>>>> I am a strong advocate in keeping the source of
>>>>> everything.
>>>>> 
>>>>> However, Â a source can easily be lost if it doesn't follow
>>>>> the document. In LaTeX, there's a package to attach a file
>>>>> to a PDF (like when you attach a file to an email). By
>>>>> doing so, the source will follow the PDF even if the common
>>>>> reader have no clue what it's for, or even how to use it.
>>>>> 
>>>> 
>>>> This sounds like a great Reproducible Research practice.
>>>> 
>>>>> 
>>>>> Here is how I attach my org source to every document I
>>>>> export to PDF:
>>>>> 
>>>>> ;; Include the source file for every exported PDF
>>>>> (org-mode) (eval-after-load "org-exp" '(defadvice
>>>>> org-export-as-latex (around org-export-add-source-pdf
>>>>> activate) "Add the source (org file) to the resulting pdf
>>>>> file" (let ((filename (buffer-name))) ad-do-it ;do the
>>>>> function (let ((latex-buffer ad-return-value)) (set-buffer
>>>>> latex-buffer) (while (re-search-forward 
>>>>> "\\\\usepackage{.+}" nil t)); go to the end of packages
>>>>> (insert "\n\\usepackage{attachfile2}"); the package needed
>>>>> to attach files (when (re-search-forward
>>>>> "\\\\end{document}" nil t) (forward-line -1) (insert
>>>>> (concat "\\vfill\n" "\\footnotesize\n" "The source of this
>>>>> document is an Org-Mode file attached here:" 
>>>>> "\n\\attachfile" "{" filename "}"))) (save-buffer)))))
>>>>> 
>>>>> 
>>>>> This is by no mean a patch, but rather a quick hack.
>>>>> Perhaps someone with a working knowledge of the org-export
>>>>> could find a way to add a source option?
>>>>> 
>>>> 
>>>> I think this practice may not actually require any changes to
>>>> the Org-mode core. Â The attached small Org-mode file will
>>>> attach itself to pdf exports using only features already
>>>> present in Org-mode.
> 
> Following this idea - how can I easily attach all files created by 
> tangling? Is there a programmatic way, without having to specify
> them manually?
> 
> Thanks,
> 
> Rainer
> 
> 
>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>>>> Thanks for sharing this idea!
>>>> 
>>>>> 
>>>>> 
>>>>> Cheers!
>>>>> 
>>>> 
> 
> 

- -- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      Rainer@krugs.de

Skype:      RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEUEARECAAYFAk8Oo7UACgkQoYgNqgF2egpg9wCfTq04zAVki+Oh1g97/C3FERf3
Ej0Al30dF8xQdyHNOmOK8y7ZolA0dzE=
=IUuN
-----END PGP SIGNATURE-----

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

* Re: Including source when exporting in PDF
  2012-01-12  9:11       ` Rainer M Krug
@ 2012-01-12 13:54         ` Frozenlock
  2012-01-12 13:59           ` Rainer M Krug
  0 siblings, 1 reply; 12+ messages in thread
From: Frozenlock @ 2012-01-12 13:54 UTC (permalink / raw)
  To: R.M.Krug; +Cc: emacs-orgmode, Eric Schulte

The code block I previously sent only require you to specify which
_extension_ you want or don't want. No need to include any specific
filename (other than the .zip file in the latex "include" command).

Am I to understand you want something to include *all and only* tangled files?

--

I tried ":exports result" with no success. I'll try to send a minimum
working example shortly.

On Thu, Jan 12, 2012 at 4:11 AM, Rainer M Krug <r.m.krug@gmail.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 12/01/12 03:06, Frozenlock wrote:
>> To include multiple files, I export all of the required files
>> before the PDF creation and zip them. This way, I only need to
>> include a single zip file.
>
> Good idea.
>
>>
>> #+BEGIN_SRC emacs-lisp :exports none ;; various exports
>> (save-window-excursion (org-export-as-ascii
>> org-export-headline-levels)) (save-window-excursion
>> (org-export-as-html org-export-headline-levels))
>>
>> ;;zip the required files (let ((filename (file-name-sans-extension
>> (file-name-nondirectory (buffer-file-name))))) (shell-command
>> (concat "zip " filename ".zip " (mapconcat '(lambda (arg) arg)
>> (remove-if '(lambda (filename) (string-match
>> "\\.$\\|\\.pdf$\\|\\.atfi$\\|#" filename)) (directory-files
>> (file-name-directory (buffer-file-name)))) " ")))) #+END_SRC
>>
>> (I've added this code in a babel block to evaluate just before the
>> PDF export.)
>
> I actually did not want to fiddle with the file names, as it is to
> easy to forget some: this concerns in my case literate programming of
> a simulation model in R, resul;ting in several files of different
> extensions - it is to easy to forget one.
>
> If I tangle, I get all the names of the tangled files, but I do not
> know how I can feed them into the zip file.
>
>>
>> As you can see, I make sure I don't include a previous PDF, or any
>> other useless file.
>
> True.
>
>>
>> If you wish to add only a single type of file, simply replace
>> "remove-if" by "remove-if-not" and change the value in the
>> string-match function. For example,
>> "\\.$\\|\\.pdf$\\|\\.atfi$\\|#" would become "\\.lisp$" to include
>> all your exported lisp files.
>>
>> Hope this helps!
>>
>>
>> By the way, I can't get the code block to be evaluated
>> automatically when I export to PDF, any clue on how to do that?
>
> I assume, it is caused by the :exports none - so no evaluation is done
> on export. Try changing it to :exports result and then generate an
> empty result, or a list of files included in the zip file.
>
> Cheers,
>
> Rainer
>
>
>>
>>
>>
>> On Wed, Jan 11, 2012 at 10:28 AM, Rainer M Krug
>> <r.m.krug@gmail.com> wrote: On 06/01/12 08:45, Eric Schulte wrote:
>>>>> Frozenlock <frozenlock@gmail.com> writes:
>>>>>
>>>>>> I am a strong advocate in keeping the source of
>>>>>> everything.
>>>>>>
>>>>>> However, Â a source can easily be lost if it doesn't follow
>>>>>> the document. In LaTeX, there's a package to attach a file
>>>>>> to a PDF (like when you attach a file to an email). By
>>>>>> doing so, the source will follow the PDF even if the common
>>>>>> reader have no clue what it's for, or even how to use it.
>>>>>>
>>>>>
>>>>> This sounds like a great Reproducible Research practice.
>>>>>
>>>>>>
>>>>>> Here is how I attach my org source to every document I
>>>>>> export to PDF:
>>>>>>
>>>>>> ;; Include the source file for every exported PDF
>>>>>> (org-mode) (eval-after-load "org-exp" '(defadvice
>>>>>> org-export-as-latex (around org-export-add-source-pdf
>>>>>> activate) "Add the source (org file) to the resulting pdf
>>>>>> file" (let ((filename (buffer-name))) ad-do-it ;do the
>>>>>> function (let ((latex-buffer ad-return-value)) (set-buffer
>>>>>> latex-buffer) (while (re-search-forward
>>>>>> "\\\\usepackage{.+}" nil t)); go to the end of packages
>>>>>> (insert "\n\\usepackage{attachfile2}"); the package needed
>>>>>> to attach files (when (re-search-forward
>>>>>> "\\\\end{document}" nil t) (forward-line -1) (insert
>>>>>> (concat "\\vfill\n" "\\footnotesize\n" "The source of this
>>>>>> document is an Org-Mode file attached here:"
>>>>>> "\n\\attachfile" "{" filename "}"))) (save-buffer)))))
>>>>>>
>>>>>>
>>>>>> This is by no mean a patch, but rather a quick hack.
>>>>>> Perhaps someone with a working knowledge of the org-export
>>>>>> could find a way to add a source option?
>>>>>>
>>>>>
>>>>> I think this practice may not actually require any changes to
>>>>> the Org-mode core. Â The attached small Org-mode file will
>>>>> attach itself to pdf exports using only features already
>>>>> present in Org-mode.
>>
>> Following this idea - how can I easily attach all files created by
>> tangling? Is there a programmatic way, without having to specify
>> them manually?
>>
>> Thanks,
>>
>> Rainer
>>
>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Thanks for sharing this idea!
>>>>>
>>>>>>
>>>>>>
>>>>>> Cheers!
>>>>>>
>>>>>
>>
>>
>
> - --
> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
> Biology, UCT), Dipl. Phys. (Germany)
>
> Centre of Excellence for Invasion Biology
> Stellenbosch University
> South Africa
>
> Tel :       +33 - (0)9 53 10 27 44
> Cell:       +33 - (0)6 85 62 59 98
> Fax :       +33 - (0)9 58 10 27 44
>
> Fax (D):    +49 - (0)3 21 21 25 22 44
>
> email:      Rainer@krugs.de
>
> Skype:      RMkrug
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.11 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEUEARECAAYFAk8Oo7UACgkQoYgNqgF2egpg9wCfTq04zAVki+Oh1g97/C3FERf3
> Ej0Al30dF8xQdyHNOmOK8y7ZolA0dzE=
> =IUuN
> -----END PGP SIGNATURE-----

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

* Re: Including source when exporting in PDF
  2012-01-12 13:54         ` Frozenlock
@ 2012-01-12 13:59           ` Rainer M Krug
  2012-01-15  5:29             ` Frozenlock
  0 siblings, 1 reply; 12+ messages in thread
From: Rainer M Krug @ 2012-01-12 13:59 UTC (permalink / raw)
  To: Frozenlock; +Cc: emacs-orgmode, Eric Schulte

On 12 January 2012 14:54, Frozenlock <frozenlock@gmail.com> wrote:
> The code block I previously sent only require you to specify which
> _extension_ you want or don't want. No need to include any specific
> filename (other than the .zip file in the latex "include" command).
>
> Am I to understand you want something to include *all and only* tangled files?

Yes - and the files do have different extensions (e.g. .R, .sh, .sub,
none) and are not tangled necessarily in a specific directory.

and the original org file, but that is not a problem.

Rainer

>
> --
>
> I tried ":exports result" with no success. I'll try to send a minimum
> working example shortly.
>
> On Thu, Jan 12, 2012 at 4:11 AM, Rainer M Krug <r.m.krug@gmail.com> wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> On 12/01/12 03:06, Frozenlock wrote:
>>> To include multiple files, I export all of the required files
>>> before the PDF creation and zip them. This way, I only need to
>>> include a single zip file.
>>
>> Good idea.
>>
>>>
>>> #+BEGIN_SRC emacs-lisp :exports none ;; various exports
>>> (save-window-excursion (org-export-as-ascii
>>> org-export-headline-levels)) (save-window-excursion
>>> (org-export-as-html org-export-headline-levels))
>>>
>>> ;;zip the required files (let ((filename (file-name-sans-extension
>>> (file-name-nondirectory (buffer-file-name))))) (shell-command
>>> (concat "zip " filename ".zip " (mapconcat '(lambda (arg) arg)
>>> (remove-if '(lambda (filename) (string-match
>>> "\\.$\\|\\.pdf$\\|\\.atfi$\\|#" filename)) (directory-files
>>> (file-name-directory (buffer-file-name)))) " ")))) #+END_SRC
>>>
>>> (I've added this code in a babel block to evaluate just before the
>>> PDF export.)
>>
>> I actually did not want to fiddle with the file names, as it is to
>> easy to forget some: this concerns in my case literate programming of
>> a simulation model in R, resul;ting in several files of different
>> extensions - it is to easy to forget one.
>>
>> If I tangle, I get all the names of the tangled files, but I do not
>> know how I can feed them into the zip file.
>>
>>>
>>> As you can see, I make sure I don't include a previous PDF, or any
>>> other useless file.
>>
>> True.
>>
>>>
>>> If you wish to add only a single type of file, simply replace
>>> "remove-if" by "remove-if-not" and change the value in the
>>> string-match function. For example,
>>> "\\.$\\|\\.pdf$\\|\\.atfi$\\|#" would become "\\.lisp$" to include
>>> all your exported lisp files.
>>>
>>> Hope this helps!
>>>
>>>
>>> By the way, I can't get the code block to be evaluated
>>> automatically when I export to PDF, any clue on how to do that?
>>
>> I assume, it is caused by the :exports none - so no evaluation is done
>> on export. Try changing it to :exports result and then generate an
>> empty result, or a list of files included in the zip file.
>>
>> Cheers,
>>
>> Rainer
>>
>>
>>>
>>>
>>>
>>> On Wed, Jan 11, 2012 at 10:28 AM, Rainer M Krug
>>> <r.m.krug@gmail.com> wrote: On 06/01/12 08:45, Eric Schulte wrote:
>>>>>> Frozenlock <frozenlock@gmail.com> writes:
>>>>>>
>>>>>>> I am a strong advocate in keeping the source of
>>>>>>> everything.
>>>>>>>
>>>>>>> However, Â a source can easily be lost if it doesn't follow
>>>>>>> the document. In LaTeX, there's a package to attach a file
>>>>>>> to a PDF (like when you attach a file to an email). By
>>>>>>> doing so, the source will follow the PDF even if the common
>>>>>>> reader have no clue what it's for, or even how to use it.
>>>>>>>
>>>>>>
>>>>>> This sounds like a great Reproducible Research practice.
>>>>>>
>>>>>>>
>>>>>>> Here is how I attach my org source to every document I
>>>>>>> export to PDF:
>>>>>>>
>>>>>>> ;; Include the source file for every exported PDF
>>>>>>> (org-mode) (eval-after-load "org-exp" '(defadvice
>>>>>>> org-export-as-latex (around org-export-add-source-pdf
>>>>>>> activate) "Add the source (org file) to the resulting pdf
>>>>>>> file" (let ((filename (buffer-name))) ad-do-it ;do the
>>>>>>> function (let ((latex-buffer ad-return-value)) (set-buffer
>>>>>>> latex-buffer) (while (re-search-forward
>>>>>>> "\\\\usepackage{.+}" nil t)); go to the end of packages
>>>>>>> (insert "\n\\usepackage{attachfile2}"); the package needed
>>>>>>> to attach files (when (re-search-forward
>>>>>>> "\\\\end{document}" nil t) (forward-line -1) (insert
>>>>>>> (concat "\\vfill\n" "\\footnotesize\n" "The source of this
>>>>>>> document is an Org-Mode file attached here:"
>>>>>>> "\n\\attachfile" "{" filename "}"))) (save-buffer)))))
>>>>>>>
>>>>>>>
>>>>>>> This is by no mean a patch, but rather a quick hack.
>>>>>>> Perhaps someone with a working knowledge of the org-export
>>>>>>> could find a way to add a source option?
>>>>>>>
>>>>>>
>>>>>> I think this practice may not actually require any changes to
>>>>>> the Org-mode core. Â The attached small Org-mode file will
>>>>>> attach itself to pdf exports using only features already
>>>>>> present in Org-mode.
>>>
>>> Following this idea - how can I easily attach all files created by
>>> tangling? Is there a programmatic way, without having to specify
>>> them manually?
>>>
>>> Thanks,
>>>
>>> Rainer
>>>
>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> Thanks for sharing this idea!
>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Cheers!
>>>>>>>
>>>>>>
>>>
>>>
>>
>> - --
>> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
>> Biology, UCT), Dipl. Phys. (Germany)
>>
>> Centre of Excellence for Invasion Biology
>> Stellenbosch University
>> South Africa
>>
>> Tel :       +33 - (0)9 53 10 27 44
>> Cell:       +33 - (0)6 85 62 59 98
>> Fax :       +33 - (0)9 58 10 27 44
>>
>> Fax (D):    +49 - (0)3 21 21 25 22 44
>>
>> email:      Rainer@krugs.de
>>
>> Skype:      RMkrug
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG v1.4.11 (GNU/Linux)
>> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>>
>> iEUEARECAAYFAk8Oo7UACgkQoYgNqgF2egpg9wCfTq04zAVki+Oh1g97/C3FERf3
>> Ej0Al30dF8xQdyHNOmOK8y7ZolA0dzE=
>> =IUuN
>> -----END PGP SIGNATURE-----



-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax (F):       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      Rainer@krugs.de

Skype:      RMkrug

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

* Re: Including source when exporting in PDF
  2012-01-12 13:59           ` Rainer M Krug
@ 2012-01-15  5:29             ` Frozenlock
  2012-01-16 11:21               ` [BUG?][babel] " Rainer M Krug
  0 siblings, 1 reply; 12+ messages in thread
From: Frozenlock @ 2012-01-15  5:29 UTC (permalink / raw)
  To: Rainer M Krug; +Cc: emacs-orgmode, Eric Schulte

This babel block should do the following:

- When exporting, automatically tangle the babel blocks.
- Then take the resulting files and add them to a zip file, along with
the original .org file.
- Add the necessary \usepackage and latex commands to insert the zipfile.

Let me know if something isn't like you want.

Here is the babel block to add to your source (org) file:

========================================
#+BEGIN_SRC emacs-lisp :results org :exports results :var
buffer-file-name=(buffer-file-name)
(let ((filename (file-name-nondirectory (file-name-sans-extension
buffer-file-name))))
    (shell-command
     (concat "zip -j " filename  ".zip " filename".org "
             (mapconcat '(lambda (arg)
                           (convert-standard-filename
                            (expand-file-name arg)))
                        (org-babel-tangle)
                        " ")))
    (concat "#+LATEX_HEADER:\\usepackage{attachfile2}\n"
            "#+LATEX: \\vfill \\textattachfile[print=false,color=0.5
0.5 0.5]{"filename".zip}{Source (.org) \\& other files...}\n"))
#+END_SRC
==============================


On a related note, I've added some improvements to my own way to
export in multiple format and add the files along with the source. The
latex commands and usepackage are included, so no need to add them
elswhere in the org file:

==============================
# Make sure this babel block is the last one in the buffer;
# block after this one won't be evaluated before the txt and html export.
#+BEGIN_SRC emacs-lisp :results org :exports results :var
buffer-file-name=(buffer-file-name)
(let ((org-export-babel-evaluate nil)); don't evaluate in 'recursive' exports
  (save-window-excursion ;; avoid leakage when more than one org export in block
    (org-export-as-ascii org-export-headline-levels))
  (save-window-excursion (org-export-as-html org-export-headline-levels))
  (let ((filename (file-name-nondirectory (file-name-sans-extension
buffer-file-name)))
	(to-include-files (directory-files (file-name-directory buffer-file-name))))
    (shell-command
     (concat "zip -j " filename  ".zip "
	     (mapconcat '(lambda (arg) arg)
			(remove-if
			 '(lambda (file)
			    (string-match "\\.$\\|\\.pdf$\\|\\.atfi$\\|\\.tex$\\|#" file))
			 ;; don't include useless files
			 to-include-files)
			" ")))
    (concat "#+LATEX_HEADER:\\usepackage{attachfile2}\n"
	    "#+LATEX: \\vfill \\textattachfile[print=false,color=0.5 0.5
0.5]{"filename".zip}{Source (.org) & html, txt...}\n")))
#+END_SRC
==============================


Enjoy!



On Thu, Jan 12, 2012 at 8:59 AM, Rainer M Krug <r.m.krug@gmail.com> wrote:
> On 12 January 2012 14:54, Frozenlock <frozenlock@gmail.com> wrote:
>> The code block I previously sent only require you to specify which
>> _extension_ you want or don't want. No need to include any specific
>> filename (other than the .zip file in the latex "include" command).
>>
>> Am I to understand you want something to include *all and only* tangled files?
>
> Yes - and the files do have different extensions (e.g. .R, .sh, .sub,
> none) and are not tangled necessarily in a specific directory.
>
> and the original org file, but that is not a problem.
>
> Rainer
>
>>
>> --
>>
>> I tried ":exports result" with no success. I'll try to send a minimum
>> working example shortly.
>>
>> On Thu, Jan 12, 2012 at 4:11 AM, Rainer M Krug <r.m.krug@gmail.com> wrote:
>>> -----BEGIN PGP SIGNED MESSAGE-----
>>> Hash: SHA1
>>>
>>> On 12/01/12 03:06, Frozenlock wrote:
>>>> To include multiple files, I export all of the required files
>>>> before the PDF creation and zip them. This way, I only need to
>>>> include a single zip file.
>>>
>>> Good idea.
>>>
>>>>
>>>> #+BEGIN_SRC emacs-lisp :exports none ;; various exports
>>>> (save-window-excursion (org-export-as-ascii
>>>> org-export-headline-levels)) (save-window-excursion
>>>> (org-export-as-html org-export-headline-levels))
>>>>
>>>> ;;zip the required files (let ((filename (file-name-sans-extension
>>>> (file-name-nondirectory (buffer-file-name))))) (shell-command
>>>> (concat "zip " filename ".zip " (mapconcat '(lambda (arg) arg)
>>>> (remove-if '(lambda (filename) (string-match
>>>> "\\.$\\|\\.pdf$\\|\\.atfi$\\|#" filename)) (directory-files
>>>> (file-name-directory (buffer-file-name)))) " ")))) #+END_SRC
>>>>
>>>> (I've added this code in a babel block to evaluate just before the
>>>> PDF export.)
>>>
>>> I actually did not want to fiddle with the file names, as it is to
>>> easy to forget some: this concerns in my case literate programming of
>>> a simulation model in R, resul;ting in several files of different
>>> extensions - it is to easy to forget one.
>>>
>>> If I tangle, I get all the names of the tangled files, but I do not
>>> know how I can feed them into the zip file.
>>>
>>>>
>>>> As you can see, I make sure I don't include a previous PDF, or any
>>>> other useless file.
>>>
>>> True.
>>>
>>>>
>>>> If you wish to add only a single type of file, simply replace
>>>> "remove-if" by "remove-if-not" and change the value in the
>>>> string-match function. For example,
>>>> "\\.$\\|\\.pdf$\\|\\.atfi$\\|#" would become "\\.lisp$" to include
>>>> all your exported lisp files.
>>>>
>>>> Hope this helps!
>>>>
>>>>
>>>> By the way, I can't get the code block to be evaluated
>>>> automatically when I export to PDF, any clue on how to do that?
>>>
>>> I assume, it is caused by the :exports none - so no evaluation is done
>>> on export. Try changing it to :exports result and then generate an
>>> empty result, or a list of files included in the zip file.
>>>
>>> Cheers,
>>>
>>> Rainer
>>>
>>>
>>>>
>>>>
>>>>
>>>> On Wed, Jan 11, 2012 at 10:28 AM, Rainer M Krug
>>>> <r.m.krug@gmail.com> wrote: On 06/01/12 08:45, Eric Schulte wrote:
>>>>>>> Frozenlock <frozenlock@gmail.com> writes:
>>>>>>>
>>>>>>>> I am a strong advocate in keeping the source of
>>>>>>>> everything.
>>>>>>>>
>>>>>>>> However, Â a source can easily be lost if it doesn't follow
>>>>>>>> the document. In LaTeX, there's a package to attach a file
>>>>>>>> to a PDF (like when you attach a file to an email). By
>>>>>>>> doing so, the source will follow the PDF even if the common
>>>>>>>> reader have no clue what it's for, or even how to use it.
>>>>>>>>
>>>>>>>
>>>>>>> This sounds like a great Reproducible Research practice.
>>>>>>>
>>>>>>>>
>>>>>>>> Here is how I attach my org source to every document I
>>>>>>>> export to PDF:
>>>>>>>>
>>>>>>>> ;; Include the source file for every exported PDF
>>>>>>>> (org-mode) (eval-after-load "org-exp" '(defadvice
>>>>>>>> org-export-as-latex (around org-export-add-source-pdf
>>>>>>>> activate) "Add the source (org file) to the resulting pdf
>>>>>>>> file" (let ((filename (buffer-name))) ad-do-it ;do the
>>>>>>>> function (let ((latex-buffer ad-return-value)) (set-buffer
>>>>>>>> latex-buffer) (while (re-search-forward
>>>>>>>> "\\\\usepackage{.+}" nil t)); go to the end of packages
>>>>>>>> (insert "\n\\usepackage{attachfile2}"); the package needed
>>>>>>>> to attach files (when (re-search-forward
>>>>>>>> "\\\\end{document}" nil t) (forward-line -1) (insert
>>>>>>>> (concat "\\vfill\n" "\\footnotesize\n" "The source of this
>>>>>>>> document is an Org-Mode file attached here:"
>>>>>>>> "\n\\attachfile" "{" filename "}"))) (save-buffer)))))
>>>>>>>>
>>>>>>>>
>>>>>>>> This is by no mean a patch, but rather a quick hack.
>>>>>>>> Perhaps someone with a working knowledge of the org-export
>>>>>>>> could find a way to add a source option?
>>>>>>>>
>>>>>>>
>>>>>>> I think this practice may not actually require any changes to
>>>>>>> the Org-mode core. Â The attached small Org-mode file will
>>>>>>> attach itself to pdf exports using only features already
>>>>>>> present in Org-mode.
>>>>
>>>> Following this idea - how can I easily attach all files created by
>>>> tangling? Is there a programmatic way, without having to specify
>>>> them manually?
>>>>
>>>> Thanks,
>>>>
>>>> Rainer
>>>>
>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Thanks for sharing this idea!
>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Cheers!
>>>>>>>>
>>>>>>>
>>>>
>>>>
>>>
>>> - --
>>> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
>>> Biology, UCT), Dipl. Phys. (Germany)
>>>
>>> Centre of Excellence for Invasion Biology
>>> Stellenbosch University
>>> South Africa
>>>
>>> Tel :       +33 - (0)9 53 10 27 44
>>> Cell:       +33 - (0)6 85 62 59 98
>>> Fax :       +33 - (0)9 58 10 27 44
>>>
>>> Fax (D):    +49 - (0)3 21 21 25 22 44
>>>
>>> email:      Rainer@krugs.de
>>>
>>> Skype:      RMkrug
>>> -----BEGIN PGP SIGNATURE-----
>>> Version: GnuPG v1.4.11 (GNU/Linux)
>>> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>>>
>>> iEUEARECAAYFAk8Oo7UACgkQoYgNqgF2egpg9wCfTq04zAVki+Oh1g97/C3FERf3
>>> Ej0Al30dF8xQdyHNOmOK8y7ZolA0dzE=
>>> =IUuN
>>> -----END PGP SIGNATURE-----
>
>
>
> --
> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
> Biology, UCT), Dipl. Phys. (Germany)
>
> Centre of Excellence for Invasion Biology
> Stellenbosch University
> South Africa
>
> Tel :       +33 - (0)9 53 10 27 44
> Cell:       +33 - (0)6 85 62 59 98
> Fax (F):       +33 - (0)9 58 10 27 44
>
> Fax (D):    +49 - (0)3 21 21 25 22 44
>
> email:      Rainer@krugs.de
>
> Skype:      RMkrug

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

* [BUG?][babel] Re:   Including source when exporting in PDF
  2012-01-15  5:29             ` Frozenlock
@ 2012-01-16 11:21               ` Rainer M Krug
  2012-01-18  0:57                 ` Frozenlock
  0 siblings, 1 reply; 12+ messages in thread
From: Rainer M Krug @ 2012-01-16 11:21 UTC (permalink / raw)
  To: Frozenlock; +Cc: emacs-orgmode, Eric Schulte

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 15/01/12 06:29, Frozenlock wrote:
> This babel block should do the following:
> 
> - When exporting, automatically tangle the babel blocks. - Then
> take the resulting files and add them to a zip file, along with the
> original .org file. - Add the necessary \usepackage and latex
> commands to insert the zipfile.
> 
> Let me know if something isn't like you want.
> 
> Here is the babel block to add to your source (org) file:
> 
> ======================================== #+BEGIN_SRC emacs-lisp
> :results org :exports results :var 
> buffer-file-name=(buffer-file-name) (let ((filename
> (file-name-nondirectory (file-name-sans-extension 
> buffer-file-name)))) (shell-command (concat "zip -j " filename
> ".zip " filename".org " (mapconcat '(lambda (arg) 
> (convert-standard-filename (expand-file-name arg))) 
> (org-babel-tangle) " "))) (concat
> "#+LATEX_HEADER:\\usepackage{attachfile2}\n" "#+LATEX: \\vfill
> \\textattachfile[print=false,color=0.5 0.5
> 0.5]{"filename".zip}{Source (.org) \\& other files...}\n")) 
> #+END_SRC ==============================

Thanks for this code - it looks good, but there is a serious problem:

src_emacs_lisp{} expressions are evaluated and replaced with the
result in the org file, which does not happen when tangling from the
buffer itself.
Example:

################################################
* name src_emacs-lisp{(buffer-file-name)}
#+BEGIN_SRC emacs-lisp :results org :exports results :var
buffer-file-name=(buffer-file-name)
  (org-babel-tangle)
#+END_SRC
################################################

If I export the file above, the file get changed to:

################################################
* name

#+BEGIN_SRC emacs-lisp :results org :exports results :var
buffer-file-name=(buffer-file-name)
  (org-babel-tangle)
#+END_SRC
################################################

Is there something wrong with the code?

Rainer


> 
> 
> On a related note, I've added some improvements to my own way to 
> export in multiple format and add the files along with the source.
> The latex commands and usepackage are included, so no need to add
> them elswhere in the org file:
> 
> ============================== # Make sure this babel block is the
> last one in the buffer; # block after this one won't be evaluated
> before the txt and html export. #+BEGIN_SRC emacs-lisp :results org
> :exports results :var buffer-file-name=(buffer-file-name) (let
> ((org-export-babel-evaluate nil)); don't evaluate in 'recursive'
> exports (save-window-excursion ;; avoid leakage when more than one
> org export in block (org-export-as-ascii
> org-export-headline-levels)) (save-window-excursion
> (org-export-as-html org-export-headline-levels)) (let ((filename
> (file-name-nondirectory (file-name-sans-extension 
> buffer-file-name))) (to-include-files (directory-files
> (file-name-directory buffer-file-name)))) (shell-command (concat
> "zip -j " filename  ".zip " (mapconcat '(lambda (arg) arg) 
> (remove-if '(lambda (file) (string-match
> "\\.$\\|\\.pdf$\\|\\.atfi$\\|\\.tex$\\|#" file)) ;; don't include
> useless files to-include-files) " "))) (concat
> "#+LATEX_HEADER:\\usepackage{attachfile2}\n" "#+LATEX: \\vfill
> \\textattachfile[print=false,color=0.5 0.5 
> 0.5]{"filename".zip}{Source (.org) & html, txt...}\n"))) #+END_SRC 
> ==============================
> 
> 
> Enjoy!
> 
> 
> 
> On Thu, Jan 12, 2012 at 8:59 AM, Rainer M Krug <r.m.krug@gmail.com>
> wrote:
>> On 12 January 2012 14:54, Frozenlock <frozenlock@gmail.com>
>> wrote:
>>> The code block I previously sent only require you to specify
>>> which _extension_ you want or don't want. No need to include
>>> any specific filename (other than the .zip file in the latex
>>> "include" command).
>>> 
>>> Am I to understand you want something to include *all and only*
>>> tangled files?
>> 
>> Yes - and the files do have different extensions (e.g. .R, .sh,
>> .sub, none) and are not tangled necessarily in a specific
>> directory.
>> 
>> and the original org file, but that is not a problem.
>> 
>> Rainer
>> 
>>> 
>>> --
>>> 
>>> I tried ":exports result" with no success. I'll try to send a
>>> minimum working example shortly.
>>> 
>>> On Thu, Jan 12, 2012 at 4:11 AM, Rainer M Krug
>>> <r.m.krug@gmail.com> wrote:
> On 12/01/12 03:06, Frozenlock wrote:
>>>>>> To include multiple files, I export all of the required
>>>>>> files before the PDF creation and zip them. This way, I
>>>>>> only need to include a single zip file.
> 
> Good idea.
> 
>>>>>> 
>>>>>> #+BEGIN_SRC emacs-lisp :exports none ;; various exports 
>>>>>> (save-window-excursion (org-export-as-ascii 
>>>>>> org-export-headline-levels)) (save-window-excursion 
>>>>>> (org-export-as-html org-export-headline-levels))
>>>>>> 
>>>>>> ;;zip the required files (let ((filename
>>>>>> (file-name-sans-extension (file-name-nondirectory
>>>>>> (buffer-file-name))))) (shell-command (concat "zip "
>>>>>> filename ".zip " (mapconcat '(lambda (arg) arg) 
>>>>>> (remove-if '(lambda (filename) (string-match 
>>>>>> "\\.$\\|\\.pdf$\\|\\.atfi$\\|#" filename))
>>>>>> (directory-files (file-name-directory
>>>>>> (buffer-file-name)))) " ")))) #+END_SRC
>>>>>> 
>>>>>> (I've added this code in a babel block to evaluate just
>>>>>> before the PDF export.)
> 
> I actually did not want to fiddle with the file names, as it is to 
> easy to forget some: this concerns in my case literate programming
> of a simulation model in R, resul;ting in several files of
> different extensions - it is to easy to forget one.
> 
> If I tangle, I get all the names of the tangled files, but I do
> not know how I can feed them into the zip file.
> 
>>>>>> 
>>>>>> As you can see, I make sure I don't include a previous
>>>>>> PDF, or any other useless file.
> 
> True.
> 
>>>>>> 
>>>>>> If you wish to add only a single type of file, simply
>>>>>> replace "remove-if" by "remove-if-not" and change the
>>>>>> value in the string-match function. For example, 
>>>>>> "\\.$\\|\\.pdf$\\|\\.atfi$\\|#" would become "\\.lisp$"
>>>>>> to include all your exported lisp files.
>>>>>> 
>>>>>> Hope this helps!
>>>>>> 
>>>>>> 
>>>>>> By the way, I can't get the code block to be evaluated 
>>>>>> automatically when I export to PDF, any clue on how to do
>>>>>> that?
> 
> I assume, it is caused by the :exports none - so no evaluation is
> done on export. Try changing it to :exports result and then
> generate an empty result, or a list of files included in the zip
> file.
> 
> Cheers,
> 
> Rainer
> 
> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> On Wed, Jan 11, 2012 at 10:28 AM, Rainer M Krug 
>>>>>> <r.m.krug@gmail.com> wrote: On 06/01/12 08:45, Eric
>>>>>> Schulte wrote:
>>>>>>>>> Frozenlock <frozenlock@gmail.com> writes:
>>>>>>>>> 
>>>>>>>>>> I am a strong advocate in keeping the source of 
>>>>>>>>>> everything.
>>>>>>>>>> 
>>>>>>>>>> However, Â a source can easily be lost if it
>>>>>>>>>> doesn't follow the document. In LaTeX, there's a
>>>>>>>>>> package to attach a file to a PDF (like when you
>>>>>>>>>> attach a file to an email). By doing so, the
>>>>>>>>>> source will follow the PDF even if the common 
>>>>>>>>>> reader have no clue what it's for, or even how to
>>>>>>>>>> use it.
>>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> This sounds like a great Reproducible Research
>>>>>>>>> practice.
>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> Here is how I attach my org source to every
>>>>>>>>>> document I export to PDF:
>>>>>>>>>> 
>>>>>>>>>> ;; Include the source file for every exported
>>>>>>>>>> PDF (org-mode) (eval-after-load "org-exp"
>>>>>>>>>> '(defadvice org-export-as-latex (around
>>>>>>>>>> org-export-add-source-pdf activate) "Add the
>>>>>>>>>> source (org file) to the resulting pdf file" (let
>>>>>>>>>> ((filename (buffer-name))) ad-do-it ;do the 
>>>>>>>>>> function (let ((latex-buffer ad-return-value))
>>>>>>>>>> (set-buffer latex-buffer) (while
>>>>>>>>>> (re-search-forward "\\\\usepackage{.+}" nil t));
>>>>>>>>>> go to the end of packages (insert
>>>>>>>>>> "\n\\usepackage{attachfile2}"); the package
>>>>>>>>>> needed to attach files (when (re-search-forward 
>>>>>>>>>> "\\\\end{document}" nil t) (forward-line -1)
>>>>>>>>>> (insert (concat "\\vfill\n" "\\footnotesize\n"
>>>>>>>>>> "The source of this document is an Org-Mode file
>>>>>>>>>> attached here:" "\n\\attachfile" "{" filename
>>>>>>>>>> "}"))) (save-buffer)))))
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> This is by no mean a patch, but rather a quick
>>>>>>>>>> hack. Perhaps someone with a working knowledge of
>>>>>>>>>> the org-export could find a way to add a source
>>>>>>>>>> option?
>>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> I think this practice may not actually require any
>>>>>>>>> changes to the Org-mode core. Â The attached small
>>>>>>>>> Org-mode file will attach itself to pdf exports
>>>>>>>>> using only features already present in Org-mode.
>>>>>> 
>>>>>> Following this idea - how can I easily attach all files
>>>>>> created by tangling? Is there a programmatic way, without
>>>>>> having to specify them manually?
>>>>>> 
>>>>>> Thanks,
>>>>>> 
>>>>>> Rainer
>>>>>> 
>>>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> Thanks for sharing this idea!
>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> Cheers!
>>>>>>>>>> 
>>>>>>>>> 
>>>>>> 
>>>>>> 
> 
>> 
>> 
>> 
>> -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc
>> (Conservation Biology, UCT), Dipl. Phys. (Germany)
>> 
>> Centre of Excellence for Invasion Biology Stellenbosch
>> University South Africa
>> 
>> Tel :       +33 - (0)9 53 10 27 44 Cell:       +33 - (0)6 85 62
>> 59 98 Fax (F):       +33 - (0)9 58 10 27 44
>> 
>> Fax (D):    +49 - (0)3 21 21 25 22 44
>> 
>> email:      Rainer@krugs.de
>> 
>> Skype:      RMkrug

- -- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      Rainer@krugs.de

Skype:      RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk8UCCEACgkQoYgNqgF2egrQjQCggcFy4UASWK2ilhtaC3jndqf0
LEYAn2jZ5yWj9H7jTi51r64ZxuspsYUh
=QKfm
-----END PGP SIGNATURE-----

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

* Re: [BUG?][babel] Re:  Including source when exporting in PDF
  2012-01-16 11:21               ` [BUG?][babel] " Rainer M Krug
@ 2012-01-18  0:57                 ` Frozenlock
  2012-01-18  9:03                   ` Rainer M Krug
  0 siblings, 1 reply; 12+ messages in thread
From: Frozenlock @ 2012-01-18  0:57 UTC (permalink / raw)
  To: R.M.Krug; +Cc: emacs-orgmode, Eric Schulte

I'm sorry, but I don't quite understand...

Would it be possible to send a minimum working example of your org file?



On Mon, Jan 16, 2012 at 6:21 AM, Rainer M Krug <r.m.krug@gmail.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 15/01/12 06:29, Frozenlock wrote:
>> This babel block should do the following:
>>
>> - When exporting, automatically tangle the babel blocks. - Then
>> take the resulting files and add them to a zip file, along with the
>> original .org file. - Add the necessary \usepackage and latex
>> commands to insert the zipfile.
>>
>> Let me know if something isn't like you want.
>>
>> Here is the babel block to add to your source (org) file:
>>
>> ======================================== #+BEGIN_SRC emacs-lisp
>> :results org :exports results :var
>> buffer-file-name=(buffer-file-name) (let ((filename
>> (file-name-nondirectory (file-name-sans-extension
>> buffer-file-name)))) (shell-command (concat "zip -j " filename
>> ".zip " filename".org " (mapconcat '(lambda (arg)
>> (convert-standard-filename (expand-file-name arg)))
>> (org-babel-tangle) " "))) (concat
>> "#+LATEX_HEADER:\\usepackage{attachfile2}\n" "#+LATEX: \\vfill
>> \\textattachfile[print=false,color=0.5 0.5
>> 0.5]{"filename".zip}{Source (.org) \\& other files...}\n"))
>> #+END_SRC ==============================
>
> Thanks for this code - it looks good, but there is a serious problem:
>
> src_emacs_lisp{} expressions are evaluated and replaced with the
> result in the org file, which does not happen when tangling from the
> buffer itself.
> Example:
>
> ################################################
> * name src_emacs-lisp{(buffer-file-name)}
> #+BEGIN_SRC emacs-lisp :results org :exports results :var
> buffer-file-name=(buffer-file-name)
>  (org-babel-tangle)
> #+END_SRC
> ################################################
>
> If I export the file above, the file get changed to:
>
> ################################################
> * name
>
> #+BEGIN_SRC emacs-lisp :results org :exports results :var
> buffer-file-name=(buffer-file-name)
>  (org-babel-tangle)
> #+END_SRC
> ################################################
>
> Is there something wrong with the code?
>
> Rainer
>
>
>>
>>
>> On a related note, I've added some improvements to my own way to
>> export in multiple format and add the files along with the source.
>> The latex commands and usepackage are included, so no need to add
>> them elswhere in the org file:
>>
>> ============================== # Make sure this babel block is the
>> last one in the buffer; # block after this one won't be evaluated
>> before the txt and html export. #+BEGIN_SRC emacs-lisp :results org
>> :exports results :var buffer-file-name=(buffer-file-name) (let
>> ((org-export-babel-evaluate nil)); don't evaluate in 'recursive'
>> exports (save-window-excursion ;; avoid leakage when more than one
>> org export in block (org-export-as-ascii
>> org-export-headline-levels)) (save-window-excursion
>> (org-export-as-html org-export-headline-levels)) (let ((filename
>> (file-name-nondirectory (file-name-sans-extension
>> buffer-file-name))) (to-include-files (directory-files
>> (file-name-directory buffer-file-name)))) (shell-command (concat
>> "zip -j " filename  ".zip " (mapconcat '(lambda (arg) arg)
>> (remove-if '(lambda (file) (string-match
>> "\\.$\\|\\.pdf$\\|\\.atfi$\\|\\.tex$\\|#" file)) ;; don't include
>> useless files to-include-files) " "))) (concat
>> "#+LATEX_HEADER:\\usepackage{attachfile2}\n" "#+LATEX: \\vfill
>> \\textattachfile[print=false,color=0.5 0.5
>> 0.5]{"filename".zip}{Source (.org) & html, txt...}\n"))) #+END_SRC
>> ==============================
>>
>>
>> Enjoy!
>>
>>
>>
>> On Thu, Jan 12, 2012 at 8:59 AM, Rainer M Krug <r.m.krug@gmail.com>
>> wrote:
>>> On 12 January 2012 14:54, Frozenlock <frozenlock@gmail.com>
>>> wrote:
>>>> The code block I previously sent only require you to specify
>>>> which _extension_ you want or don't want. No need to include
>>>> any specific filename (other than the .zip file in the latex
>>>> "include" command).
>>>>
>>>> Am I to understand you want something to include *all and only*
>>>> tangled files?
>>>
>>> Yes - and the files do have different extensions (e.g. .R, .sh,
>>> .sub, none) and are not tangled necessarily in a specific
>>> directory.
>>>
>>> and the original org file, but that is not a problem.
>>>
>>> Rainer
>>>
>>>>
>>>> --
>>>>
>>>> I tried ":exports result" with no success. I'll try to send a
>>>> minimum working example shortly.
>>>>
>>>> On Thu, Jan 12, 2012 at 4:11 AM, Rainer M Krug
>>>> <r.m.krug@gmail.com> wrote:
>> On 12/01/12 03:06, Frozenlock wrote:
>>>>>>> To include multiple files, I export all of the required
>>>>>>> files before the PDF creation and zip them. This way, I
>>>>>>> only need to include a single zip file.
>>
>> Good idea.
>>
>>>>>>>
>>>>>>> #+BEGIN_SRC emacs-lisp :exports none ;; various exports
>>>>>>> (save-window-excursion (org-export-as-ascii
>>>>>>> org-export-headline-levels)) (save-window-excursion
>>>>>>> (org-export-as-html org-export-headline-levels))
>>>>>>>
>>>>>>> ;;zip the required files (let ((filename
>>>>>>> (file-name-sans-extension (file-name-nondirectory
>>>>>>> (buffer-file-name))))) (shell-command (concat "zip "
>>>>>>> filename ".zip " (mapconcat '(lambda (arg) arg)
>>>>>>> (remove-if '(lambda (filename) (string-match
>>>>>>> "\\.$\\|\\.pdf$\\|\\.atfi$\\|#" filename))
>>>>>>> (directory-files (file-name-directory
>>>>>>> (buffer-file-name)))) " ")))) #+END_SRC
>>>>>>>
>>>>>>> (I've added this code in a babel block to evaluate just
>>>>>>> before the PDF export.)
>>
>> I actually did not want to fiddle with the file names, as it is to
>> easy to forget some: this concerns in my case literate programming
>> of a simulation model in R, resul;ting in several files of
>> different extensions - it is to easy to forget one.
>>
>> If I tangle, I get all the names of the tangled files, but I do
>> not know how I can feed them into the zip file.
>>
>>>>>>>
>>>>>>> As you can see, I make sure I don't include a previous
>>>>>>> PDF, or any other useless file.
>>
>> True.
>>
>>>>>>>
>>>>>>> If you wish to add only a single type of file, simply
>>>>>>> replace "remove-if" by "remove-if-not" and change the
>>>>>>> value in the string-match function. For example,
>>>>>>> "\\.$\\|\\.pdf$\\|\\.atfi$\\|#" would become "\\.lisp$"
>>>>>>> to include all your exported lisp files.
>>>>>>>
>>>>>>> Hope this helps!
>>>>>>>
>>>>>>>
>>>>>>> By the way, I can't get the code block to be evaluated
>>>>>>> automatically when I export to PDF, any clue on how to do
>>>>>>> that?
>>
>> I assume, it is caused by the :exports none - so no evaluation is
>> done on export. Try changing it to :exports result and then
>> generate an empty result, or a list of files included in the zip
>> file.
>>
>> Cheers,
>>
>> Rainer
>>
>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Wed, Jan 11, 2012 at 10:28 AM, Rainer M Krug
>>>>>>> <r.m.krug@gmail.com> wrote: On 06/01/12 08:45, Eric
>>>>>>> Schulte wrote:
>>>>>>>>>> Frozenlock <frozenlock@gmail.com> writes:
>>>>>>>>>>
>>>>>>>>>>> I am a strong advocate in keeping the source of
>>>>>>>>>>> everything.
>>>>>>>>>>>
>>>>>>>>>>> However, Â a source can easily be lost if it
>>>>>>>>>>> doesn't follow the document. In LaTeX, there's a
>>>>>>>>>>> package to attach a file to a PDF (like when you
>>>>>>>>>>> attach a file to an email). By doing so, the
>>>>>>>>>>> source will follow the PDF even if the common
>>>>>>>>>>> reader have no clue what it's for, or even how to
>>>>>>>>>>> use it.
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> This sounds like a great Reproducible Research
>>>>>>>>>> practice.
>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Here is how I attach my org source to every
>>>>>>>>>>> document I export to PDF:
>>>>>>>>>>>
>>>>>>>>>>> ;; Include the source file for every exported
>>>>>>>>>>> PDF (org-mode) (eval-after-load "org-exp"
>>>>>>>>>>> '(defadvice org-export-as-latex (around
>>>>>>>>>>> org-export-add-source-pdf activate) "Add the
>>>>>>>>>>> source (org file) to the resulting pdf file" (let
>>>>>>>>>>> ((filename (buffer-name))) ad-do-it ;do the
>>>>>>>>>>> function (let ((latex-buffer ad-return-value))
>>>>>>>>>>> (set-buffer latex-buffer) (while
>>>>>>>>>>> (re-search-forward "\\\\usepackage{.+}" nil t));
>>>>>>>>>>> go to the end of packages (insert
>>>>>>>>>>> "\n\\usepackage{attachfile2}"); the package
>>>>>>>>>>> needed to attach files (when (re-search-forward
>>>>>>>>>>> "\\\\end{document}" nil t) (forward-line -1)
>>>>>>>>>>> (insert (concat "\\vfill\n" "\\footnotesize\n"
>>>>>>>>>>> "The source of this document is an Org-Mode file
>>>>>>>>>>> attached here:" "\n\\attachfile" "{" filename
>>>>>>>>>>> "}"))) (save-buffer)))))
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> This is by no mean a patch, but rather a quick
>>>>>>>>>>> hack. Perhaps someone with a working knowledge of
>>>>>>>>>>> the org-export could find a way to add a source
>>>>>>>>>>> option?
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> I think this practice may not actually require any
>>>>>>>>>> changes to the Org-mode core. Â The attached small
>>>>>>>>>> Org-mode file will attach itself to pdf exports
>>>>>>>>>> using only features already present in Org-mode.
>>>>>>>
>>>>>>> Following this idea - how can I easily attach all files
>>>>>>> created by tangling? Is there a programmatic way, without
>>>>>>> having to specify them manually?
>>>>>>>
>>>>>>> Thanks,
>>>>>>>
>>>>>>> Rainer
>>>>>>>
>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Thanks for sharing this idea!
>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Cheers!
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>
>>>>>>>
>>
>>>
>>>
>>>
>>> -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc
>>> (Conservation Biology, UCT), Dipl. Phys. (Germany)
>>>
>>> Centre of Excellence for Invasion Biology Stellenbosch
>>> University South Africa
>>>
>>> Tel :       +33 - (0)9 53 10 27 44 Cell:       +33 - (0)6 85 62
>>> 59 98 Fax (F):       +33 - (0)9 58 10 27 44
>>>
>>> Fax (D):    +49 - (0)3 21 21 25 22 44
>>>
>>> email:      Rainer@krugs.de
>>>
>>> Skype:      RMkrug
>
> - --
> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
> Biology, UCT), Dipl. Phys. (Germany)
>
> Centre of Excellence for Invasion Biology
> Stellenbosch University
> South Africa
>
> Tel :       +33 - (0)9 53 10 27 44
> Cell:       +33 - (0)6 85 62 59 98
> Fax :       +33 - (0)9 58 10 27 44
>
> Fax (D):    +49 - (0)3 21 21 25 22 44
>
> email:      Rainer@krugs.de
>
> Skype:      RMkrug
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.11 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk8UCCEACgkQoYgNqgF2egrQjQCggcFy4UASWK2ilhtaC3jndqf0
> LEYAn2jZ5yWj9H7jTi51r64ZxuspsYUh
> =QKfm
> -----END PGP SIGNATURE-----

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

* Re: [BUG?][babel] Re:  Including source when exporting in PDF
  2012-01-18  0:57                 ` Frozenlock
@ 2012-01-18  9:03                   ` Rainer M Krug
  2012-01-20 18:12                     ` Eric Schulte
  0 siblings, 1 reply; 12+ messages in thread
From: Rainer M Krug @ 2012-01-18  9:03 UTC (permalink / raw)
  To: Frozenlock; +Cc: emacs-orgmode, Eric Schulte

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 18/01/12 01:57, Frozenlock wrote:
> I'm sorry, but I don't quite understand...
> 
> Would it be possible to send a minimum working example of your org
> file?
> 

The example is below:

################################################
* name src_emacs-lisp{(buffer-file-name)}
#+BEGIN_SRC emacs-lisp :results org :exports results :var
buffer-file-name=(buffer-file-name)
  (org-babel-tangle)
#+END_SRC
################################################

If I put the text in the ### lines in a new org file and export it, it
is modified as described below.

My guess is that it has to do with the fact that on export, a
temporary copy is created, and some confusion is happening with which
file is tangled.

Cheers,

Rainer

> 
> 
> On Mon, Jan 16, 2012 at 6:21 AM, Rainer M Krug <r.m.krug@gmail.com>
> wrote: On 15/01/12 06:29, Frozenlock wrote:
>>>> This babel block should do the following:
>>>> 
>>>> - When exporting, automatically tangle the babel blocks. -
>>>> Then take the resulting files and add them to a zip file,
>>>> along with the original .org file. - Add the necessary
>>>> \usepackage and latex commands to insert the zipfile.
>>>> 
>>>> Let me know if something isn't like you want.
>>>> 
>>>> Here is the babel block to add to your source (org) file:
>>>> 
>>>> ======================================== #+BEGIN_SRC
>>>> emacs-lisp :results org :exports results :var 
>>>> buffer-file-name=(buffer-file-name) (let ((filename 
>>>> (file-name-nondirectory (file-name-sans-extension 
>>>> buffer-file-name)))) (shell-command (concat "zip -j "
>>>> filename ".zip " filename".org " (mapconcat '(lambda (arg) 
>>>> (convert-standard-filename (expand-file-name arg))) 
>>>> (org-babel-tangle) " "))) (concat 
>>>> "#+LATEX_HEADER:\\usepackage{attachfile2}\n" "#+LATEX:
>>>> \\vfill \\textattachfile[print=false,color=0.5 0.5 
>>>> 0.5]{"filename".zip}{Source (.org) \\& other files...}\n")) 
>>>> #+END_SRC ==============================
> 
> Thanks for this code - it looks good, but there is a serious
> problem:
> 
> src_emacs_lisp{} expressions are evaluated and replaced with the 
> result in the org file, which does not happen when tangling from
> the buffer itself. Example:
> 
> ################################################ * name
> src_emacs-lisp{(buffer-file-name)} #+BEGIN_SRC emacs-lisp :results
> org :exports results :var buffer-file-name=(buffer-file-name) 
> (org-babel-tangle) #+END_SRC 
> ################################################
> 
> If I export the file above, the file get changed to:
> 
> ################################################ * name
> 
> #+BEGIN_SRC emacs-lisp :results org :exports results :var 
> buffer-file-name=(buffer-file-name) (org-babel-tangle) #+END_SRC 
> ################################################
> 
> Is there something wrong with the code?
> 
> Rainer
> 
> 
>>>> 
>>>> 
>>>> On a related note, I've added some improvements to my own way
>>>> to export in multiple format and add the files along with the
>>>> source. The latex commands and usepackage are included, so no
>>>> need to add them elswhere in the org file:
>>>> 
>>>> ============================== # Make sure this babel block
>>>> is the last one in the buffer; # block after this one won't
>>>> be evaluated before the txt and html export. #+BEGIN_SRC
>>>> emacs-lisp :results org :exports results :var
>>>> buffer-file-name=(buffer-file-name) (let 
>>>> ((org-export-babel-evaluate nil)); don't evaluate in
>>>> 'recursive' exports (save-window-excursion ;; avoid leakage
>>>> when more than one org export in block (org-export-as-ascii 
>>>> org-export-headline-levels)) (save-window-excursion 
>>>> (org-export-as-html org-export-headline-levels)) (let
>>>> ((filename (file-name-nondirectory (file-name-sans-extension 
>>>> buffer-file-name))) (to-include-files (directory-files 
>>>> (file-name-directory buffer-file-name)))) (shell-command
>>>> (concat "zip -j " filename  ".zip " (mapconcat '(lambda (arg)
>>>> arg) (remove-if '(lambda (file) (string-match 
>>>> "\\.$\\|\\.pdf$\\|\\.atfi$\\|\\.tex$\\|#" file)) ;; don't
>>>> include useless files to-include-files) " "))) (concat 
>>>> "#+LATEX_HEADER:\\usepackage{attachfile2}\n" "#+LATEX:
>>>> \\vfill \\textattachfile[print=false,color=0.5 0.5 
>>>> 0.5]{"filename".zip}{Source (.org) & html, txt...}\n")))
>>>> #+END_SRC ==============================
>>>> 
>>>> 
>>>> Enjoy!
>>>> 
>>>> 
>>>> 
>>>> On Thu, Jan 12, 2012 at 8:59 AM, Rainer M Krug
>>>> <r.m.krug@gmail.com> wrote:
>>>>> On 12 January 2012 14:54, Frozenlock
>>>>> <frozenlock@gmail.com> wrote:
>>>>>> The code block I previously sent only require you to
>>>>>> specify which _extension_ you want or don't want. No need
>>>>>> to include any specific filename (other than the .zip
>>>>>> file in the latex "include" command).
>>>>>> 
>>>>>> Am I to understand you want something to include *all and
>>>>>> only* tangled files?
>>>>> 
>>>>> Yes - and the files do have different extensions (e.g. .R,
>>>>> .sh, .sub, none) and are not tangled necessarily in a
>>>>> specific directory.
>>>>> 
>>>>> and the original org file, but that is not a problem.
>>>>> 
>>>>> Rainer
>>>>> 
>>>>>> 
>>>>>> --
>>>>>> 
>>>>>> I tried ":exports result" with no success. I'll try to
>>>>>> send a minimum working example shortly.
>>>>>> 
>>>>>> On Thu, Jan 12, 2012 at 4:11 AM, Rainer M Krug 
>>>>>> <r.m.krug@gmail.com> wrote:
>>>> On 12/01/12 03:06, Frozenlock wrote:
>>>>>>>>> To include multiple files, I export all of the
>>>>>>>>> required files before the PDF creation and zip
>>>>>>>>> them. This way, I only need to include a single zip
>>>>>>>>> file.
>>>> 
>>>> Good idea.
>>>> 
>>>>>>>>> 
>>>>>>>>> #+BEGIN_SRC emacs-lisp :exports none ;; various
>>>>>>>>> exports (save-window-excursion
>>>>>>>>> (org-export-as-ascii org-export-headline-levels))
>>>>>>>>> (save-window-excursion (org-export-as-html
>>>>>>>>> org-export-headline-levels))
>>>>>>>>> 
>>>>>>>>> ;;zip the required files (let ((filename 
>>>>>>>>> (file-name-sans-extension (file-name-nondirectory 
>>>>>>>>> (buffer-file-name))))) (shell-command (concat "zip
>>>>>>>>> " filename ".zip " (mapconcat '(lambda (arg) arg) 
>>>>>>>>> (remove-if '(lambda (filename) (string-match 
>>>>>>>>> "\\.$\\|\\.pdf$\\|\\.atfi$\\|#" filename)) 
>>>>>>>>> (directory-files (file-name-directory 
>>>>>>>>> (buffer-file-name)))) " ")))) #+END_SRC
>>>>>>>>> 
>>>>>>>>> (I've added this code in a babel block to evaluate
>>>>>>>>> just before the PDF export.)
>>>> 
>>>> I actually did not want to fiddle with the file names, as it
>>>> is to easy to forget some: this concerns in my case literate
>>>> programming of a simulation model in R, resul;ting in several
>>>> files of different extensions - it is to easy to forget one.
>>>> 
>>>> If I tangle, I get all the names of the tangled files, but I
>>>> do not know how I can feed them into the zip file.
>>>> 
>>>>>>>>> 
>>>>>>>>> As you can see, I make sure I don't include a
>>>>>>>>> previous PDF, or any other useless file.
>>>> 
>>>> True.
>>>> 
>>>>>>>>> 
>>>>>>>>> If you wish to add only a single type of file,
>>>>>>>>> simply replace "remove-if" by "remove-if-not" and
>>>>>>>>> change the value in the string-match function. For
>>>>>>>>> example, "\\.$\\|\\.pdf$\\|\\.atfi$\\|#" would
>>>>>>>>> become "\\.lisp$" to include all your exported lisp
>>>>>>>>> files.
>>>>>>>>> 
>>>>>>>>> Hope this helps!
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> By the way, I can't get the code block to be
>>>>>>>>> evaluated automatically when I export to PDF, any
>>>>>>>>> clue on how to do that?
>>>> 
>>>> I assume, it is caused by the :exports none - so no
>>>> evaluation is done on export. Try changing it to :exports
>>>> result and then generate an empty result, or a list of files
>>>> included in the zip file.
>>>> 
>>>> Cheers,
>>>> 
>>>> Rainer
>>>> 
>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> On Wed, Jan 11, 2012 at 10:28 AM, Rainer M Krug 
>>>>>>>>> <r.m.krug@gmail.com> wrote: On 06/01/12 08:45,
>>>>>>>>> Eric Schulte wrote:
>>>>>>>>>>>> Frozenlock <frozenlock@gmail.com> writes:
>>>>>>>>>>>> 
>>>>>>>>>>>>> I am a strong advocate in keeping the
>>>>>>>>>>>>> source of everything.
>>>>>>>>>>>>> 
>>>>>>>>>>>>> However, Â a source can easily be lost if
>>>>>>>>>>>>> it doesn't follow the document. In LaTeX,
>>>>>>>>>>>>> there's a package to attach a file to a PDF
>>>>>>>>>>>>> (like when you attach a file to an email).
>>>>>>>>>>>>> By doing so, the source will follow the PDF
>>>>>>>>>>>>> even if the common reader have no clue what
>>>>>>>>>>>>> it's for, or even how to use it.
>>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> This sounds like a great Reproducible
>>>>>>>>>>>> Research practice.
>>>>>>>>>>>> 
>>>>>>>>>>>>> 
>>>>>>>>>>>>> Here is how I attach my org source to
>>>>>>>>>>>>> every document I export to PDF:
>>>>>>>>>>>>> 
>>>>>>>>>>>>> ;; Include the source file for every
>>>>>>>>>>>>> exported PDF (org-mode) (eval-after-load
>>>>>>>>>>>>> "org-exp" '(defadvice org-export-as-latex
>>>>>>>>>>>>> (around org-export-add-source-pdf activate)
>>>>>>>>>>>>> "Add the source (org file) to the resulting
>>>>>>>>>>>>> pdf file" (let ((filename (buffer-name)))
>>>>>>>>>>>>> ad-do-it ;do the function (let
>>>>>>>>>>>>> ((latex-buffer ad-return-value)) 
>>>>>>>>>>>>> (set-buffer latex-buffer) (while 
>>>>>>>>>>>>> (re-search-forward "\\\\usepackage{.+}" nil
>>>>>>>>>>>>> t)); go to the end of packages (insert 
>>>>>>>>>>>>> "\n\\usepackage{attachfile2}"); the
>>>>>>>>>>>>> package needed to attach files (when
>>>>>>>>>>>>> (re-search-forward "\\\\end{document}" nil
>>>>>>>>>>>>> t) (forward-line -1) (insert (concat
>>>>>>>>>>>>> "\\vfill\n" "\\footnotesize\n" "The source
>>>>>>>>>>>>> of this document is an Org-Mode file 
>>>>>>>>>>>>> attached here:" "\n\\attachfile" "{"
>>>>>>>>>>>>> filename "}"))) (save-buffer)))))
>>>>>>>>>>>>> 
>>>>>>>>>>>>> 
>>>>>>>>>>>>> This is by no mean a patch, but rather a
>>>>>>>>>>>>> quick hack. Perhaps someone with a working
>>>>>>>>>>>>> knowledge of the org-export could find a
>>>>>>>>>>>>> way to add a source option?
>>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> I think this practice may not actually
>>>>>>>>>>>> require any changes to the Org-mode core. Â
>>>>>>>>>>>> The attached small Org-mode file will attach
>>>>>>>>>>>> itself to pdf exports using only features
>>>>>>>>>>>> already present in Org-mode.
>>>>>>>>> 
>>>>>>>>> Following this idea - how can I easily attach all
>>>>>>>>> files created by tangling? Is there a programmatic
>>>>>>>>> way, without having to specify them manually?
>>>>>>>>> 
>>>>>>>>> Thanks,
>>>>>>>>> 
>>>>>>>>> Rainer
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> Thanks for sharing this idea!
>>>>>>>>>>>> 
>>>>>>>>>>>>> 
>>>>>>>>>>>>> 
>>>>>>>>>>>>> Cheers!
>>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc 
>>>>> (Conservation Biology, UCT), Dipl. Phys. (Germany)
>>>>> 
>>>>> Centre of Excellence for Invasion Biology Stellenbosch 
>>>>> University South Africa
>>>>> 
>>>>> Tel :       +33 - (0)9 53 10 27 44 Cell:       +33 - (0)6
>>>>> 85 62 59 98 Fax (F):       +33 - (0)9 58 10 27 44
>>>>> 
>>>>> Fax (D):    +49 - (0)3 21 21 25 22 44
>>>>> 
>>>>> email:      Rainer@krugs.de
>>>>> 
>>>>> Skype:      RMkrug
> 

- -- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      Rainer@krugs.de

Skype:      RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk8WisYACgkQoYgNqgF2egpFsACfYejaRRCaCy312UKqY1L4i7ZE
NkkAnRv0jffw++k8rvky+xckPKeMWqps
=VaDt
-----END PGP SIGNATURE-----

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

* Re: [BUG?][babel] Re:  Including source when exporting in PDF
  2012-01-18  9:03                   ` Rainer M Krug
@ 2012-01-20 18:12                     ` Eric Schulte
  0 siblings, 0 replies; 12+ messages in thread
From: Eric Schulte @ 2012-01-20 18:12 UTC (permalink / raw)
  To: R.M.Krug; +Cc: emacs-orgmode, Frozenlock

[-- Attachment #1: Type: text/plain, Size: 321 bytes --]

Rainer M Krug <r.m.krug@gmail.com> writes:

> On 18/01/12 01:57, Frozenlock wrote:
>> I'm sorry, but I don't quite understand...
>> 
>> Would it be possible to send a minimum working example of your org
>> file?
>> 
>
> The example is below:
>

This is likely the most evil snippet of Org-mode code I have ever
seen. :)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: evil.org --]
[-- Type: text/x-org, Size: 183 bytes --]

#+Options: ^:nil

* name src_emacs-lisp{(buffer-file-name)}

#+BEGIN_SRC emacs-lisp :results org :exports code :var buffer-file-name=(buffer-file-name)
  (org-babel-tangle)
#+END_SRC

[-- Attachment #3: Type: text/plain, Size: 693 bytes --]


I can confirm that it does modify the value of the file on disk as part
of the export process.  Additionally, the src_emacs_lisp in the header
does not export any results because by the time (buffer-file-name) is
called the code is living in a temporary export buffer which is not
visiting a file, note that a heading like the following would probably
give the result you're after

* name src_emacs-lisp{org-current-export-file}

similarly you want the tangling to be done in the original Org-mode file
(not the temporary export file), so that should be placed in a header
argument as well.  Try the following less evil version on for size and
let me know if it doesn't solve your problems.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: less-evil.org --]
[-- Type: text/x-org, Size: 309 bytes --]

#+Options: ^:nil

* name src_emacs-lisp{org-current-export-file}

One block to tangle.
#+BEGIN_SRC emacs-lisp :tangle yes
  (message "I am tangled")
#+END_SRC

One block to export.
#+BEGIN_SRC emacs-lisp :exports results :var foo=(org-babel-tangle)
  (message "I just tangled %S during export" foo)
#+END_SRC

[-- Attachment #5: Type: text/plain, Size: 11845 bytes --]


>
> ################################################
> * name src_emacs-lisp{(buffer-file-name)}
> #+BEGIN_SRC emacs-lisp :results org :exports results :var
> buffer-file-name=(buffer-file-name)
>   (org-babel-tangle)
> #+END_SRC
> ################################################
>
> If I put the text in the ### lines in a new org file and export it, it
> is modified as described below.
>
> My guess is that it has to do with the fact that on export, a
> temporary copy is created, and some confusion is happening with which
> file is tangled.
>
> Cheers,
>
> Rainer
>
>> 
>> 
>> On Mon, Jan 16, 2012 at 6:21 AM, Rainer M Krug <r.m.krug@gmail.com>
>> wrote: On 15/01/12 06:29, Frozenlock wrote:
>>>>> This babel block should do the following:
>>>>> 
>>>>> - When exporting, automatically tangle the babel blocks. -
>>>>> Then take the resulting files and add them to a zip file,
>>>>> along with the original .org file. - Add the necessary
>>>>> \usepackage and latex commands to insert the zipfile.
>>>>> 
>>>>> Let me know if something isn't like you want.
>>>>> 
>>>>> Here is the babel block to add to your source (org) file:
>>>>> 
>>>>> ======================================== #+BEGIN_SRC
>>>>> emacs-lisp :results org :exports results :var 
>>>>> buffer-file-name=(buffer-file-name) (let ((filename 
>>>>> (file-name-nondirectory (file-name-sans-extension 
>>>>> buffer-file-name)))) (shell-command (concat "zip -j "
>>>>> filename ".zip " filename".org " (mapconcat '(lambda (arg) 
>>>>> (convert-standard-filename (expand-file-name arg))) 
>>>>> (org-babel-tangle) " "))) (concat 
>>>>> "#+LATEX_HEADER:\\usepackage{attachfile2}\n" "#+LATEX:
>>>>> \\vfill \\textattachfile[print=false,color=0.5 0.5 
>>>>> 0.5]{"filename".zip}{Source (.org) \\& other files...}\n")) 
>>>>> #+END_SRC ==============================
>> 
>> Thanks for this code - it looks good, but there is a serious
>> problem:
>> 
>> src_emacs_lisp{} expressions are evaluated and replaced with the 
>> result in the org file, which does not happen when tangling from
>> the buffer itself. Example:
>> 
>> ################################################ * name
>> src_emacs-lisp{(buffer-file-name)} #+BEGIN_SRC emacs-lisp :results
>> org :exports results :var buffer-file-name=(buffer-file-name) 
>> (org-babel-tangle) #+END_SRC 
>> ################################################
>> 
>> If I export the file above, the file get changed to:
>> 
>> ################################################ * name
>> 
>> #+BEGIN_SRC emacs-lisp :results org :exports results :var 
>> buffer-file-name=(buffer-file-name) (org-babel-tangle) #+END_SRC 
>> ################################################
>> 
>> Is there something wrong with the code?
>> 
>> Rainer
>> 
>> 
>>>>> 
>>>>> 
>>>>> On a related note, I've added some improvements to my own way
>>>>> to export in multiple format and add the files along with the
>>>>> source. The latex commands and usepackage are included, so no
>>>>> need to add them elswhere in the org file:
>>>>> 
>>>>> ============================== # Make sure this babel block
>>>>> is the last one in the buffer; # block after this one won't
>>>>> be evaluated before the txt and html export. #+BEGIN_SRC
>>>>> emacs-lisp :results org :exports results :var
>>>>> buffer-file-name=(buffer-file-name) (let 
>>>>> ((org-export-babel-evaluate nil)); don't evaluate in
>>>>> 'recursive' exports (save-window-excursion ;; avoid leakage
>>>>> when more than one org export in block (org-export-as-ascii 
>>>>> org-export-headline-levels)) (save-window-excursion 
>>>>> (org-export-as-html org-export-headline-levels)) (let
>>>>> ((filename (file-name-nondirectory (file-name-sans-extension 
>>>>> buffer-file-name))) (to-include-files (directory-files 
>>>>> (file-name-directory buffer-file-name)))) (shell-command
>>>>> (concat "zip -j " filename  ".zip " (mapconcat '(lambda (arg)
>>>>> arg) (remove-if '(lambda (file) (string-match 
>>>>> "\\.$\\|\\.pdf$\\|\\.atfi$\\|\\.tex$\\|#" file)) ;; don't
>>>>> include useless files to-include-files) " "))) (concat 
>>>>> "#+LATEX_HEADER:\\usepackage{attachfile2}\n" "#+LATEX:
>>>>> \\vfill \\textattachfile[print=false,color=0.5 0.5 
>>>>> 0.5]{"filename".zip}{Source (.org) & html, txt...}\n")))
>>>>> #+END_SRC ==============================
>>>>> 
>>>>> 
>>>>> Enjoy!
>>>>> 
>>>>> 
>>>>> 
>>>>> On Thu, Jan 12, 2012 at 8:59 AM, Rainer M Krug
>>>>> <r.m.krug@gmail.com> wrote:
>>>>>> On 12 January 2012 14:54, Frozenlock
>>>>>> <frozenlock@gmail.com> wrote:
>>>>>>> The code block I previously sent only require you to
>>>>>>> specify which _extension_ you want or don't want. No need
>>>>>>> to include any specific filename (other than the .zip
>>>>>>> file in the latex "include" command).
>>>>>>> 
>>>>>>> Am I to understand you want something to include *all and
>>>>>>> only* tangled files?
>>>>>> 
>>>>>> Yes - and the files do have different extensions (e.g. .R,
>>>>>> .sh, .sub, none) and are not tangled necessarily in a
>>>>>> specific directory.
>>>>>> 
>>>>>> and the original org file, but that is not a problem.
>>>>>> 
>>>>>> Rainer
>>>>>> 
>>>>>>> 
>>>>>>> --
>>>>>>> 
>>>>>>> I tried ":exports result" with no success. I'll try to
>>>>>>> send a minimum working example shortly.
>>>>>>> 
>>>>>>> On Thu, Jan 12, 2012 at 4:11 AM, Rainer M Krug 
>>>>>>> <r.m.krug@gmail.com> wrote:
>>>>> On 12/01/12 03:06, Frozenlock wrote:
>>>>>>>>>> To include multiple files, I export all of the
>>>>>>>>>> required files before the PDF creation and zip
>>>>>>>>>> them. This way, I only need to include a single zip
>>>>>>>>>> file.
>>>>> 
>>>>> Good idea.
>>>>> 
>>>>>>>>>> 
>>>>>>>>>> #+BEGIN_SRC emacs-lisp :exports none ;; various
>>>>>>>>>> exports (save-window-excursion
>>>>>>>>>> (org-export-as-ascii org-export-headline-levels))
>>>>>>>>>> (save-window-excursion (org-export-as-html
>>>>>>>>>> org-export-headline-levels))
>>>>>>>>>> 
>>>>>>>>>> ;;zip the required files (let ((filename 
>>>>>>>>>> (file-name-sans-extension (file-name-nondirectory 
>>>>>>>>>> (buffer-file-name))))) (shell-command (concat "zip
>>>>>>>>>> " filename ".zip " (mapconcat '(lambda (arg) arg) 
>>>>>>>>>> (remove-if '(lambda (filename) (string-match 
>>>>>>>>>> "\\.$\\|\\.pdf$\\|\\.atfi$\\|#" filename)) 
>>>>>>>>>> (directory-files (file-name-directory 
>>>>>>>>>> (buffer-file-name)))) " ")))) #+END_SRC
>>>>>>>>>> 
>>>>>>>>>> (I've added this code in a babel block to evaluate
>>>>>>>>>> just before the PDF export.)
>>>>> 
>>>>> I actually did not want to fiddle with the file names, as it
>>>>> is to easy to forget some: this concerns in my case literate
>>>>> programming of a simulation model in R, resul;ting in several
>>>>> files of different extensions - it is to easy to forget one.
>>>>> 
>>>>> If I tangle, I get all the names of the tangled files, but I
>>>>> do not know how I can feed them into the zip file.
>>>>> 
>>>>>>>>>> 
>>>>>>>>>> As you can see, I make sure I don't include a
>>>>>>>>>> previous PDF, or any other useless file.
>>>>> 
>>>>> True.
>>>>> 
>>>>>>>>>> 
>>>>>>>>>> If you wish to add only a single type of file,
>>>>>>>>>> simply replace "remove-if" by "remove-if-not" and
>>>>>>>>>> change the value in the string-match function. For
>>>>>>>>>> example, "\\.$\\|\\.pdf$\\|\\.atfi$\\|#" would
>>>>>>>>>> become "\\.lisp$" to include all your exported lisp
>>>>>>>>>> files.
>>>>>>>>>> 
>>>>>>>>>> Hope this helps!
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> By the way, I can't get the code block to be
>>>>>>>>>> evaluated automatically when I export to PDF, any
>>>>>>>>>> clue on how to do that?
>>>>> 
>>>>> I assume, it is caused by the :exports none - so no
>>>>> evaluation is done on export. Try changing it to :exports
>>>>> result and then generate an empty result, or a list of files
>>>>> included in the zip file.
>>>>> 
>>>>> Cheers,
>>>>> 
>>>>> Rainer
>>>>> 
>>>>> 
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> On Wed, Jan 11, 2012 at 10:28 AM, Rainer M Krug 
>>>>>>>>>> <r.m.krug@gmail.com> wrote: On 06/01/12 08:45,
>>>>>>>>>> Eric Schulte wrote:
>>>>>>>>>>>>> Frozenlock <frozenlock@gmail.com> writes:
>>>>>>>>>>>>> 
>>>>>>>>>>>>>> I am a strong advocate in keeping the
>>>>>>>>>>>>>> source of everything.
>>>>>>>>>>>>>> 
>>>>>>>>>>>>>> However, Â a source can easily be lost if
>>>>>>>>>>>>>> it doesn't follow the document. In LaTeX,
>>>>>>>>>>>>>> there's a package to attach a file to a PDF
>>>>>>>>>>>>>> (like when you attach a file to an email).
>>>>>>>>>>>>>> By doing so, the source will follow the PDF
>>>>>>>>>>>>>> even if the common reader have no clue what
>>>>>>>>>>>>>> it's for, or even how to use it.
>>>>>>>>>>>>>> 
>>>>>>>>>>>>> 
>>>>>>>>>>>>> This sounds like a great Reproducible
>>>>>>>>>>>>> Research practice.
>>>>>>>>>>>>> 
>>>>>>>>>>>>>> 
>>>>>>>>>>>>>> Here is how I attach my org source to
>>>>>>>>>>>>>> every document I export to PDF:
>>>>>>>>>>>>>> 
>>>>>>>>>>>>>> ;; Include the source file for every
>>>>>>>>>>>>>> exported PDF (org-mode) (eval-after-load
>>>>>>>>>>>>>> "org-exp" '(defadvice org-export-as-latex
>>>>>>>>>>>>>> (around org-export-add-source-pdf activate)
>>>>>>>>>>>>>> "Add the source (org file) to the resulting
>>>>>>>>>>>>>> pdf file" (let ((filename (buffer-name)))
>>>>>>>>>>>>>> ad-do-it ;do the function (let
>>>>>>>>>>>>>> ((latex-buffer ad-return-value)) 
>>>>>>>>>>>>>> (set-buffer latex-buffer) (while 
>>>>>>>>>>>>>> (re-search-forward "\\\\usepackage{.+}" nil
>>>>>>>>>>>>>> t)); go to the end of packages (insert 
>>>>>>>>>>>>>> "\n\\usepackage{attachfile2}"); the
>>>>>>>>>>>>>> package needed to attach files (when
>>>>>>>>>>>>>> (re-search-forward "\\\\end{document}" nil
>>>>>>>>>>>>>> t) (forward-line -1) (insert (concat
>>>>>>>>>>>>>> "\\vfill\n" "\\footnotesize\n" "The source
>>>>>>>>>>>>>> of this document is an Org-Mode file 
>>>>>>>>>>>>>> attached here:" "\n\\attachfile" "{"
>>>>>>>>>>>>>> filename "}"))) (save-buffer)))))
>>>>>>>>>>>>>> 
>>>>>>>>>>>>>> 
>>>>>>>>>>>>>> This is by no mean a patch, but rather a
>>>>>>>>>>>>>> quick hack. Perhaps someone with a working
>>>>>>>>>>>>>> knowledge of the org-export could find a
>>>>>>>>>>>>>> way to add a source option?
>>>>>>>>>>>>>> 
>>>>>>>>>>>>> 
>>>>>>>>>>>>> I think this practice may not actually
>>>>>>>>>>>>> require any changes to the Org-mode core. Â
>>>>>>>>>>>>> The attached small Org-mode file will attach
>>>>>>>>>>>>> itself to pdf exports using only features
>>>>>>>>>>>>> already present in Org-mode.
>>>>>>>>>> 
>>>>>>>>>> Following this idea - how can I easily attach all
>>>>>>>>>> files created by tangling? Is there a programmatic
>>>>>>>>>> way, without having to specify them manually?
>>>>>>>>>> 
>>>>>>>>>> Thanks,
>>>>>>>>>> 
>>>>>>>>>> Rainer
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>>>>> 
>>>>>>>>>>>>> 
>>>>>>>>>>>>> 
>>>>>>>>>>>>> 
>>>>>>>>>>>>> 
>>>>>>>>>>>>> Thanks for sharing this idea!
>>>>>>>>>>>>> 
>>>>>>>>>>>>>> 
>>>>>>>>>>>>>> 
>>>>>>>>>>>>>> Cheers!
>>>>>>>>>>>>>> 
>>>>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> 
>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc 
>>>>>> (Conservation Biology, UCT), Dipl. Phys. (Germany)
>>>>>> 
>>>>>> Centre of Excellence for Invasion Biology Stellenbosch 
>>>>>> University South Africa
>>>>>> 
>>>>>> Tel :       +33 - (0)9 53 10 27 44 Cell:       +33 - (0)6
>>>>>> 85 62 59 98 Fax (F):       +33 - (0)9 58 10 27 44
>>>>>> 
>>>>>> Fax (D):    +49 - (0)3 21 21 25 22 44
>>>>>> 
>>>>>> email:      Rainer@krugs.de
>>>>>> 
>>>>>> Skype:      RMkrug
>> 

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

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

end of thread, other threads:[~2012-01-20 19:01 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-04 21:29 Including source when exporting in PDF Frozenlock
2012-01-06  7:45 ` Eric Schulte
2012-01-11 15:28   ` Rainer M Krug
2012-01-12  2:06     ` Frozenlock
2012-01-12  9:11       ` Rainer M Krug
2012-01-12 13:54         ` Frozenlock
2012-01-12 13:59           ` Rainer M Krug
2012-01-15  5:29             ` Frozenlock
2012-01-16 11:21               ` [BUG?][babel] " Rainer M Krug
2012-01-18  0:57                 ` Frozenlock
2012-01-18  9:03                   ` Rainer M Krug
2012-01-20 18:12                     ` Eric Schulte

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