How to embedded source code on-demand into PDF?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
6
down vote

favorite
2












I wondered if its possible to embed source code of some software you are writing about into the PDF but not displayed by default. E.g. you have a long script I would be nice if the user/reader could click on a link if he needs details, and see the source code of that script.



Best would be if this can be rendered with syntax highlighting (by listings or minted package).



So far I am only aware of either use ECMAscript (which seems not supported by latex) or by OCG layers, as tooltips. For both I am unsure if they support syntax highlighting.



As a workaround I would do it as in the old days with an appendix and hyperref to it.



Do you have any better suggestion?







share|improve this question
























    up vote
    6
    down vote

    favorite
    2












    I wondered if its possible to embed source code of some software you are writing about into the PDF but not displayed by default. E.g. you have a long script I would be nice if the user/reader could click on a link if he needs details, and see the source code of that script.



    Best would be if this can be rendered with syntax highlighting (by listings or minted package).



    So far I am only aware of either use ECMAscript (which seems not supported by latex) or by OCG layers, as tooltips. For both I am unsure if they support syntax highlighting.



    As a workaround I would do it as in the old days with an appendix and hyperref to it.



    Do you have any better suggestion?







    share|improve this question






















      up vote
      6
      down vote

      favorite
      2









      up vote
      6
      down vote

      favorite
      2






      2





      I wondered if its possible to embed source code of some software you are writing about into the PDF but not displayed by default. E.g. you have a long script I would be nice if the user/reader could click on a link if he needs details, and see the source code of that script.



      Best would be if this can be rendered with syntax highlighting (by listings or minted package).



      So far I am only aware of either use ECMAscript (which seems not supported by latex) or by OCG layers, as tooltips. For both I am unsure if they support syntax highlighting.



      As a workaround I would do it as in the old days with an appendix and hyperref to it.



      Do you have any better suggestion?







      share|improve this question












      I wondered if its possible to embed source code of some software you are writing about into the PDF but not displayed by default. E.g. you have a long script I would be nice if the user/reader could click on a link if he needs details, and see the source code of that script.



      Best would be if this can be rendered with syntax highlighting (by listings or minted package).



      So far I am only aware of either use ECMAscript (which seems not supported by latex) or by OCG layers, as tooltips. For both I am unsure if they support syntax highlighting.



      As a workaround I would do it as in the old days with an appendix and hyperref to it.



      Do you have any better suggestion?









      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 20 at 8:53









      math

      1,74021623




      1,74021623




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          8
          down vote



          accepted










          Yes, you may embed your source code as a file in the pdf. I'm using usually the package attachfile, but there are some more, the embedfile package e.g. or attachfile2.



          Using attachfile I'm printing an icon into the margin and explain in the PDF text that clicking on the symbol will provide the attached file.






          share|improve this answer






















          • Please note that there is a difference between attaching and embedding at the PDF file level, see the documentation of the packages.
            – TeXnician
            Aug 20 at 9:01










          • @TeXnician the documentation of attachfile says "This package defines an attachfile command that lets you attach arbitrary files to a pdf document. These files are embedded right in the pdf file, so they get transmitted along with it." That sounds like there is no difference?
            – lucidbrot
            Aug 20 at 11:14






          • 1




            @lucidbrot You need to read the right documentation (attachfile2/embedfile): "The PDF format ([3]) allows the inclusion of fies inside the PDF document. The included fies can be bound to an annotation on a page. Or they can be recorded in a sorted list of embedded fies. The packages attachfie or attachfie2 follow the fist approach, package embedfie uses the latter method." Of course that does not explain the technical details, but it gives the right hint.
            – TeXnician
            Aug 20 at 11:22











          • Yes this is quite cool. Unfortunately not all PDF readers can handle it, e.g. I tried to open with firefox builtin reader and no action took place. But with other readers I had success, very neat. Thank all of you so much.
            – math
            Aug 20 at 11:38






          • 1




            @lucidbrot If I remember correctly you'll find the PDF specification online which should contain these details. Concerning the linking I think they are quite equivalent.
            – TeXnician
            Aug 20 at 12:17










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "85"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f446779%2fhow-to-embedded-source-code-on-demand-into-pdf%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          8
          down vote



          accepted










          Yes, you may embed your source code as a file in the pdf. I'm using usually the package attachfile, but there are some more, the embedfile package e.g. or attachfile2.



          Using attachfile I'm printing an icon into the margin and explain in the PDF text that clicking on the symbol will provide the attached file.






          share|improve this answer






















          • Please note that there is a difference between attaching and embedding at the PDF file level, see the documentation of the packages.
            – TeXnician
            Aug 20 at 9:01










          • @TeXnician the documentation of attachfile says "This package defines an attachfile command that lets you attach arbitrary files to a pdf document. These files are embedded right in the pdf file, so they get transmitted along with it." That sounds like there is no difference?
            – lucidbrot
            Aug 20 at 11:14






          • 1




            @lucidbrot You need to read the right documentation (attachfile2/embedfile): "The PDF format ([3]) allows the inclusion of fies inside the PDF document. The included fies can be bound to an annotation on a page. Or they can be recorded in a sorted list of embedded fies. The packages attachfie or attachfie2 follow the fist approach, package embedfie uses the latter method." Of course that does not explain the technical details, but it gives the right hint.
            – TeXnician
            Aug 20 at 11:22











          • Yes this is quite cool. Unfortunately not all PDF readers can handle it, e.g. I tried to open with firefox builtin reader and no action took place. But with other readers I had success, very neat. Thank all of you so much.
            – math
            Aug 20 at 11:38






          • 1




            @lucidbrot If I remember correctly you'll find the PDF specification online which should contain these details. Concerning the linking I think they are quite equivalent.
            – TeXnician
            Aug 20 at 12:17














          up vote
          8
          down vote



          accepted










          Yes, you may embed your source code as a file in the pdf. I'm using usually the package attachfile, but there are some more, the embedfile package e.g. or attachfile2.



          Using attachfile I'm printing an icon into the margin and explain in the PDF text that clicking on the symbol will provide the attached file.






          share|improve this answer






















          • Please note that there is a difference between attaching and embedding at the PDF file level, see the documentation of the packages.
            – TeXnician
            Aug 20 at 9:01










          • @TeXnician the documentation of attachfile says "This package defines an attachfile command that lets you attach arbitrary files to a pdf document. These files are embedded right in the pdf file, so they get transmitted along with it." That sounds like there is no difference?
            – lucidbrot
            Aug 20 at 11:14






          • 1




            @lucidbrot You need to read the right documentation (attachfile2/embedfile): "The PDF format ([3]) allows the inclusion of fies inside the PDF document. The included fies can be bound to an annotation on a page. Or they can be recorded in a sorted list of embedded fies. The packages attachfie or attachfie2 follow the fist approach, package embedfie uses the latter method." Of course that does not explain the technical details, but it gives the right hint.
            – TeXnician
            Aug 20 at 11:22











          • Yes this is quite cool. Unfortunately not all PDF readers can handle it, e.g. I tried to open with firefox builtin reader and no action took place. But with other readers I had success, very neat. Thank all of you so much.
            – math
            Aug 20 at 11:38






          • 1




            @lucidbrot If I remember correctly you'll find the PDF specification online which should contain these details. Concerning the linking I think they are quite equivalent.
            – TeXnician
            Aug 20 at 12:17












          up vote
          8
          down vote



          accepted







          up vote
          8
          down vote



          accepted






          Yes, you may embed your source code as a file in the pdf. I'm using usually the package attachfile, but there are some more, the embedfile package e.g. or attachfile2.



          Using attachfile I'm printing an icon into the margin and explain in the PDF text that clicking on the symbol will provide the attached file.






          share|improve this answer














          Yes, you may embed your source code as a file in the pdf. I'm using usually the package attachfile, but there are some more, the embedfile package e.g. or attachfile2.



          Using attachfile I'm printing an icon into the margin and explain in the PDF text that clicking on the symbol will provide the attached file.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 20 at 9:03

























          answered Aug 20 at 8:58









          Keks Dose

          19.8k35190




          19.8k35190











          • Please note that there is a difference between attaching and embedding at the PDF file level, see the documentation of the packages.
            – TeXnician
            Aug 20 at 9:01










          • @TeXnician the documentation of attachfile says "This package defines an attachfile command that lets you attach arbitrary files to a pdf document. These files are embedded right in the pdf file, so they get transmitted along with it." That sounds like there is no difference?
            – lucidbrot
            Aug 20 at 11:14






          • 1




            @lucidbrot You need to read the right documentation (attachfile2/embedfile): "The PDF format ([3]) allows the inclusion of fies inside the PDF document. The included fies can be bound to an annotation on a page. Or they can be recorded in a sorted list of embedded fies. The packages attachfie or attachfie2 follow the fist approach, package embedfie uses the latter method." Of course that does not explain the technical details, but it gives the right hint.
            – TeXnician
            Aug 20 at 11:22











          • Yes this is quite cool. Unfortunately not all PDF readers can handle it, e.g. I tried to open with firefox builtin reader and no action took place. But with other readers I had success, very neat. Thank all of you so much.
            – math
            Aug 20 at 11:38






          • 1




            @lucidbrot If I remember correctly you'll find the PDF specification online which should contain these details. Concerning the linking I think they are quite equivalent.
            – TeXnician
            Aug 20 at 12:17
















          • Please note that there is a difference between attaching and embedding at the PDF file level, see the documentation of the packages.
            – TeXnician
            Aug 20 at 9:01










          • @TeXnician the documentation of attachfile says "This package defines an attachfile command that lets you attach arbitrary files to a pdf document. These files are embedded right in the pdf file, so they get transmitted along with it." That sounds like there is no difference?
            – lucidbrot
            Aug 20 at 11:14






          • 1




            @lucidbrot You need to read the right documentation (attachfile2/embedfile): "The PDF format ([3]) allows the inclusion of fies inside the PDF document. The included fies can be bound to an annotation on a page. Or they can be recorded in a sorted list of embedded fies. The packages attachfie or attachfie2 follow the fist approach, package embedfie uses the latter method." Of course that does not explain the technical details, but it gives the right hint.
            – TeXnician
            Aug 20 at 11:22











          • Yes this is quite cool. Unfortunately not all PDF readers can handle it, e.g. I tried to open with firefox builtin reader and no action took place. But with other readers I had success, very neat. Thank all of you so much.
            – math
            Aug 20 at 11:38






          • 1




            @lucidbrot If I remember correctly you'll find the PDF specification online which should contain these details. Concerning the linking I think they are quite equivalent.
            – TeXnician
            Aug 20 at 12:17















          Please note that there is a difference between attaching and embedding at the PDF file level, see the documentation of the packages.
          – TeXnician
          Aug 20 at 9:01




          Please note that there is a difference between attaching and embedding at the PDF file level, see the documentation of the packages.
          – TeXnician
          Aug 20 at 9:01












          @TeXnician the documentation of attachfile says "This package defines an attachfile command that lets you attach arbitrary files to a pdf document. These files are embedded right in the pdf file, so they get transmitted along with it." That sounds like there is no difference?
          – lucidbrot
          Aug 20 at 11:14




          @TeXnician the documentation of attachfile says "This package defines an attachfile command that lets you attach arbitrary files to a pdf document. These files are embedded right in the pdf file, so they get transmitted along with it." That sounds like there is no difference?
          – lucidbrot
          Aug 20 at 11:14




          1




          1




          @lucidbrot You need to read the right documentation (attachfile2/embedfile): "The PDF format ([3]) allows the inclusion of fies inside the PDF document. The included fies can be bound to an annotation on a page. Or they can be recorded in a sorted list of embedded fies. The packages attachfie or attachfie2 follow the fist approach, package embedfie uses the latter method." Of course that does not explain the technical details, but it gives the right hint.
          – TeXnician
          Aug 20 at 11:22





          @lucidbrot You need to read the right documentation (attachfile2/embedfile): "The PDF format ([3]) allows the inclusion of fies inside the PDF document. The included fies can be bound to an annotation on a page. Or they can be recorded in a sorted list of embedded fies. The packages attachfie or attachfie2 follow the fist approach, package embedfie uses the latter method." Of course that does not explain the technical details, but it gives the right hint.
          – TeXnician
          Aug 20 at 11:22













          Yes this is quite cool. Unfortunately not all PDF readers can handle it, e.g. I tried to open with firefox builtin reader and no action took place. But with other readers I had success, very neat. Thank all of you so much.
          – math
          Aug 20 at 11:38




          Yes this is quite cool. Unfortunately not all PDF readers can handle it, e.g. I tried to open with firefox builtin reader and no action took place. But with other readers I had success, very neat. Thank all of you so much.
          – math
          Aug 20 at 11:38




          1




          1




          @lucidbrot If I remember correctly you'll find the PDF specification online which should contain these details. Concerning the linking I think they are quite equivalent.
          – TeXnician
          Aug 20 at 12:17




          @lucidbrot If I remember correctly you'll find the PDF specification online which should contain these details. Concerning the linking I think they are quite equivalent.
          – TeXnician
          Aug 20 at 12:17












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f446779%2fhow-to-embedded-source-code-on-demand-into-pdf%23new-answer', 'question_page');

          );

          Post as a guest













































































          這個網誌中的熱門文章

          How to combine Bézier curves to a surface?

          Why am i infinitely getting the same tweet with the Twitter Search API?

          Is there any way to eliminate the singular point to solve this integral by hand or by approximations?