Debian Codegraph @

texmf-dist/source/latex/intopdf/intopdf.dtx

raw
1 % \iffalse meta-comment
2 %
3 %% Copyright (C) 2020 by Marcel Krueger
4 %%
5 %% This file may be distributed and/or modified under the
6 %% conditions of the LaTeX Project Public License, either
7 %% version 1.3c of this license or (at your option) any later
8 %% version. The latest version of this license is in:
9 %%
10 %% http://www.latex-project.org/lppl.txt
11 %%
12 %% and version 1.3 or later is part of all distributions of
13 %% LaTeX version 2005/12/01 or later.
14 %
15 %<*batch>
16 %<*gobble>
17 \ifx\jobname\relax\let\documentclass\undefined\fi
18 \ifx\documentclass\undefined
19 \csname fi\endcsname
20 %</gobble>
21 \input l3docstrip.tex
22 \keepsilent
23 \preamble
24 \endpreamble
25 \generate{\file{intopdf.sty}{\from{intopdf.dtx}{package}}}
26 \endbatchfile
27 %</batch>
28 %<*gobble>
29 \fi
30 \expandafter\ifx\csname @currname\endcsname\empty
31 \csname fi\endcsname
32 %</gobble>
33 %<*driver>
34 \documentclass[full]{l3doc}
35 \usepackage{intopdf,metalogo}
36 \begin{document}
37 \DocInput{intopdf.dtx}
38 \clearpage
39 \PrintIndex
40 \PrintChanges
41 \end{document}
42 %</driver>
43 %<*gobble>
44 \fi
45 %</gobble>
46 % \fi
47 %
48 % \GetFileInfo{intopdf.dtx}
49 % \title{The \pkg{intopdf} package\thanks{This document
50 % corresponds to \pkg{intopdf}~0.4.1, dated~2022/07/21.}}
51 % \author{Marcel Kr\"uger \\ \href{mailto:[email protected]}{[email protected]}}
52 %
53 % \maketitle
54 %
55 % \begin{documentation}
56 % This package defines a command \cmd\attachandlink{} which allows to attach an arbitrary file to your PDF document and linking to it from the main text.
57 % It is inspired by the \TeX Stack Exchange question \href{https://tex.stackexchange.com/questions/418606/embed-non-pdf-files-e-g-bibtex-into-pdf-with-hyperlink-in-the-pdf/418827#418827}{Embed non-PDF files (e.g., BibTex) into PDF with hyperlink in the PDF}.
58 %
59 % \section{Usage}
60 % \begin{function}{\attachandlink}
61 % \begin{syntax}
62 % |\attachandlink| [\meta{filespec}]\Arg{filename}[\meta{mime-type}]\Arg{Description}\Arg{link text}
63 % \end{syntax}
64 % The text \meta{link text} is inserted, linking to the file \meta{filename} which is attached to the document.
65 %
66 % \meta{Description} should be a description of the file and will be shown by the PDF viewer in the atttached files section and sometimes in a mouseover tooltip.\\
67 % \meta{mime-type} should be the MIME-Type of \meta{filename}. Currently \meta{mime-type} is mandatory but I hope to make it optional in a later release.
68 % Additionally \meta{filespec} can be used to specify the filename which will be shown in the PDF viewer.
69 % If this is not given, it will default to \meta{filename}.
70 % \end{function}
71 % \section{Example}
72 % The source of the document is attached
73 % \attachandlink{intopdf.dtx}[application/x-tex]
74 % {The source of this document}{here}.
75 % \begin{verbatim}
76 % The source of the document is attached
77 % \attachandlink{intopdf.dtx}[application/x-tex]
78 % {The source of this document}{here}.
79 % \end{verbatim}
80 % \end{documentation}
81 % \begin{implementation}
82 % \section{The implementation}
83 % \changes{v0.0.1}{2018/03/13}{Initial version}
84 % \begin{macrocode}
85 %<@@=intopdf>
86 % \end{macrocode}
87 % \iffalse
88 %<*package>
89 \NeedsTeXFormat{LaTeX2e}
90 \RequirePackage{expl3,xparse}
91 \ProvidesExplPackage
92 {intopdf}
93 {2022/07/21}
94 {v0.4.1}
95 {Embed non-PDF files into PDF with hyperlink}
96
97 \RequirePackage{hyperref}
98 %</package>
99 % \fi
100 % \begin{macro}{\attachandlink,\intopdf_attach_link:nnnnn,\intopdf_attach_link:nnnn}
101 % \changes{v0.2.0}{2019/05/21}{Added filespec support. (The first optional argument) Added \cs{intopdf_attach_link:nnnnn}.}
102 % \changes{v0.3.0}{2020/03/13}{Switched to \texttt{l3pdf} instead of using primitives directly. Currently some internal functions from \texttt{l3backend} are needed too for handling links.}
103 % \changes{v0.4.0}{2021/02/26}{Update to new \texttt{l3pdf} names and support more engines.}
104 % \changes{v0.4.1}{2022/07/21}{Properly separate legacy and Unicode filenames}
105 % The main functionality.
106 % \begin{macrocode}
107 \str_new:N \l__intopdf_mime_str
108 \str_new:N \l__intopdf_filename_str
109 \str_new:N \l__intopdf_description_str
110
111 \cs_new_protected:Nn\intopdf_attach_link:nnnnn{
112 \leavevmode
113 \str_set_convert:Nnnn \l__intopdf_mime_str { #3 } { default } { utf8/name }
114 \pdf_object_unnamed_write:nx {fstream} { {
115 /Subtype /\l__intopdf_mime_str
116 } { #2 } }
117 \str_set_convert:Nnnn \l__intopdf_filename_str { #1 } { default } { utf8/string }
118 \str_set_convert:Nnnn \l__intopdf_filename_unicode_str { #1 } { default } { utf16/string }
119 \str_set_convert:Nnnn \l__intopdf_description_str { #4 } { default } { utf16/string }
120 \pdf_object_unnamed_write:nx {dict} {
121 /Type /Filespec
122 /F (\l__intopdf_filename_str)
123 /UF (\l__intopdf_filename_unicode_str)
124 /EF << /F~\pdf_object_ref_last: >>
125 /Desc (\l__intopdf_description_str)
126 }
127 \__pdf_backend_link_begin_user:nnw {
128 \Hy@setpdfborder
129 \tl_if_empty:NF\@pdfhighlight{
130 /H\@pdfhighlight
131 }
132 \cs_if_free:NF\@urlbordercolor{
133 /C[\@urlbordercolor]
134 }
135 }{
136 /Subtype /Link
137 }
138 \__pdf_backend_link_begin_user:nnw { } {
139 /Subtype /FileAttachment
140 /FS~\pdf_object_ref_last:
141 /F~416
142 /CA~0
143 /Contents (\l__intopdf_description_str)
144 }
145 #5
146 \__pdf_backend_link_end:
147 \__pdf_backend_link_end:
148 }
149 \cs_new_protected:Npn \intopdf_attach_link:nnnn #1{
150 \intopdf_attach_link:nnnnn{#1}{#1}
151 }
152 \NewDocumentCommand\attachandlink{O{#2}mr[]mm}{
153 \intopdf_attach_link:nnnnn{#1}{#2}{#3}{#4}{#5}
154 }
155 % \end{macrocode}
156 % \end{macro}
157 % \end{implementation}