From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rainer M Krug Subject: Re: Including source when exporting in PDF Date: Thu, 12 Jan 2012 14:59:49 +0100 Message-ID: References: <8739bt1dhe.fsf@gmx.com> <4F0DAAAC.50607@gmail.com> <4F0EA3B5.6080903@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([140.186.70.92]:46488) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RlLC8-0007hl-9z for emacs-orgmode@gnu.org; Thu, 12 Jan 2012 09:00:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RlLC1-0005tm-RD for emacs-orgmode@gnu.org; Thu, 12 Jan 2012 08:59:56 -0500 Received: from mail-qw0-f48.google.com ([209.85.216.48]:43606) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RlLC1-0005th-Mq for emacs-orgmode@gnu.org; Thu, 12 Jan 2012 08:59:49 -0500 Received: by qadz30 with SMTP id z30so323744qad.0 for ; Thu, 12 Jan 2012 05:59:49 -0800 (PST) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Frozenlock Cc: emacs-orgmode@gnu.org, Eric Schulte On 12 January 2012 14:54, Frozenlock 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 f= iles? 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 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 >>> wrote: On 06/01/12 08:45, Eric Schulte wrote: >>>>>> Frozenlock writes: >>>>>> >>>>>>> I am a strong advocate in keeping the source of >>>>>>> everything. >>>>>>> >>>>>>> However, =C2 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. =C2 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 : =A0 =A0 =A0 +33 - (0)9 53 10 27 44 >> Cell: =A0 =A0 =A0 +33 - (0)6 85 62 59 98 >> Fax : =A0 =A0 =A0 +33 - (0)9 58 10 27 44 >> >> Fax (D): =A0 =A0+49 - (0)3 21 21 25 22 44 >> >> email: =A0 =A0 =A0Rainer@krugs.de >> >> Skype: =A0 =A0 =A0RMkrug >> -----BEGIN PGP SIGNATURE----- >> Version: GnuPG v1.4.11 (GNU/Linux) >> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ >> >> iEUEARECAAYFAk8Oo7UACgkQoYgNqgF2egpg9wCfTq04zAVki+Oh1g97/C3FERf3 >> Ej0Al30dF8xQdyHNOmOK8y7ZolA0dzE=3D >> =3DIUuN >> -----END PGP SIGNATURE----- --=20 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 : =A0 =A0 =A0 +33 - (0)9 53 10 27 44 Cell: =A0 =A0 =A0 +33 - (0)6 85 62 59 98 Fax (F): =A0 =A0 =A0 +33 - (0)9 58 10 27 44 Fax (D): =A0 =A0+49 - (0)3 21 21 25 22 44 email: =A0 =A0 =A0Rainer@krugs.de Skype: =A0 =A0 =A0RMkrug