summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/docmute/docmute.dtx
blob: cc4a1e0e71becc336c2fd20177ddde2719dc948f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
% \iffalse
%<*internal>
\iffalse
%</internal>
%
%<*license>
Copyright (C) 2009 by T.M. Trzeciak <t34www@googlemail.com>

This work may be distributed and/or modified under the
conditions of the LaTeX Project Public License (LPPL), either
version 1.3c of this license or (at your option) any later
version.  The latest version of this license is in the file:

http://www.latex-project.org/lppl.txt

This work is "maintained" (as per LPPL maintenance status) by
T.M. Trzeciak.

This work consists of the file  docmute.dtx
and the derived files           docmute.ins,
                                docmute.pdf
                                docmute.sty.
%</license>
%
%<*readme>
The docmute package enables to input or include standalone
LaTeX documents as if they consisted of only the content
between \begin{document} and \end{document}.
%</readme>
%
%<*internal>
\fi
\begingroup
%</internal>
%
%<*batchfile>
\input docstrip.tex
\keepsilent\askforoverwritefalse
\nopreamble\nopostamble
\generate{\file{\jobname.sty}{\from{\jobname.dtx}{package}}}
%</batchfile>
%<batchfile>\endbatchfile
%
%<*internal>
\generate{\file{\jobname.ins}{\from{\jobname.dtx}{batchfile}}}
\generate{\file{README.TXT}{\from{\jobname.dtx}{readme}}}
\endgroup
%</internal>
% \fi
%
% \begin{comment}
% 
%<*documentation>
\documentclass{ltxdoc}
\usepackage{verbatim}
\usepackage{docmute}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
%\OnlyDescription
%
\begin{document}

\GetFileInfo{docmute.sty}
\title{The \textsf{docmute} package%
\thanks{This file describes version \fileversion, last revised \filedate.}}
\author{T.\,M. Trzeciak\thanks{E-mail: \texttt{t34www@googlemail.com}}}
\maketitle

\section{Intoduction}

The structure of \LaTeX\ documents doesn't allow one document to be included as a part of another (at least not without some hacking). This package tries to remove this limitation and enable the standard |\input| and |\include| commands to be used on standalone documents just as if they contained no preamble.

\section{Usage}

The package is loaded with the usual |\usepackage{docmute}|. It redefines the |\documentclass| command in such a way that everything between this command and the |\begin{document}| is skipped, as well as everything after the |\end{document}|. No attempts are made to analyse the actual content of the preamble. It is up to you to ensure that the main document loads all packages required by subsidiary documents.

\DescribeMacro{\docmute}
In rare cases some commands might be already present already before the |\documentclass| command. These commands would be then normally executed by the main document. You can prevent that by putting |\csname docmute\endcsname| at the top of the inputted document. The |\docmute| command has the same effect as the redefined |\documentclass|. Executing it through the control sequence forming primitive rather than directly ensures that standalone compilation is still possible.  In that case |\csname docmute\endcsname| will have the same effect as |\relax|.

By default, nesting of inputted documents is not allowed, i.e. inputted documents cannot themselves input other documents. This behaviour can be changed with the package option |nested|. With this option inputted documents are surrounded by a group and nesting becomes possible. Note, that due to grouping only global macro (re)definitions will be visible in the parent document.

\section{Known limitations}

The |\documentclass| and/or |\csname docmute\endcsname| command  has to be in the same file as |\begin{document}|. This is due to employed preamble gobbling method, which relies on scanning for delimited macro arguments and which doesn't work across the file boundaries.

\DocInput{\jobname.dtx}

\end{document}
%</documentation>
%
% \end{comment}
%
% \StopEventually{}
% 
% \section{Implementation}
% 
% \iffalse
%<*package>
% \fi
% 
% Initial boilerplate code.
% 
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{docmute}[2009/10/08 v1.1 Input standalone documents]
%    \end{macrocode}
%    
% Macro used for comparison to see if we already reached 
% |\begin{document}|.
% 
%    \begin{macrocode}
\def\docmute@docenv{document}
%    \end{macrocode}
%    
% The main macro of this package. Grab everything before the 
% |\begin| command and check what argument was passed to it.
% 
%    \begin{macrocode}
\long\def\docmute@gobblepreamble#1\begin#2{% 
  \def\docmute@thisenv{#2}% 
%    \end{macrocode}
%    
% If |\begin{document}| was reached we can stop gobbling, 
% otherwise we continue with tail recursive call.
% 
%    \begin{macrocode}
  \ifx\docmute@thisenv\docmute@docenv
    \docmute@afterpreamble
  \else
    \expandafter\docmute@gobblepreamble
  \fi
}
%    \end{macrocode}
%    
% After gobbling stops, |\enddocument| is redefined to stop 
% input when it's executed. Excess spaces, if any, are taken 
% care of by |\ignorespaces|.
% 
%    \begin{macrocode}
\def\docmute@afterpreamble{% 
  \docmute@atbegindoc
  \def\enddocument{% 
    \docmute@atenddoc
    \aftergroup\ignorespaces
    \endinput
  }% 
  \ignorespaces
}
%    \end{macrocode}
%    
% Save original definitions of |\document| and |\enddocument|
% 
%    \begin{macrocode}
\let\docmute@document=\document
\let\docmute@enddocument=\enddocument
%    \end{macrocode}
%    
% Hooks to implement nesting.
% 
%    \begin{macrocode}
\let\docmute@atbegindoc=\relax
\def\docmute@atenddoc{%
  \let\enddocument=\docmute@enddocument
  \begingroup
}
%    \end{macrocode}
%    
% Define the |\docmute| command
% 
%    \begin{macrocode}
\let\docmute=\docmute@gobblepreamble
%    \end{macrocode}
%    
% Redefine the |\documentclass| command at the beginning of 
% the document. |\AtBeginDocument| happens to early to be used
% for that, so we need to append directly to the |\document|.
% 
%    \begin{macrocode}
\def\document{% 
  \docmute@document
  \let\documentclass=\docmute
  \ignorespaces
}
%    \end{macrocode}
%    
% Finally, handle the only option we have and that's it.
% 
%    \begin{macrocode}
\DeclareOption{nested}{% 
  \let\docmute@atbegindoc=\begingroup
  \let\docmute@atenddoc=\relax
}
\ProcessOptions
\endinput
%    \end{macrocode} 
% \iffalse
%</package>
% \fi
% 
% \Finale