% -*- coding: utf-8; time-stamp-format: "%02d-%02m-%:y at %02H:%02M:%02S %Z" -*- % N.B.: this dtx file is NOT for use with \DocInput. The latex source of the % user manual isn't prefixed with percent signs. %<*none> \def\dtxtimestamp {Time-stamp: <19-09-2016 at 11:46:39 CEST>}% % %<*!readme> %% %% Package: filecontentsdef %% Version: 1.2 (2016/09/19) %% License: LPPL 1.3c %% Copyright (C) 2016 Jean-Francois Burnol %% % %<*insfile> \def\pkgname {filecontentsdef} \def\pkgdate {2016/09/19} \def\pkgdocdate {2016/09/19} \def\pkgversion {v1.2} \def\pkgdescription {filecontents + macro + verbatim (JFB)} % %<*none> \iffalse % %<*readme> Source: filecontentsdef.dtx (v1.2 2016/09/19) Author: Jean-Francois Burnol Info: filecontents + macro + verbatim License: LPPL 1.3c Copyright (C) 2016 Jean-Francois Burnol. ABSTRACT ======== This lightweight LaTeX2e package provides two environments called `filecontentsdef` and `filecontentshere`. They are derived from the LaTeX `filecontents` environment as extended by Scott Pakin's [filecontents] [1] package. In addition to the file creation they either store the (verbatim) contents in a macro (`filecontentsdef`) or typeset them (verbatim) on the spot (`filecontentshere`). I developed this to display TeX code verbatim in documentation and simultaneously produce during the LaTeX run the corresponding files in order to embed them in the PDF as _file attachment annotations_ (via the services of Scott Pakin's further package [attachfile] [2].) [1]: http://www.ctan.org/pkg/filecontents "filecontents package" [2]: http://www.ctan.org/pkg/attachfile "attachfile package" INSTALLATION ============ To extract the package (.sty) run etex on the dtx file. To produce the PDF documentation, either: 1. latex (twice) filecontentsdef.dtx, then dvips, then ps2pdf 2. or pdflatex (twice), 3. or latex (twice) then dvipdfmx This will also extract automatically the style file. Installation: filecontentsdef.sty -> TDS:tex/latex/filecontentsdef/filecontentsdef.sty filecontentsdef.dtx -> TDS:source/latex/filecontentsdef/filecontentsdef.dtx filecontentsdef.pdf -> TDS:doc/latex/filecontentsdef/filecontentsdef.pdf README.md -> TDS:doc/latex/filecontentsdef/README.md The other files may be discarded. LICENSE ======= This Work may be distributed and/or modified under the conditions of the LaTeX Project Public License 1.3c. This version of this license is in > and the latest version of this license is in > and version 1.3 or later is part of all distributions of LaTeX version 2005/12/01 or later. The Author of this Work is: - Jean-Francois Burnol `` This Work consists of the main source file filecontentsdef.dtx and the derived files filecontentsdef.sty, filecontentsdef.ins, filecontentsdef.pdf, filecontentsdef.dvi, README.md. CHANGE LOG ========== v1.2 \[2016/09/19\] ------------------- Initial version. % %<*tex>------------------------------------------------------------------------- \chardef\Withdvipdfmx 1 % replace 1 by 0 for using pdflatex \chardef\NoSourceCode 0 % replace 0 by 1 for the doc *without* the source code \NeedsTeXFormat{LaTeX2e} \ProvidesFile {filecontentsdef.tex}[Driver for filecontentsdef documentation]% \PassOptionsToClass {a4paper,fontsize=11pt,oneside}{scrdoc} \PassOptionsToPackage {english}{babel} \input filecontentsdef.dtx %%% Local Variables: %%% mode: latex %%% End: %------------------------------------------------------------------------- %<*insfile>--------------------------------------------------------------------- \input docstrip.tex \askforoverwritefalse \def\pkgpreamble{\defaultpreamble^^J\MetaPrefix^^J% \string\NeedsTeXFormat{LaTeX2e}^^J% \string\ProvidesPackage{filecontentsdef}^^J% \space[\pkgdate\space\pkgversion\space\pkgdescription]}% \generate{\nopreamble\nopostamble \file{README.md}{\from{\pkgname.dtx}{readme}}% \usepostamble\defaultpostamble \file{\pkgname.tex}{\from{\pkgname.dtx}{tex}}% \usepreamble\pkgpreamble \file{\pkgname.sty}{\from{\pkgname.dtx}{package}}}% \catcode32=13\relax% active space \let =\space% \Msg{************************************************************************} \Msg{*} \Msg{* To finish the installation you have to move the following} \Msg{* file into a directory searched by TeX:} \Msg{*} \Msg{* \pkgname.sty} \Msg{*} \Msg{* To produce the documentation run latex twice on file \pkgname.tex} \Msg{* and then run dvipdfmx on \pkgname.dvi.} \Msg{*} \Msg{* Happy TeXing!} \Msg{*} \Msg{************************************************************************} \ifx\numexpr\undefined \Msg{* warning: to get correct utf-8 encoded README.md }% \Msg{* do etex \pkgname.ins and not tex \pkgname.ins }% \Msg{************************************************************************} \fi \endbatchfile %--------------------------------------------------------------------- %<*none>------------------------------------------------------------------------ \fi % \chardef\noetex 0 \ifx\numexpr\undefined\chardef\noetex 1 \fi \ifnum\noetex=1 \chardef\extractfiles 0 % extract files, then stop \else \ifx\ProvidesFile\undefined \chardef\extractfiles 0 % etex etc.. on dtx, only file extraction. \else % latex/pdflatex \ifx\Withdvipdfmx\undefined % latex/pdflatex on dtx \chardef\extractfiles 1 % 1 = extract files and typeset manual, 2 = only typeset \chardef\Withdvipdfmx 1 % 0 = pdflatex or latex+dvips, 1 = dvipdfmx \chardef\NoSourceCode 0 % 0 = include source code, 1 = do not \NeedsTeXFormat {LaTeX2e}% \PassOptionsToClass {a4paper,fontsize=11pt,oneside}{scrdoc}% \PassOptionsToPackage {english}{babel}% \else % latex on tex \chardef\extractfiles 2 % do not extract files, only typeset \fi \ProvidesFile{\pkgname.dtx}% [\pkgname\space source and documentation (\dtxtimestamp)]% \fi \fi \ifnum\extractfiles<2 % extract files \def\MessageDeFin{\newlinechar10 \let\Msg\message \Msg{********************************************************************^^J}% \Msg{*^^J}% \Msg{* To finish the installation you have to move the following^^J}% \Msg{* file into a directory searched by TeX:^^J}% \Msg{*^^J}% \Msg{*\space\space\space\space \pkgname.sty^^J}% \Msg{*^^J}% \Msg{* To produce the documentation with source code included run latex^^J}% \Msg{* twice on file \pkgname.tex and then dvipdfmx on \pkgname.dvi^^J}% \Msg{*^^J}% \Msg{* Happy TeXing!^^J}% \Msg{*^^J}% \Msg{********************************************************************^^J}% }% \begingroup \input docstrip.tex \askforoverwritefalse \def\pkgpreamble{\defaultpreamble^^J\MetaPrefix^^J% \string\NeedsTeXFormat{LaTeX2e}^^J% \string\ProvidesPackage{\pkgname}^^J% \space[\pkgdate\space\pkgversion\space\pkgdescription]}% \generate{\nopreamble\nopostamble \file{README.md}{\from{\pkgname.dtx}{readme}}% \usepostamble\defaultpostamble \file{\pkgname.ins}{\from{\pkgname.dtx}{insfile}}% \file{\pkgname.tex}{\from{\pkgname.dtx}{tex}}% \usepreamble\pkgpreamble \file{\pkgname.sty}{\from{\pkgname.dtx}{package}}}% \endgroup \fi % end of file extraction (from etex/latex/pdflatex run) \ifnum\noetex=1 % warning for README.md \expandafter\def\expandafter\MessageDeFin\expandafter {\MessageDeFin \Msg{* warning: to get correct utf-8 encoded README.md ^^J}% \Msg{* do etex \pkgname.dtx and not tex \pkgname.dtx ^^J}% \Msg{********************************************************************^^J}}% \fi \ifnum\extractfiles=0 % tex/etex/xetex/etc files extracted, stop \MessageDeFin\expandafter\end \fi % From this point on, run is necessarily with e-TeX. % Check if \MessageDeFin got defined, if yes put it at end of run. \ifdefined\MessageDeFin\AtEndDocument{\MessageDeFin}\fi %------------------------------------------------------------------------------- % START OF USER MANUAL TEX SOURCE \documentclass[abstract]{scrdoc} \ifnum\NoSourceCode=1 \OnlyDescription\fi \usepackage{ifpdf} \ifpdf\chardef\Withdvipdfmx 0 \fi \makeatletter \ifnum\Withdvipdfmx=1 \@for\@tempa:=hyperref,bookmark,graphicx,xcolor,pict2e\do {\PassOptionsToPackage{dvipdfmx}\@tempa} % \PassOptionsToPackage{dvipdfm}{geometry} \PassOptionsToPackage{bookmarks=true}{hyperref} \PassOptionsToPackage{dvipdfmx-outline-open}{hyperref} \PassOptionsToPackage{dvipdfmx-outline-open}{bookmark} % \def\pgfsysdriver{pgfsys-dvipdfm.def} \else \PassOptionsToPackage{bookmarks=true}{hyperref} \fi \let\original@check@percent\check@percent \let\check@percent\relax \makeatother \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage[hscale=0.66,vscale=0.75]{geometry} \pagestyle{headings} \def\MacroFont{\ttfamily\small\hyphenchar\font45 \baselineskip11pt\relax} % ATTENTION: (avec doc.sty ou les classes scrdoc ou ltxdoc) % % - l'environnement macrocode se fait avec \macro@font qui est le % \MacroFont du \begin{document}. % % - les environnements verbatim utilisent le \MacroFont courant. % % - \verb utilise un \ttfamily !! et non pas \verbatim@font que l'on % peut customiser. % % - (9 mars 2015) il ne faut PAS commencer des macrocode directement après % un \section, il faut un paragraphe (par exemple un \indent\par) \usepackage{xspace} \usepackage[dvipsnames]{xcolor} \definecolor{joli}{RGB}{225,95,0} \definecolor{JOLI}{RGB}{225,95,0} \newcommand\fcdname{% \texorpdfstring{{\color{joli}\ttfamily\bfseries \pkgname}}{\pkgname}\xspace} \DeclareRobustCommand\csa [1] {{\ttfamily\hyphenchar\font45 \char`\\ #1}} \newcommand\csh[1]{\texorpdfstring{\csa{#1}}{\textbackslash\detokenize{#1}}} \usepackage {babel} % ngerman and english options have been passed to babel \AtBeginDocument {% \renewcommand\partname{Part}% \addto\captionsenglish {\renewcommand\partname{Part}}% } \usepackage[pdfencoding=pdfdoc]{hyperref} \hypersetup{% linktoc=all,% %% bookmarksdepth=3,% breaklinks=true,% colorlinks,% linkcolor=OliveGreen,%RoyalBlue,% urlcolor=RoyalBlue,%OliveGreen,% pdfauthor={Jean-Fran\c cois Burnol},% pdftitle={The \pkgname\space package},% pdfsubject={\pkgdescription},% pdfkeywords={LaTeX, files, verbatim},% pdfstartview=FitH,% pdfpagemode=UseOutlines} \usepackage{bookmark} \usepackage[zerostyle=a,scaled=0.95,straightquotes]{newtxtt} \renewcommand\familydefault\sfdefault \frenchspacing \usepackage{framed} %\usepackage{varioref} %\usepackage{footnotehyper} \usepackage{filecontentsdef} \makeatletter \newcommand\inmarg [1]{\@bsphack \vadjust{\vskip-\dp\strutbox \smash{\hbox to 0pt {\color[named]{PineGreen}\normalfont\small \hsize 2.5cm\rightskip.5cm minus.5cm \hyphenpenalty\z@\exhyphenpenalty\z@ \doublehyphendemerits\z@\baselineskip9pt \hss\vtop{\noindent#1}\kern.25cm }}% \vskip\dp\strutbox }\strut\@esphack} \makeatother \begin{document} \rmfamily \thispagestyle{empty} \bookmark[named=FirstPage,level=1]{Title page} %\ttzfamily {% \normalfont\Large\parindent0pt \parfillskip 0pt\relax \leftskip 2cm plus 1fil \rightskip 2cm plus 1fil The \fcdname package\par } {\centering \textsc{Jean-François Burnol}\par \footnotesize jfbu (at) free (dot) fr\par Package version: \pkgversion\ (\pkgdate); documentation date: \pkgdocdate.\par {From source file \texttt{\pkgname.dtx}. \dtxtimestamp.}\par } \begin{abstract} This lightweight \LaTeX2e package provides environments |filecontentsdef| and |filecontentshere|. They are derived from the \LaTeX\ |filecontents| environment as extended by \textsc{Scott Pakin}'s \href{http://www.ctan.org/pkg/filecontents}{filecontents} package.\footnote{\fcdname works independently from \href{http://www.ctan.org/pkg/filecontents}{filecontents} and does not load it.} In addition to the file creation they either store the (verbatim) contents in a macro (|filecontentsdef|) or typeset them (verbatim) on the spot (|filecontentshere|). I developed this to display \TeX\ code verbatim in documentation and simultaneously produce during the LaTeX run the corresponding files in order to embed them in the PDF as \emph{file attachment annotations} (via the services of \textsc{Scott Pakin}'s further package \href{http://www.ctan.org/pkg/attachfile}{attachfile}.) \end{abstract} \section{Description} The environment\inmarg{|file\-contents\-here|} \begin{verbatim} \begin{filecontentshere}{} ... arbitrary contents ... \end{filecontentshere} \end{verbatim} creates on the fly a file with these contents, and simultaneously it typesets them in a verbatim environment. There is no syntax highlighting whatsoever. \begin{footnotesize} \begin{enumerate} \item The contents are not completely arbitrary, as they may not contain |\end{filecontentshere}| itself...\par \item This uses underneath the |verbatim| environment and this has been tested to be compatible with the standard |verbatim|, with the one from package \href{http://www.ctan.org/pkg/doc}{doc} (classes |ltxdoc.cls|, |scrdoc.cls|) and also with the one from package \href{http://www.ctan.org/pkg/verbatim}{verbatim} (whose mechanism is quite different from the one of the default |verbatim| environment.) \end{enumerate} \end{footnotesize} \medskip The other environment is |filecontentsdef|.\inmarg{|file\-contents\-def|} It has a second mandatory argument, a macro. \begin{verbatim} \begin{filecontentsdef}{}{\macro} ... arbitrary contents ... \end{filecontentsdef} \end{verbatim} It creates the file and rather than typesetting it verbatim simultaneously, it stores its (verbatim) contents in its second argument |\macro|. \begin{enumerate} \item the scope of the macro definition is global, \item |filecontentshere| is a wrapper of the |filecontentsdef| environment using \csa{filecontentsheremacro} as the macro where the contents are stored.\inmarg{\csa{file\-contents\-here\-macro}} This macro can then be reused elsewhere if wanted. \item both environments admit the starred form which does \emph{not} add the usual three comment lines at the top of the written file (those lines are anyhow not typeset by |filecontentshere| nor are they included in the macro by |filecontentsdef|). \end{enumerate} \begin{framed} Please note that |filecontentsdef| basically stores sanitized (i.e. verbatim) tokens in its macro argument |\macro|. If the material consists of \LaTeX\ code, the expansion of the macro will only typeset some \emph{verbatim} rendering of the \LaTeX\ code. \end{framed} \begin{footnotesize} \def\MacroFont{\ttfamily\footnotesize\hyphenchar\font45 \baselineskip\the\baselineskip\relax} Using \eTeX's \csa{scantokens}, one can re-tokenize the macro contents and (here naturally, we are talking about the situation where the macro contains \TeX/\LaTeX\ code): we obtain its ``execution'' via |\scantokens\expandafter{\macro}|. Due to the way |\scantokens| works, this must be done with |\newlinechar| set to |13| (to match the |^^M|'s; see later in this documentation). Example: \begin{verbatim} \begin{filecontentsdef}{\jobname.test}{\macro} \begin{framed} \noindent We have coded this in \LaTeX: both $E=mc^2$ (input as |$E=mc^2$|) and $E=h\nu$ owe much to \textsc{Albert Einstein}. \end{framed} \end{filecontentsdef} {\newlinechar13 \scantokens\expandafter{\macro}} \end{verbatim} \begin{filecontentsdef}{\jobname.test}{\macro} \begin{framed} \noindent We have coded this in \LaTeX: both $E=mc^2$ (input as |$E=mc^2$|) and $E=h\nu$ owe much to \textsc{Albert Einstein}. \end{framed} \end{filecontentsdef} \filecontentsexec\macro Notice\footnote{The absence of indentation at the start of this paragraph is a funny effect due to it immediately following |framed| which itself immediately follows a |verbatim|.} that a space token will generally appear at the end of the expansion, due to |\scantokens|'s way of working. This is an end-of-line space, which we could suppress via |\endlinechar-1\relax| before the |\scantokens|, but that is an option only in the case of single-line contents. If we had written above \verb|\end{framed}%| or |\end{framed}\relax| in our use of |filecontentsdef| this would have prevented |\scantokens| from inserting this final space (naturally in this example the space is issued while \TeX\ is in vertical mode and leaves no trace anyhow).\footnote{for basic information on this issue, see: \url{http://tex.stackexchange.com/questions/117906/use-of-everyeof-and-endlinechar-with-scantokens}} Although \fcdname itself makes no use of \eTeX, it provides as a convenience \csa{filecontentsexec}\inmarg{\csa{file\-contents\-exec}\csa{macro}} which will use |\scantokens| to execute a |\macro| as above (thus assuming it contains legitimate but possibly verbatimized \LaTeX\ code.) Rather than using a group (possibly |\macro| makes some non-global definitions) it issues |\newlinechar10\relax| (as this is the default -- we could have stored and restored current value, but well...) after the |\scantokens|.\par \end{footnotesize} As an example consider the following (with some |utf8| characters among those which are available in |T1|-encoded \TeX-fonts as used by this document with the help of |fontenc| and |inputenc|): \begin{verbatim} \begin{filecontentsdef}{filecontentsdef.license}{\fcdlicense} This Work may be distributed and/or modified under the conditions of the LaTeX Project Public License 1.3c. This version of this license is in > and the latest version of this license is in > and version 1.3 or later is part of all distributions of LaTeX version 2005/12/01 or later. The Author of this Work is: - Jean-François Burnol `` This Work consists of the main source file filecontentsdef.dtx and the derived files filecontentsdef.sty, filecontentsdef.ins, filecontentsdef.pdf, filecontentsdef.dvi, README.md. CHANGE LOG ========== v1.2 \[2016/09/19\] ------------------- Initial version. test: éèàùÉÈÇÀÙÛÎåðñòóôõöœøùúûüýþߟŽ§ \end{filecontentsdef} \end{verbatim} \begin{filecontentsdef}{filecontentsdef.license}{\fcdlicense} This Work may be distributed and/or modified under the conditions of the LaTeX Project Public License 1.3c. This version of this license is in > and the latest version of this license is in > and version 1.3 or later is part of all distributions of LaTeX version 2005/12/01 or later. The Author of this Work is: - Jean-François Burnol `` This Work consists of the main source file filecontentsdef.dtx and the derived files filecontentsdef.sty, filecontentsdef.ins, filecontentsdef.pdf, filecontentsdef.dvi, README.md. CHANGE LOG ========== v1.2 \[2016/09/19\] ------------------- Initial version. test: éèàùÉÈÇÀÙÛÎåðñòóôõöœøùúûüýþߟŽ§ \end{filecontentsdef} The file |filecontentsdef.license| is created with the usual three commentary lines at top of it. And macro \csa{fcdlicense} contains the verbatim material. It can then be expanded anywhere in the document. Here are some relevant details: \begin{enumerate} \item the usual special characters are sanitized like in a verbatim environment, \item spaces become the active character of ascii code |32|, and end of lines are converted into the active character of ascii code |13| (i.e. |^^M|), \item the tabs |CTRL-I| have been converted to active spaces, \item the form feeds |CTRL-L| have been converted to blank lines (|^^M^^M|), \item the characters of ascii code between |128| and |255| have been either given the catcode |letter|, or if they were active (which will be the case with package |inputenc|), they are just inserted in the produced macro as active characters. \end{enumerate} Thus what is needed before inserting \csa{fcdlicense} in the document is to give definitions to the active space and the active |^^M|. \LaTeX\ and \TeX\ both provide \csa{obeyspaces} and \csa{obeylines}. For a true verbatim printout, these are usually not enough because spaces at start of lines will disappear, and multiple empty lines give multiple |\par|'s which collapse into a single one (hence no empty line can be observed in the output). The usual |verbatim| environment uses a special definition of |\par| which prevents the disappearance of empty lines, and for the spaces it has macro \csa{@vobeyspaces} which makes the spaces issue |\leavevmode| so they are not skipped at the start of lines. Let's define: \begin{verbatim} \makeatletter % this redefines active spaces, but does not make spaces active \def\niceactivespaces{\@vobeyspaces\catcode32=10\relax}% \makeatother \begingroup % this redefines active end of lines, but does not make them active \catcode`\^^M\active % \gdef\niceactiveCRs{\def^^M{\leavevmode\par}}% \endgroup % \end{verbatim} Then we can issue something like (the output is not shown): \begin{verbatim} {\setlength{\parindent}{1cm}\niceactivespaces\niceactiveCRs\fcdlicense} \end{verbatim} Notice however this will still allow hyphenation and ligatures, which are usually inhibited in standard |verbatim| (and also we have not switched to the monospace font.) To emulate exactly what a real |verbatim| would give, \fcdname provides \csa{filecontentsprint}\inmarg{\csa{file\-contents\-print}\csa{macro}} which is a command with one mandatory argument whose invocation will produce the same as what \begingroup\makeatletter\def\x{\let\@xverbatim\relax \verbatim \string\begin\string{verbatim\string}\par \par \string\end\string{verbatim\string}\par \endverbatim% \endgroup}\x % % bizarre % % \texttt{\parindent0pt\relax\niceactivespaces\niceactiveCRs\fcdlicense}% % % crée l'indentation il faut faire le \parindent0pt avant ! % % hmm, bon pas envie de regarder ce que fait \texttt % % pour le fun % % {\setlength{\parindent}{11cm}\niceactivespaces\niceactiveCRs\ttfamily\fcdlicense} \noindent would have given.\footnote{This is compatible with \href{http://www.ctan.org/pkg/verbatim}{verbatim.sty}'s |verbatim| and hopefully also with other packages modifiying the way the |verbatim| environment works.} The tokens stored in the macro must be of the type described above. As an illustration, here is the output from |\filecontentsprint\fcdlicense|: \filecontentsprint\fcdlicense \StopEventually{\end{document}} \makeatletter \let\check@percent\original@check@percent \makeatother \small \section{Implementation} \indent % !!!!!!!!!!!!!!!!! Lundi 09 mars 2015 à 09:32:22 \makeatletter \begingroup \topsep\MacrocodeTopsep \trivlist\parskip\z@\item[] \macro@font \leftskip\@totalleftmargin \advance\leftskip\MacroIndent \rightskip\z@ \parindent\z@ \parfillskip\@flushglue \global\@newlistfalse \global\@minipagefalse \ifcodeline@index \everypar{\global\advance\c@CodelineNo\@ne \llap{\theCodelineNo\ \hskip\@totalleftmargin}}% \fi \string\NeedsTeXFormat\string{LaTeX2e\string}[1999/12/01]\par \string\ProvidesPackage\string{\pkgname\string}\par \noindent\space [\pkgdate\space\pkgversion\space\pkgdescription]\par \nointerlineskip \global\@inlabelfalse \endtrivlist \endgroup \makeatother % The catcode hackery next is to avoid to have <*package> to be listed % in the commented source code... % (c) 2012/11/19 jf burnol ;-) \MakePercentIgnore % % \catcode`\<=0 \catcode`\>=11 \catcode`\*=11 \catcode`\/=11 % \let\relax % \def<*package>{\catcode`\<=12 \catcode`\>=12 \catcode`\*=12 \catcode`\/=12} % % %<*package> % Most of % the code is still identical to the one in \textsc{Scott Pakin}'s % \href{http://www.ctan.org/pkg/filecontents}{filecontents} hence to % the original one in \LaTeX's sources. % \begin{macrocode} \begingroup \catcode`\^^M\active% \catcode`\^^L\active\let^^L\relax% \catcode`\^^I\active% \gdef\filec@ntentsdef#1#2{% \let#2\@empty% \openin\@inputcheck#1 % \ifeof\@inputcheck% \@latex@warning@no@line% {Writing file `\@currdir#1'}% \else% \@latex@warning@no@line% {Overwriting file `\@currdir#1'}% \fi% \closein\@inputcheck% \chardef\reserved@c15 % \ch@ck7\reserved@c\write% \immediate\openout\reserved@c#1\relax% \if@tempswa% \immediate\write\reserved@c{% \@percentchar\@percentchar\space% \expandafter\@gobble\string\LaTeX2e file `#1'^^J% \@percentchar\@percentchar\space generated by the % `\@currenvir' \expandafter\@gobblefour\string\newenvironment^^J% \@percentchar\@percentchar\space from source `\jobname' on % \number\year/\two@digits\month/\two@digits\day.^^J% \@percentchar\@percentchar}% \fi% \let\do\@makeother\dospecials% % \end{macrocode} % SP's |filecontents| sets here in the loop all catcodes to |11|, but we % need for correct rendering in verbatim that the constructed macro % stores active characters as active characters. % % We don't check for unusual active characters of ascii code |<128| % as this is not done by original or SP's |filecontents|. But if % present then they will expand similarly both in the |\write| and % in the construction of the macro. % \begin{macrocode} \count@=128\relax% \loop% \ifnum\catcode\count@=\active% \lccode`~\count@% \lowercase{\def~{\noexpand~}}% \else% \catcode\count@=11 % \fi% \advance\count@ by \@ne% \ifnum\count@<\@cclvi% \repeat% % \end{macrocode} % The default active |^^L| is |\outer|. But |\reserved@b| will be |def'd| % with an active |^^L| in its replacement text. % \begin{macrocode} \let^^L\relax% \edef\E{\@backslashchar end\string{\@currenvir\string}}% \edef\reserved@b{\def\noexpand\reserved@b####1\E####2\E####3\relax}% \reserved@b{% \ifx\relax##3\relax% \immediate\write\reserved@c{##1}% % \end{macrocode} % This is where the original |filecontents| is extended to store the % parsed material in a macro (in my very first hack I simply % patched it to redefine |\write| to also do the macro storage, but % considerations like the one relative to active characters due to % |inputenc| made me decide to re-write the whole thing, hence make % a new package.) % % Active characters were defined with a single |\noexpand| in the % loop, and this is enough because after each new line is processed % the characters it contains are protected from further expansion in % the |\xdef|'s. And the single |\noexpand| is enough also for the % |\write| done above. % % The |lccode| of the tilde is |32| when this gets executed. Multiple % form feeds produce the same effect in the macro (insertion of two % |^^M| per form feed) as in the written out file (via two |^^J|). % \begin{macrocode} \toks@\expandafter{#2}% {\def^^L{\noexpand^^M\noexpand^^M}\lowercase{\let^^I~}% \xdef#2{\the\toks@##1\noexpand^^M}}% \else% \edef^^M{\noexpand\end{\@currenvir}}% \ifx\relax##1\relax% \else% \@latex@warning{Writing text `##1' before % \string\end{\@currenvir}\MessageBreak as last line of #1}% \immediate\write\reserved@c{##1}% % \end{macrocode} % Same added code as above. % \begin{macrocode} \toks@\expandafter{#2}% {\def^^L{\noexpand^^M\noexpand^^M}\lowercase{\let^^I~}% \xdef#2{\the\toks@##1\noexpand^^M}}% \fi% \ifx\relax##2\relax% \else% \@latex@warning{% Ignoring text `##2' after \string\end{\@currenvir}}% \fi% \fi% ^^M}% \catcode`\^^L\active% \let\L\@undefined% \def^^L{\@ifundefined L^^J^^J^^J}% \catcode`\^^I\active% \let\I\@undefined% \def^^I{\@ifundefined I\space\space}% \catcode`\^^M\active% \edef^^M##1^^M{\noexpand\reserved@b##1\E\E\relax}% % \end{macrocode} % We want space characters to be active in the produced macro. % We only need to protect them once from expansion. % \begin{macrocode} \catcode32\active\lccode`~32 \lowercase{\def~{\noexpand~}}% }% \endgroup \begingroup \catcode`\*=11 \gdef\filecontentsdef {\@tempswatrue\filec@ntentsdef}% \gdef\filecontentsdef*{\@tempswafalse\filec@ntentsdef}% \global\let\endfilecontentsdef \endfilecontents \global\let\endfilecontentsdef*\endfilecontents \gdef\filecontentshere #1{\@tempswatrue \filec@ntentsdef{#1}\filecontentsheremacro}% \gdef\filecontentshere*#1{\@tempswafalse \filec@ntentsdef{#1}\filecontentsheremacro}% \gdef\endfilecontentshere{\endfilecontentsdef\aftergroup\filecontents@verbatim}% \global\let\endfilecontentshere*\endfilecontentshere % \end{macrocode} % Package |verbatim.sty| modifies the standard |verbatim| environment. For % both the original and the modified version we need to insert an active |^^M| % upfront, else an empty first line would not be obeyed. The |verbatim.sty|'s % |verbatim| needs that we feed it with the macro expanded once, as it uses % active end of lines as delimiters and they thus need to be immediately % visible. It also needs an active |^^M| after the |\end{verbatim}|. To avoid % to check at |\AtBeginDocument| if package |verbatim.sty| is loaded, we use a % slightly tricky common definition. The advantage is that this may help make % the code compatible with further packages (I have not looked for them) % modifying the |verbatim| environment. For better code readibility I use % |^^M%|'s rather than exploiting the active ends of lines here. % \begin{macrocode} \catcode`\^^M\active% \gdef\filecontentsprint #1{\let\filecontentsprint@EOL^^M\let^^M\relax% \begingroup\toks@\expandafter{#1}\edef\x{\endgroup% \noexpand\begin{verbatim}^^M% \the\toks@\@backslashchar end\string{verbatim\string}}\x^^M% \filecontentsprint@resetEOL}% \gdef\filecontentsprint@resetEOL{\let^^M\filecontentsprint@EOL}% \endgroup \def\filecontents@verbatim {\filecontentsprint\filecontentsheremacro}% \def\filecontentsexec #1{\newlinechar13 \scantokens\expandafter{#1}\newlinechar10\relax}% \endinput % \end{macrocode} % \MakePercentComment \Finale %% %% End of file `filecontentsdef.dtx'.