summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/ltxtools/ltxtools-incluput.sty
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/ltxtools/ltxtools-incluput.sty')
-rw-r--r--macros/latex/contrib/ltxtools/ltxtools-incluput.sty193
1 files changed, 193 insertions, 0 deletions
diff --git a/macros/latex/contrib/ltxtools/ltxtools-incluput.sty b/macros/latex/contrib/ltxtools/ltxtools-incluput.sty
new file mode 100644
index 0000000000..b7262a4979
--- /dev/null
+++ b/macros/latex/contrib/ltxtools/ltxtools-incluput.sty
@@ -0,0 +1,193 @@
+%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
+% This is file ltxtools-incluput.sty, version 0.0.1, December 2011. %
+% %
+% It can be used to input standalone subsidiary documents without %
+% also including their preamble and/or postamble. Files can be %
+% 'inputted' or 'included'. %
+% %
+% If you enter 'persistent=false' in the call to the package, %
+% you would have to put \let\documentclass\ltxtools-incluput at the top %
+% of every file to be included in the main document, otherwise enter it %
+% only in the first file to be input. %
+% %
+% Use the 'nested' option to input documents that themselves input %
+% other documents. %
+% %
+% This work may be distributed and/or modified under the conditions %
+% of the LaTeX Project Public License, either version 1.3 of this %
+% license or any later version. The latest version of this license %
+% is in http://www.latex-project.org/lppl.txt and version 1.3 or later %
+% is part of all distributions of LaTeX version 2005/12/01 or later. %
+% %
+% Copyright (c) 2011 Ahmed Musa (a.musa@rocketmail.com). %
+% %
+%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
+
+\@ifpackageloaded{ltxtools}{%
+ \@ifpackagelater{ltxtools}{2011/12/12}{}{%
+ \@latex@error{Loaded version of ltxtools package is
+ not current}\@ehc
+ }%
+}{%
+ \RequirePackage{ltxtools}[2011/12/12]%
+}
+\@ifpackageloaded{ltxkeys}{%
+ \@ifpackagelater{ltxkeys}{2011/12/12}{}{%
+ \@latex@error{Loaded version of ltxkeys package is
+ not current}\@ehc
+ }%
+}{%
+ \RequirePackage{ltxkeys}[2011/12/12]%
+}
+\UseNormalCatcodes
+\StyleFilePurpose{Input standalone documents (AM)}
+\StyleFileRCSInfo
+$Id: ltxtools-incluput.sty,v 0.0.1 2011/12/12 09:00:00 Ahmed Musa Exp $
+\ProvidesPackage{ltxtools-incluput}[\StyleFileInfo]
+\NeedsTeXFormat{LaTeX2e}[2011/06/27]
+\SetStyleFileMessages[inclp@]{info}{warn}{err}
+\ifx\documentclass\@twoclasseserror\else
+ \inclp@err{Package 'ltxtools-incluput' can't be loaded
+ \MsgBrk outside document preamble}\@ehc
+\fi
+\AfterStartOfDocument{%
+ \ifoneloadedTF{%
+ docmute,standalone,fileimport-filedate
+ }{%
+ \inclp@err{Package 'ltxtools-incluput' can't be used
+ \MsgBrk with package '\ltspkgcls'}\@ehc
+ \expandafter\endinput
+ }%
+ \ifinclp@useincluput
+ \gletcs\documentclass\incluput
+ \incluputtrue
+ \else
+ \incluputfalse
+ \fi
+}
+\cptnewbools{incluput}
+\def\inclp@gobblepreamble{%
+ \begingroup
+ \everyeof{\begin{EOF}\relax}%
+ \inclp@g@bblepreamble
+}
+\long\def\inclp@g@bblepreamble#1\begin#2{%
+ \ifstrcmpTF{#2}{document}{%
+ \endgroup
+ \ifinclp@persistent\else
+ \let\documentclass\@twoclasseserror
+ \fi
+ \inclp@afterpreamble
+ }{%
+ \ifstrcmpTF{#2}{EOF}{%
+ \endgroup\endinput
+ }{%
+ \inclp@g@bblepreamble
+ }%
+ }%
+}
+\let\inclp@document\document
+\let\inclp@enddocument\enddocument
+\let\inclp@afterbegindoc\relax
+\def\inclp@beforeenddoc{%
+ \let\enddocument\inclp@enddocument
+ \ifinclp@persistent\else
+ \incluputfalse
+ \fi
+ \begingroup
+}
+\def\inclp@afterpreamble{%
+ \inclp@afterbegindoc
+ \def\enddocument{%
+ \inclp@beforeenddoc
+ \endinput
+ \aftergroup\ignorespaces
+ }%
+ \ignorespaces
+}
+\newletcs\incluput\inclp@gobblepreamble
+\ltxkeys@boolkey[KV]{incluput}[inclp@]{useincluput}[true]{}
+\ltxkeys@boolkey[KV]{incluput}[inclp@]{persistent}[true]{%
+ \ifinclp@persistent
+ \def\document{%
+ \inclp@document
+ \let\documentclass\incluput
+ }%
+ \fi
+}
+\ltxkeys@boolkey[KV]{incluput}[inclp@]{nested}[true]{%
+ \ifinclp@nested
+ \let\inclp@afterbegindoc\begingroup
+ \let\inclp@beforeenddoc\relax
+ \else
+ \inclp@info{Option 'nested' is false}%
+ \fi
+}
+\ltxkeys@declareoption*{%
+ \inclp@warn{Unknown option '#3' with value '#4' ignored}%
+}
+\ltxkeys@executeoptions[KV]<incluput>{persistent,useincluput=false}
+\ltxkeys@processoptions*[KV]<incluput>\relax
+\providecommand*\input@path{}
+\robust@def*\InputDocument{%
+ \let\inclp@input\@@input
+ \inclp@inputdocument
+}
+\robust@def*\IncludeDocument{%
+ \let\inclp@input\include
+ \inclp@inputdocument
+}
+\robust@def*\inclp@inputdocument{%
+ \ifinclp@persistent\else
+ \inclp@warn{Option 'persistent' is false.\MsgBrk
+ If you don't want to set 'persistent=true',\MsgBrk
+ then you must put '\detokenize{\let\documentclass\incluput}'%
+ \MsgBrk at the top of each document to input,
+ \MsgBrk ie, before the \string\documentclass
+ }%
+ \fi
+ \gletcs\inclp@inputpath\input@path
+ \let\inclp@newgeometry\newgeometry
+ \let\inclp@restoregeometry\restoregeometry
+ \let\newgeometry\@gobble
+ \let\restoregeometry\relax
+ \cpt@teststopt\inclp@inputfile{.}%
+}
+\new@def*\inclp@inputfile[#1]#2{%
+ \ifblankTF{#1}{}{%
+ \edef\input@path{\expandcsonce\input@path{#1/}}%
+ }%
+ \ifboolTF{cpt@st}{%
+ \inclp@inp@tfile{#2}%
+ }{%
+ \ifcsndefTF{#2@readx}{%
+ \inclp@info{File '#2' already read:\MsgBrk
+ File '#2' wasn't read again}%
+ }{%
+ \inclp@inp@tfile{#2}%
+ }%
+ }%
+}
+\new@def*\inclp@inp@tfile#1{%
+ \IfFileExists{#1}{%
+ \inclp@input\@filef@und
+ \letcsntocs{#1@readx}\noboundary
+ \inclp@afterfileinput
+ }{%
+ \typein[\answer]{^^J! File '\string#1' does not exist.
+ ^^JEnter filename or 'x' and <return> to continue.}%
+ \def\reserved@a{x}%
+ \ifxTF\answer\reserved@a{%
+ \inclp@afterfileinput
+ }{%
+ \cptexpandarg{\inclp@inputfile[]}\answer
+ }%
+ }%
+}
+\new@def*\inclp@afterfileinput{%
+ \gletcs\input@path\inclp@inputpath
+ \let\newgeometry\inclp@newgeometry
+ \let\restoregeometry\inclp@restoregeometry
+}
+
+\endinput