diff options
author | Karl Berry <karl@freefriends.org> | 2019-05-21 21:03:31 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2019-05-21 21:03:31 +0000 |
commit | ae33300b5a7e260971065fd5c13c614351ba3754 (patch) | |
tree | 608a7cdd18b2795bfdb0e8fa769c657d2b93a184 /Master | |
parent | 207abb781e607768591cc5d882990bb7071b2b3a (diff) |
embedall (21may19)
git-svn-id: svn://tug.org/texlive/trunk@51177 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master')
-rw-r--r-- | Master/texmf-dist/doc/latex/embedall/README | 2 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/embedall/embedall.pdf | bin | 154739 -> 235095 bytes | |||
-rw-r--r-- | Master/texmf-dist/source/latex/embedall/embedall.dtx | 385 | ||||
-rw-r--r-- | Master/texmf-dist/source/latex/embedall/embedall.ins | 37 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/embedall/embedall.sty | 170 |
5 files changed, 438 insertions, 156 deletions
diff --git a/Master/texmf-dist/doc/latex/embedall/README b/Master/texmf-dist/doc/latex/embedall/README new file mode 100644 index 00000000000..4ad8f406572 --- /dev/null +++ b/Master/texmf-dist/doc/latex/embedall/README @@ -0,0 +1,2 @@ +This package provides an easy way of storing the main TeX file as an attachment in the output PDF. +The same functionality is provided for several types of content imports like external TeX files, images and listings. diff --git a/Master/texmf-dist/doc/latex/embedall/embedall.pdf b/Master/texmf-dist/doc/latex/embedall/embedall.pdf Binary files differindex c6e2dc259a4..99f6600ee0f 100644 --- a/Master/texmf-dist/doc/latex/embedall/embedall.pdf +++ b/Master/texmf-dist/doc/latex/embedall/embedall.pdf diff --git a/Master/texmf-dist/source/latex/embedall/embedall.dtx b/Master/texmf-dist/source/latex/embedall/embedall.dtx index 763963da21d..99a05c7149d 100644 --- a/Master/texmf-dist/source/latex/embedall/embedall.dtx +++ b/Master/texmf-dist/source/latex/embedall/embedall.dtx @@ -1,54 +1,51 @@ % \iffalse meta-comment % -% Copyright (C) 20013 by Alberto Sartori +% Copyright (C) 2013 by Alberto Sartori +% Copyright (C) 2019 by David Lichti % ------------------------------------------------------- % % This file may be distributed and/or modified under the -% conditions of the LaTeX Project Public License, either version 1.2 -% of this license or (at your option) any later version. -% The latest version of this license is in: +% conditions of the LaTeX Project Public License, either +% version 1.3 of this license or (at your option) any later +% version. The latest version of this license is in: % % http://www.latex-project.org/lppl.txt % -% and version 1.2 or later is part of all distributions of LaTeX -% version 1999/12/01 or later. +% and version 1.3 or later is part of all distributions of +% LaTeX version 2005/12/01 or later. % % \fi % % \iffalse -%<*driver> -\ProvidesFile{embedall.dtx} -%</driver> -%<package>\NeedsTeXFormat{LaTeX2e}[1994/06/01] -%<package>\ProvidesPackage{embedall} -%<*package> - [2013/10/10 v1.0 embed files in pdf] -%</package> +% +%<package>\NeedsTeXFormat{LaTeX2e} +%<package>\ProvidesClass{embedall}[2019/05/18 v2.0 Automatically embed source files in PDF] % %<*driver> \documentclass{ltxdoc} -\usepackage{embedall}[2013/10/10] +\usepackage[notall]{embedall}[2019/05/18] +\usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[osf,sc]{mathpazo} -\usepackage{hyperref} +\usepackage{parskip} \renewcommand\sfdefault{lmsf} \renewcommand\ttdefault{lmtt} \usepackage{microtype} \linespread{1.1} \usepackage{enumitem} \setdescription{font=\itshape,leftmargin=2cm,style=sameline} +\usepackage{hyperref} \EnableCrossrefs \CodelineIndex \RecordChanges \begin{document} \DocInput{embedall.dtx} - %\PrintChanges - %\PrintIndex \end{document} %</driver> +% % \fi % -% \CheckSum{74} +% \CheckSum{154} % % \CharacterTable % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z @@ -67,123 +64,343 @@ % Right brace \} Tilde \~} % % \changes{v1.0}{2013/10/10}{Initial version} +% \changes{v2.0}{2019/05/18}{Overhaul using filehook package} % -% \GetFileInfo{embedall.dtx} +% \GetFileInfo{embedall.sty} % % \DoNotIndex{\newcommand,\def,\let,\DeclareRobustCommand} +% \DoNotIndex{\newif,\DeclareOption,\ProcessOptions,\relax,\RequirePackage,\fi,\else,\ifcsname,\endcsname,\PackageWarning,\^\^} +% \DoNotIndex{\AtBeginDocument,\IfFileExists,\input,\jobname,\LetLtxMacro,\listxadd,\message,\newlinechar,\xifinlist} +% \DoNotIndex{\embedfile,\currfilename,\AtBeginOfInputs,\AtBeginOfIncludes} +% \DoNotIndex{\Gin@setfile} +% \DoNotIndex{\csvloop,\csv@input@filename} % % \title{The \textbf{embedall} package\thanks{This document % corresponds to \textsf{embedall}~\fileversion, dated \filedate.}} -% \author{Alberto Sartori \\ \texttt{\href{mailto:alberto.sartori.as@gmail.com}{alberto.sartori.as@gmail.com}}} +% \author{ +% Alberto Sartori -- \texttt{\href{mailto:alberto.sartori.as@gmail.com}{alberto.sartori.as@gmail.com}}\\ +% David Lichti -- \texttt{\href{mailto:dlichtistw@gmx.de}{dlichtistw@gmx.de}} +% } % % \maketitle % +% \embedsource[desc=main source file] +% % \section{Introduction} % -% This package is designed to help you storing your projects without losing anything. It uses the |embedfile| package in order to attach to the generated |pdf| file all files used in creating your project. In particular it can embed images, external |tex| files, external codes and most important the source file itself. +% This package is designed to help you storing your projects without losing anything. +% It uses the |filehook| package and some custom patches to hook into several supported import mechanisms. +% These imported files are then attached to the PDF file using the |embedfile| package. +% In particular it can embed images, external TeX files, external code listings, CSV files, and, most importantly, the main TeX file itself. +% +% \section{Usage} +% +% To use the package, simply add |\usepackage{embedsources}| to your document's preamble. +% Without any option, the default behaviour is to attach all supported source file types to the finished document. +% See section~\ref{sec:PackageOptions} for options to change this behaviour. +% No furhter macros are needed, and no change has to be made to the rest of the source. +% +% As of now, this package can hook into |\input| and |\include| using the |filehook| package. +% Furthermore, two hooks for |graphicx| and |csvsimple| are provided. % -% \section{Options} +% \subsection{Package Options}\label{sec:PackageOptions} % -% If you use this package without specifying any option, |embedall| attaches by default all files it can. If you don't want to do so you have to use one (or more than one) of the following options. Every option attaches the files it refers to: +% If the package is loaded without any option, then all hooks are installed. +% In case this is not wanted, each hook can be enabled individually. % \begin{description} -% \item[graphicx] images included with the |\includegraphics| command of the |graphicx| package -% \item[listings] external codes included with |\listinputlisting| command of the |listings| package -% \item[source] the main source |tex| file +% \item[|main|] Attach the main source file. +% This uses the |\AtBeginDocument| hook. +% \item[|input|] Attach files loaded with |\input|. +% This is done using |\AtBeginOfInputs| from the |filehook| package. +% It also applies to every macro relying on |\input| to load external content. +% \item[|include|] Attach files loaded with |\include|. +% This is done using the |\AtBeginOfIncludes| hook. +% \item[|graphicx|] Attach image files used with |\includegraphics|. +% This patches some macro in the |graphicx| package, so make sure that it is loaded prior to |embedsources|. +% \item[|csvsimple|] Attach data files used with the |csvsimple| package. +% Make sure that it is already loaded. % \end{description} -% Note that the |embedall| package imports the |graphicx| and |listings| packages without any options so if you want to specify some options you have to do it before |\usepackage{embedall}| either with |\usepackage|\oarg{options}|{graphicx}| or with |\PassOptionsToPackage|\marg{options}|{graphicx}| (the same for |listings|). +% Specifying any of these options will disable all hooks that are not enabled explicitly. % -% \section{Commands} -% \DescribeMacro{\embedinput} \noindent This is the only new command defined by this package. It is the substitute of the |\input| one and it adds the feature of attaching the file to the |pdf| after inserting it in the |tex| source. It was not possible to directly redefine the |\input| command because it is often used by other packages to import their own source code so its redefinition would have the disadvantage of attaching also these files to the final document. +% There are some other options for very special cases. +% \begin{description} +% \item[|all|] Enable all file type hooks. +% This is the default and the option is mostly redundant. +% However, it may be used to reenable all hooks, after an explicit type option has disabled them. +% \item[|notall|] Do not enable all file type hooks. +% As for the the |all| option, this is mostly useless, since it disables all effects this package was intended for. +% However, some side effects may remain. +% Consider not loading the package at all. +% \item[|compat|] Enable compatibility mode to maintain some functionality from version 1.0. +% Use this if your document needs the old style |\embedinput| macro. +%\end{description} +% +% \subsection{User Commands} +% +% \DescribeMacro{\embedfile \oarg{options} \marg{filename}} +% Although not defined by this package, it is made available by loading |embedfile|. +% You may use it to manually embed sources or any file, that is not covered by the hooks described above. +% See the |embedfile| documentation for more details. +% +% \DescribeMacro{\embedsource \oarg{options}} +% This macro can be used to embed the current TeX file in case the automatic hook has been disabled. +% Use it inside the file to be loaded. +% The \meta{options} are passed to the |\embedfile| macro. % +% \DescribeMacro{\embedinput \oarg{options} \marg{filename}} +% This command is a substitute for |\input{<filename>}| in compatibility mode. +% It adds the feature of attaching the file to the PDF after inserting it in the TeX source. +% The \meta{options} are ultimately passed to the |\embedfile| macro. +% As of version 2.0 with the automatic input file hook enabled, this is not needed anymore. +% Consider using |\embedsource| for manual embedding without the automatic hook. +% +% \section{Compatibility} +% +% This package heavily relies on |filehook|'s\footnote{filehook package: \url{https://ctan.org/pkg/filehook}} file hooks and |embedfile|'s\footnote{embedfile package: \url{https://ctan.org/pkg/embedfile}} file embedding. +% See the compatibility notes in their respective documentations. +% +% Furthermore, hooking into the |graphicx| and |csvsimple| macros is done by patching some of their macros. +% If they have not been loaded when |embedall| is loaded, this will fail. +% If they are loaded or reloaded after |embedall|, these patches may be overwritten. +% To ensure good functionality, load this package after all packages providing import commands. +% % \StopEventually{} % % \section{Implementation} % -% Initial operations: declaration of packages, commands and options. +% \subsection{Options} +% +% First, we need some booleans to store package options. +% The switch |embedall@all| acts on all types of hooks. +% \begin{macrocode} +\newif\ifembedall@all +\embedall@alltrue +% \end{macrocode} +% The following |embedall@<hook>| can be used to enable specific embedding hooks. +% \begin{macrocode} +\newif\ifembedall@main +\embedall@mainfalse +\newif\ifembedall@input +\embedall@inputfalse +\newif\ifembedall@include +\embedall@includefalse +\newif\ifembedall@graphicx +\embedall@graphicxfalse +\newif\ifembedall@csvsimple +\embedall@csvsimplefalse +% \end{macrocode} +% Compatibility mode is disabled by default. +% \begin{macrocode} +\newif\ifembedall@compat +\embedall@compatfalse +% \end{macrocode} +% +% Now, declare the actual package options. +% \begin{macrocode} +\DeclareOption{all}{\embedall@alltrue} +\DeclareOption{notall}{\embedall@allfalse} +% \end{macrocode} +% The following options correspond to the more specific embedding hooks mentioned above. +% Using any of these options will turn of general embedding off all source file types. +% \begin{macrocode} +\DeclareOption{main}{\embedall@maintrue\embedall@allfalse} +\DeclareOption{input}{\embedall@inputtrue\embedall@allfalse} +\DeclareOption{include}{\embedall@includetrue\embedall@allfalse} +\DeclareOption{graphicx}{\embedall@graphicxtrue\embedall@allfalse} +\DeclareOption{csvsimple}{\embedall@csvsimpletrue\embedall@allfalse} +% \end{macrocode} +% Request compatibility mode. +% \begin{macrocode} +\DeclareOption{compat}{\embedall@compattrue} +% \end{macrocode} +% +% Now, process these options. +% \begin{macrocode} +\ProcessOptions\relax +% \end{macrocode} +% +% Turn on all |embedall@<hook>| if |embedall@all| is |true|. +% \begin{macrocode} +\ifembedall@all + \embedall@maintrue + \embedall@inputtrue + \embedall@includetrue + \embedall@graphicxtrue + \embedall@csvsimpletrue +\fi +% \end{macrocode} +% +% \subsection{Dependencies} +% +% Load packages for file embedding and file hooks. % \begin{macrocode} - \RequirePackage{embedfile} -\RequirePackage{graphicx} -\RequirePackage{listings} -\RequirePackage{letltxmacro} - -\newcommand\embedall@all{1} -\newcommand\embedall@graphicx{0} -\newcommand\embedall@list{0} -\newcommand\embedall@source{0} - -\DeclareOption{graphicx}{\def\embedall@graphicx{1}\def\embedall@all{0}} -\DeclareOption{listings}{\def\embedall@list{1}\def\embedall@all{0}} -\DeclareOption{source}{\def\embedall@source{1}\def\embedall@all{0}} - -\ProcessOptions - +\RequirePackage{filehook} +\RequirePackage{currfile} +\RequirePackage{etoolbox} +\ifembedall@compat + \RequirePackage{letltxmacro} +\fi +% \end{macrocode} +% +% \subsection{Macros} +% +% \begin{macro}{\embedsource} +% We define a shorthand to embed the current source file. +% \begin{macrocode} +\newcommand\embedsource[1][]{\embedall@embed[#1]{\currfilename}} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\embedall@filelist} +% Keep a list of files that have already been attached. +% \begin{macrocode} +\def\embedall@filelist{} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\embedall@embed} +% This is done to avoid embedding the same file multiple times. +% \begin{macrocode} +\newcommand{\embedall@embed}[2][]{% + \xifinlist{#2}{\embedall@filelist}{}{% + \newlinechar=`\^^J% + \message{^^J^^Jembedall: Attaching file '#2'.^^J^^J}% + \embedfile[#1]{#2}% + \listxadd{\embedall@filelist}{#2}% + }% +} +% \end{macrocode} +% \end{macro} +% +% \subsection{Compatibility Commands} +% +% The following macros are only defined in compatibility mode to maintain backward compatibility. +% \begin{macrocode} +\ifembedall@compat % \end{macrocode} +% % \begin{macro}{\embedall@includegraphics} -% This macro is the modified version of |\includegraphics| command from the |graphicx| package with included the |\embedfile| command. First the original |\includegraphics| command is stored inside the not-user-accessible |\embedall@latex@includegraphics|. +% This macro is the modified version of |\includegraphics| command from the |graphicx| package with included the |\embedfile| command. +% First the original |\includegraphics| command is stored inside the not-user-accessible |\embedall@latex@includegraphics|. % \begin{macrocode} -\LetLtxMacro\embedall@latex@includegraphics\includegraphics + \LetLtxMacro\embedall@latex@includegraphics\includegraphics % \end{macrocode} -% |\LetLtxMacro| is used (instead of simply |\let|) because some packages modify the |\includegraphics| command. For this reason you can not use the * variant of this command but you have to declare the |clip| option instead. +% |\LetLtxMacro| is used (instead of simply |\let|) because some packages modify the |\includegraphics| command. +% For this reason you can not use the * variant of this command but you have to declare the |clip| option instead. % % Then the |\embedall@includegraphics| is defined % \begin{macrocode} -\newcommand\embedall@includegraphics[2][]{% - \embedfile[desc=image]{#2} - \embedall@latex@includegraphics[#1]{#2}% -} - + \newcommand\embedall@includegraphics[2][]{% + \embedall@embed[desc=image]{#2} + \embedall@latex@includegraphics[#1]{#2}% + } % \end{macrocode} % \end{macro} % % \begin{macro}{\embedall@listinputlisting} -% This macro is the modified version of |\listinputlisting| command from the |listings| package with included the |\embedfile| command. First the original |\listinputlisting| command is stored inside the not-user-accessible |\embedall@latex@listinputlisting|. +% This macro is the modified version of |\listinputlisting| command from the |listings| package with included the |\embedfile| command. +% First the original |\listinputlisting| command is stored inside the not-user-accessible |\embedall@latex@listinputlisting|. % \begin{macrocode} -\LetLtxMacro\embedall@latex@lstinputlisting\lstinputlisting + \LetLtxMacro\embedall@latex@lstinputlisting\lstinputlisting % \end{macrocode} % Then the |\embedall@listinputlisting| is defined % \begin{macrocode} -\newcommand\embedall@lstinputlisting[2][]{% - \embedfile[desc=listing file]{#2} - \embedall@latex@lstinputlisting[#1]{#2}% -} - + \newcommand\embedall@lstinputlisting[2][]{% + \embedfile[desc=listing file]{#2} + \embedall@latex@lstinputlisting[#1]{#2}% + } % \end{macrocode} % \end{macro} % % \begin{macro}{\embedinput} -% This command substitute the |\input| one, the added optional option gives the input file -% description in the generated pdf. +% This command can be used as a substitute for |\input| to manually embed the source if the automatic file hook is not enabled. +% Otherwise, it will just call |\input| without further side effects. +% The additional optional parameter sets the input file description in the generated PDF. % \begin{macrocode} -\DeclareRobustCommand\embedinput[2][input file]{% - \input{#2}% - \embedfile[desc={#1}]{#2}% -} - + \ifembedall@input + \DeclareRobustCommand\embedinput[2][]{% + \input{#2}% + } + \else + \DeclareRobustCommand\embedinput[2][input file]{% + \input{#2}% + \embedall@embed[desc={#1}]{#2}% + } + \fi +\fi % \end{macrocode} % \end{macro} % -% \noindent Finally options are processed +% \subsection{Installing Hooks} +% +% The actual work happens here. +% First, the main source file is attached. % \begin{macrocode} -\ifnum\embedall@all=1% - \def\embedall@graphicx{1} - \def\embedall@list{1} - \def\embedall@source{1} +\ifembedall@main + \ifembedall@compat + \IfFileExists{./\jobname.tex}{% + \embedall@embed[desc=main source file]{\jobname.tex} + }{} + \else + \AtBeginDocument{\embedsource[desc=main source file]} + \fi \fi -\ifnum\embedall@graphicx=1% - \LetLtxMacro\includegraphics\embedall@includegraphics +% \end{macrocode} +% These macros are provided by the |embedfile| and |currfile| packages. +% +% Then, the hooks for |\input| and |\include| are installed, given the respective switch was enabled. +% \begin{macrocode} +\ifembedall@input + \AtBeginOfInputs{\embedsource[desc=input file]} \fi -\ifnum\embedall@list=1% - \LetLtxMacro\lstinputlisting\embedall@lstinputlisting +\ifembedall@include + \AtBeginOfIncludes{\embedsource[desc=include file]} \fi - % \end{macrocode} -% and the complete tex source file is also included if the |source| option is present. +% The macros |\AtBeginOfInputs| and |\AtBeginOfIncludes| are provided by the |filehook| package. +% +% For the |graphicx| hook, we need to patch the |\Gin@setfile| macro to call |\embedfile| after finishing its own work. +% At this point, the full file name including the file name extension will be available as the third argument passed to the macro. % \begin{macrocode} -\IfFileExists{./\jobname.tex}{% - \ifnum\embedall@source=1% - \embedfile[desc=main source file]{\jobname.tex}\fi}{} +\ifembedall@graphicx + \ifcsname Gin@setfile\endcsname + \let\embedall@Gin@setfile\Gin@setfile + \def\Gin@setfile#1#2#3{% + \embedall@Gin@setfile{#1}{#2}{#3}% + \embedall@embed[image file]{#3}% + } % \end{macrocode} +% Issue a warning if |\Gin@setfile| does not exists. +% This could happen in the unlikely case that the internal workings of |graphicx| have changed, or, more likely, because the package was not loaded. +% \begin{macrocode} + \else + \ifembedall@all\else + \PackageWarning{embedall}{Patching of graphicx requested, but package not loaded. Consider removing the 'graphicx' option.} + \fi + \fi +\fi +% \end{macrocode} +% +% The |csvsimple| hook is very similar to the |graphicx| hook. +% It patches into the |\csvloop| macro which is used by all other user macros to do the actual work. +% \begin{macrocode} +\ifembedall@csvsimple + \ifcsname csvloop\endcsname + \let\embedall@csvloop\csvloop + \def\csvloop#1{% + \embedall@csvloop{#1}% + \embedall@embed[CSV file]{\csv@input@filename}% + } + \else + \ifembedall@all\else + \PackageWarning{embedall}{Patching of csvsimple requested explicitly, but package not loaded. Consider removing the 'csvsimple' option.} + \fi + \fi +\fi +% \end{macrocode} +% The |\csv@input@filename| macro is used in the |csvsimple| macro to store the input file name. +% % \Finale - +% \endinput diff --git a/Master/texmf-dist/source/latex/embedall/embedall.ins b/Master/texmf-dist/source/latex/embedall/embedall.ins index 6ee3a3b3f41..7adebf85b06 100644 --- a/Master/texmf-dist/source/latex/embedall/embedall.ins +++ b/Master/texmf-dist/source/latex/embedall/embedall.ins @@ -1,37 +1,40 @@ %% %% Copyright (C) 2013 by Alberto Sartori +%% Copyright (C) 2019 by David Lichti +%% +%% This file may be distributed and/or modified under the +%% conditions of the LaTeX Project Public License, either +%% version 1.3 of this license or (at your option) any later +%% version. The latest version of this license is in: %% -%% This file may be distributed and/or modified under the conditions of -%% the LaTeX Project Public License, either version 1.2 of this license -%% or (at your option) any later version. The latest version of this -%% license is in: -%% %% http://www.latex-project.org/lppl.txt -%% -%% and version 1.2 or later is part of all distributions of LaTeX version -%% 1999/12/01 or later. %% +%% and version 1.3 or later is part of all distributions of +%% LaTeX version 2005/12/01 or later. +%% + +\input{docstrip.tex} -\input docstrip.tex \keepsilent -\usedir{tex/latex/skeleton} +\usedir{tex/latex/embedall} \preamble This is a generated file. Copyright (C) 2013 by Alberto Sartori +Copyright (C) 2019 by David Lichti -This file may be distributed and/or modified under the conditions of -the LaTeX Project Public License, either version 1.2 of this license -or (at your option) any later version. The latest version of this -license is in: +This file may be distributed and/or modified under the +conditions of the LaTeX Project Public License, either +version 1.3 of this license or (at your option) any later +version. The latest version of this license is in: - http://www.latex-project.org/lppl.txt +http://www.latex-project.org/lppl.txt -and version 1.2 or later is part of all distributions of LaTeX version -1999/12/01 or later. +and version 1.3 or later is part of all distributions of +LaTeX version 2005/12/01 or later. \endpreamble diff --git a/Master/texmf-dist/tex/latex/embedall/embedall.sty b/Master/texmf-dist/tex/latex/embedall/embedall.sty index f5ff6313f09..ae34ada4047 100644 --- a/Master/texmf-dist/tex/latex/embedall/embedall.sty +++ b/Master/texmf-dist/tex/latex/embedall/embedall.sty @@ -9,70 +9,130 @@ %% This is a generated file. %% %% Copyright (C) 2013 by Alberto Sartori +%% Copyright (C) 2019 by David Lichti %% -%% This file may be distributed and/or modified under the conditions of -%% the LaTeX Project Public License, either version 1.2 of this license -%% or (at your option) any later version. The latest version of this -%% license is in: +%% This file may be distributed and/or modified under the +%% conditions of the LaTeX Project Public License, either +%% version 1.3 of this license or (at your option) any later +%% version. The latest version of this license is in: %% -%% http://www.latex-project.org/lppl.txt +%% http://www.latex-project.org/lppl.txt %% -%% and version 1.2 or later is part of all distributions of LaTeX version -%% 1999/12/01 or later. +%% and version 1.3 or later is part of all distributions of +%% LaTeX version 2005/12/01 or later. %% -\NeedsTeXFormat{LaTeX2e}[1994/06/01] -\ProvidesPackage{embedall} - [2013/10/10 v1.0 embed files in pdf] - +\NeedsTeXFormat{LaTeX2e} +\ProvidesClass{embedall}[2019/05/18 v2.0 Automatically embed source files in PDF] +\newif\ifembedall@all +\embedall@alltrue +\newif\ifembedall@main +\embedall@mainfalse +\newif\ifembedall@input +\embedall@inputfalse +\newif\ifembedall@include +\embedall@includefalse +\newif\ifembedall@graphicx +\embedall@graphicxfalse +\newif\ifembedall@csvsimple +\embedall@csvsimplefalse +\newif\ifembedall@compat +\embedall@compatfalse +\DeclareOption{all}{\embedall@alltrue} +\DeclareOption{notall}{\embedall@allfalse} +\DeclareOption{main}{\embedall@maintrue\embedall@allfalse} +\DeclareOption{input}{\embedall@inputtrue\embedall@allfalse} +\DeclareOption{include}{\embedall@includetrue\embedall@allfalse} +\DeclareOption{graphicx}{\embedall@graphicxtrue\embedall@allfalse} +\DeclareOption{csvsimple}{\embedall@csvsimpletrue\embedall@allfalse} +\DeclareOption{compat}{\embedall@compattrue} +\ProcessOptions\relax +\ifembedall@all + \embedall@maintrue + \embedall@inputtrue + \embedall@includetrue + \embedall@graphicxtrue + \embedall@csvsimpletrue +\fi \RequirePackage{embedfile} -\RequirePackage{graphicx} -\RequirePackage{listings} -\RequirePackage{letltxmacro} - -\newcommand\embedall@all{1} -\newcommand\embedall@graphicx{0} -\newcommand\embedall@list{0} -\newcommand\embedall@source{0} - -\DeclareOption{graphicx}{\def\embedall@graphicx{1}\def\embedall@all{0}} -\DeclareOption{listings}{\def\embedall@list{1}\def\embedall@all{0}} -\DeclareOption{source}{\def\embedall@source{1}\def\embedall@all{0}} - -\ProcessOptions - -\LetLtxMacro\embedall@latex@includegraphics\includegraphics -\newcommand\embedall@includegraphics[2][]{% - \embedfile[desc=image]{#2} - \embedall@latex@includegraphics[#1]{#2}% -} - -\LetLtxMacro\embedall@latex@lstinputlisting\lstinputlisting -\newcommand\embedall@lstinputlisting[2][]{% - \embedfile[desc=listing file]{#2} - \embedall@latex@lstinputlisting[#1]{#2}% -} - -\DeclareRobustCommand\embedinput[2][input file]{% - \input{#2}% - \embedfile[desc={#1}]{#2}% +\RequirePackage{filehook} +\RequirePackage{currfile} +\RequirePackage{etoolbox} +\ifembedall@compat + \RequirePackage{letltxmacro} +\fi +\newcommand\embedsource[1][]{\embedall@embed[#1]{\currfilename}} +\def\embedall@filelist{} +\newcommand{\embedall@embed}[2][]{% + \xifinlist{#2}{\embedall@filelist}{}{% + \newlinechar=`\^^J% + \message{^^J^^Jembedall: Attaching file '#2'.^^J^^J}% + \embedfile[#1]{#2}% + \listxadd{\embedall@filelist}{#2}% + }% } - -\ifnum\embedall@all=1% - \def\embedall@graphicx{1} - \def\embedall@list{1} - \def\embedall@source{1} +\ifembedall@compat + \LetLtxMacro\embedall@latex@includegraphics\includegraphics + \newcommand\embedall@includegraphics[2][]{% + \embedall@embed[desc=image]{#2} + \embedall@latex@includegraphics[#1]{#2}% + } + \LetLtxMacro\embedall@latex@lstinputlisting\lstinputlisting + \newcommand\embedall@lstinputlisting[2][]{% + \embedfile[desc=listing file]{#2} + \embedall@latex@lstinputlisting[#1]{#2}% + } + \ifembedall@input + \DeclareRobustCommand\embedinput[2][]{% + \input{#2}% + } + \else + \DeclareRobustCommand\embedinput[2][input file]{% + \input{#2}% + \embedall@embed[desc={#1}]{#2}% + } + \fi +\fi +\ifembedall@main + \ifembedall@compat + \IfFileExists{./\jobname.tex}{% + \embedall@embed[desc=main source file]{\jobname.tex} + }{} + \else + \AtBeginDocument{\embedsource[desc=main source file]} + \fi +\fi +\ifembedall@input + \AtBeginOfInputs{\embedsource[desc=input file]} +\fi +\ifembedall@include + \AtBeginOfIncludes{\embedsource[desc=include file]} \fi -\ifnum\embedall@graphicx=1% - \LetLtxMacro\includegraphics\embedall@includegraphics +\ifembedall@graphicx + \ifcsname Gin@setfile\endcsname + \let\embedall@Gin@setfile\Gin@setfile + \def\Gin@setfile#1#2#3{% + \embedall@Gin@setfile{#1}{#2}{#3}% + \embedall@embed[image file]{#3}% + } + \else + \ifembedall@all\else + \PackageWarning{embedall}{Patching of graphicx requested, but package not loaded. Consider removing the 'graphicx' option.} + \fi + \fi \fi -\ifnum\embedall@list=1% - \LetLtxMacro\lstinputlisting\embedall@lstinputlisting +\ifembedall@csvsimple + \ifcsname csvloop\endcsname + \let\embedall@csvloop\csvloop + \def\csvloop#1{% + \embedall@csvloop{#1}% + \embedall@embed[CSV file]{\csv@input@filename}% + } + \else + \ifembedall@all\else + \PackageWarning{embedall}{Patching of csvsimple requested explicitly, but package not loaded. Consider removing the 'csvsimple' option.} + \fi + \fi \fi - -\IfFileExists{./\jobname.tex}{% - \ifnum\embedall@source=1% - \embedfile[desc=main source file]{\jobname.tex}\fi}{} - \endinput %% %% End of file `embedall.sty'. |