diff options
Diffstat (limited to 'macros/latex/contrib/memoir/memoir.dtx')
-rw-r--r-- | macros/latex/contrib/memoir/memoir.dtx | 3246 |
1 files changed, 1856 insertions, 1390 deletions
diff --git a/macros/latex/contrib/memoir/memoir.dtx b/macros/latex/contrib/memoir/memoir.dtx index 674082db74..61a8b9d90e 100644 --- a/macros/latex/contrib/memoir/memoir.dtx +++ b/macros/latex/contrib/memoir/memoir.dtx @@ -20,7 +20,7 @@ % This work consists of the files listed in the README file. % % \fi -% \CheckSum{28664} +% \CheckSum{28075} % % \changes{v0.1}{2001/05/20}{First public alpha release} % \changes{v0.2}{2001/06/03}{First beta release} @@ -203,6 +203,8 @@ % \def\fileversion{v3.7r} \def\filedate{2022/07/29} % \def\fileversion{v3.7.19} \def\filedate{2022/11/17} % \def\fileversion{v3.8} \def\filedate{2023/08/08} +% \def\fileversion{v3.8.1} \def\filedate{2023/08/21} +% \def\fileversion{v3.8.2} \def\filedate{2024/01/26} % \title{The LaTeX \Lpack{memoir} class for configurable book % typesetting: Source code\thanks{This % file (\texttt{\dtxfile}) has version number \fileversion, last revised @@ -435,8 +437,8 @@ % Announce the name, option files and version for LaTeX2e files: % \begin{macrocode} %<class>\ProvidesClass{memoir}% -%<class> [2023/08/21 v3.8.1 configurable book, report, article document class] -%<class>\newcommand\memversion{v3.8.1, 2023/08/21} +%<class> [2024/01/26 v3.8.2 configurable book, report, article document class] +%<class>\newcommand\memversion{v3.8.2, 2024/01/26} % \end{macrocode} % % \changes{v3.7m}{2020/08/05}{Added \cs{IfFormatAtLeastTF}} @@ -10854,59 +10856,131 @@ % \changes{v1.4}{2003/11/22}{Added extra optional arg to \cs{@startsection} % (from patch v1.4)} % \item make sure it is not effected by a non-zero \cs{parskip} -% \changes{v3.6j}{2011/03/02}{added the above feature} +% \changes{v3.6j}{2011/03/02}{added the above feature} +% \item store the name of the type in \cs{m@msecn@me} % \end{itemize} -% The original is in \file{ltsect.dtx}. \\ +% The original is in \file{latex.ltx}. \\ % \cs{@startsection}\marg{name}\marg{level}\marg{indent} \\ % \hspace*{1.5in} \marg{beforeskip}\marg{afterskip}\marg{style} +% +% In order to make experiments with the tagging code, we only make the +% redefinition, if \textsf{dev-mode} is not active. Otherwise we +% patch. It is intentional that the patches are ``talkative''. +% \changes{v3.8.2}{2023/08/24}{Forgot to add this patching branch in 3.8} +% \begin{macrocode} +\ifmem@devmode + +% \end{macrocode} +% The first patch add the block hook, the raggedbottom secton code, +% and the storing of the name of the section type. % \begin{macrocode} -\renewcommand{\@startsection}[6]{% + \patchcmd\@startsection{% + \if@noskipsec \leavevmode \fi% + }{% + \@nameuse{#1block}% + \ifraggedbottomsection\if@nobreak\else + \vskip\z@\@plus\bottomsectionskip + \penalty\bottomsectionpenalty + \vskip\z@\@plus -\bottomsectionskip + \fi\fi + \def\m@msecn@me{#1}% + \if@noskipsec \leavevmode \fi% + }% + {\typeout{\string\@startsection\space patch 1 success}} + {\typeout{\string\@startsection\space patch 1 failed}} + +% \end{macrocode} +% The second patch adds a small adjustment that help counter the +% effect of a non-zero \cs{parskip} +% \begin{macrocode} + \patchcmd\@startsection{% + \addpenalty\@secpenalty\addvspace\@tempskipa% + }{% + \addpenalty\@secpenalty\addvspace\@tempskipa + \addvspace{-\parskip}% <--- added 2011/03/02 + }% + {\typeout{\string\@startsection\space patch 2 success}} + {\typeout{\string\@startsection\space patch 2 failed}} + +% \end{macrocode} +% The third patch completely replaces +% \begin{verbatim} +% \@ifstar +% {\@ssect{#3}{#4}{#5}{#6}}% +% {\@dblarg{\@sect{#1}{#2}{#3}{#4}{#5}{#6}}} +% \end{verbatim} +% as we need to handle two optional args not just the normal +% 1. Perhaps there are better ways. +% \begin{macrocode} + \patchcmd\@startsection{% + \@ifstar% + {\@ssect{#3}{#4}{#5}{#6}}% + {\@dblarg{\@sect{#1}{#2}{#3}{#4}{#5}{#6}}}% + }{% + \@ifstar% + {\@ssect{#3}{#4}{#5}{#6}}% + {\@trplargoom{\M@sect{#1}{#2}{#3}{#4}{#5}{#6}}}% + }% + {\typeout{\string\@startsection\space patch 3 success}} + {\typeout{\string\@startsection\space patch 3 failed}} + +\else % standard branch for dev-mode false +% \end{macrocode} +% Then the normal redefinition +% \begin{macrocode} + \renewcommand{\@startsection}[6]{% % \end{macrocode} % \changes{v3.6h}{2011/02/07}{Added float block hook} % \begin{macrocode} - \@nameuse{#1block}% + \@nameuse{#1block}% % \end{macrocode} % Do raggedbottom stuff. % \changes{v3.6k}{2012/07/22}{Made the \cs{raggedbottomsection} % penalty configurable} % \begin{macrocode} - \ifraggedbottomsection\if@nobreak\else - \vskip\z@\@plus\bottomsectionskip - \penalty\bottomsectionpenalty - \vskip\z@\@plus -\bottomsectionskip - \fi\fi + \ifraggedbottomsection\if@nobreak\else + \vskip\z@\@plus\bottomsectionskip + \penalty\bottomsectionpenalty + \vskip\z@\@plus -\bottomsectionskip + \fi\fi % \end{macrocode} % Save the section name. % \begin{macrocode} - \def\m@msecn@me{#1}% + \def\m@msecn@me{#1}% % \end{macrocode} % The original code. % \begin{macrocode} - \if@noskipsec \leavevmode \fi - \par - \@tempskipa #4\relax - \@afterindenttrue - \ifdim \@tempskipa <\z@ - \@tempskipa -\@tempskipa \@afterindentfalse - \fi - \if@nobreak - \everypar{}% - \else + \if@noskipsec \leavevmode \fi + \par + \@tempskipa #4\relax + \@afterindenttrue + \ifdim \@tempskipa <\z@ + \@tempskipa -\@tempskipa \@afterindentfalse + \fi + \if@nobreak + \everypar{}% + \else % \end{macrocode} % Slight change such that the effect of \cs{parskip} is cancelled % \changes{v3.6j}{2011/03/02}{Adding a negative \cs{parskip} seem to % be able to remove the effect of a non-zero \cs{parskip}} % \begin{macrocode} - \addpenalty\@secpenalty\addvspace\@tempskipa - \addvspace{-\parskip}% <--- added 2011/03/02 - \fi + \addpenalty\@secpenalty\addvspace\@tempskipa + \addvspace{-\parskip}% <--- added 2011/03/02 + \fi % \end{macrocode} % For the extra optional argument, change the original \verb?\@dblarg{\@sect{...? % below to \verb?\@trplargoom{\M@sect{...?. % \begin{macrocode} - \@ifstar - {\@ssect{#3}{#4}{#5}{#6}}% - {\@trplargoom{\M@sect{#1}{#2}{#3}{#4}{#5}{#6}}}} + \@ifstar + {\@ssect{#3}{#4}{#5}{#6}}% + {\@trplargoom{\M@sect{#1}{#2}{#3}{#4}{#5}{#6}}}} + +% \end{macrocode} +% end dev-mode-else branch for \cs{@startsection}: +% \begin{macrocode} + +\fi % en dev-mode else branch % \end{macrocode} % \end{macro} @@ -12682,7 +12756,31 @@ % \end{macrocode} % \end{macro} % -% +% \begin{macro}{\raggedwrap} +% +% \changes{v3.8.2}{2024/01/25}{Code moved here from the verbatim +% section. The code where it was uses has been removed, but the +% macro might still be interesting.} +% +% \cs{raggedwrap} is a variation on \cs{raggedright} (\cs{leftskip} +% is set to \cs{@totalleftmargin} instead of 0pt), and seems to have +% fixed the problem with the original code which used +% \cs{raggedright}. \changes{v1.61803}{2008/01/30}{Added +% \cs{raggedwrap} (mempatch v4.4)} +% \changes{v1.61803398}{2009/07/18}{Added bidi support to +% \cs{raggedwrap}} +% \begin{macrocode} +\newcommand*{\raggedwrap}{% + \@rightskip\@flushglue +%%% \rightskip\@rightskip + \memRTLrightskip\@rightskip +%%% \leftskip\@totalleftmargin + \memRTLleftskip\@totalleftmargin + \parindent\ragrparindent} + +% \end{macrocode} +% \end{macro} +% % \subsubsection{Hanging} % % \begin{macro}{\hangfrom} @@ -18102,20 +18200,36 @@ % \end{macro} % % \begin{macro}{\endsidecaption} -% \cs{endsidecaption} does the work for \verb?\end{sidecaption}?. +% \begin{macro}{\endsidecaption@refstepcounter} +% \cs{endsidecaption} does the work for +% \verb?\end{sidecaption}?. + +% First we define a helper macro that others can hook into. Here is +% the default definition. The two arguments are either two copies of +% \cs{@captype} or for the cont version, \cs{@captype} and +% \texttt{memhycontfloat}. Then this macro is redefined whenever +% \Lpack{hyperref} is loaded (via \Lpack{memhfixc}). The addition +% eliminates the need for a full macro redef in \Lpack{memhfixc}. +% \changes{v3.8.2}{2023/09/10}{Added macro at the suggestion of Axel Sommerfelt} +% \begin{macrocode} +\newcommand*\sidecaption@refstepcounter[2]{\refstepcounter{#1}} +% \end{macrocode} % % Finish the float minipage, then increment the caption counter and % call \cs{label} via \cs{m@mscaplabel}. % \begin{macrocode} \def\endsidecaption{% \m@mscapend@fbox - \refstepcounter\@captype +% \end{macrocode} +% % \changes{v3.8.2}{2023/09/10}{Added macro call at the suggestion of Axel Sommerfelt} +% \begin{macrocode} + \sidecaption@refstepcounter\@captype\@captype \m@mscaplabel % \end{macrocode} % \changes{v3.6k}{2012/08/19}{We need to move \cs{m@mscapcheckside} % here or the \cs{sidecapstyle} inside the box, will never work correctly.} % \begin{macrocode} - \m@mscapcheckside %<--- added 2012/08/19 + \m@mscapcheckside% % \end{macrocode} % Set the caption inside a minipage, saving it in box \cs{m@mscap@capbox}. % \begin{macrocode} @@ -18131,6 +18245,7 @@ \m@mscapopboxes} % \end{macrocode} % \end{macro} +% \end{macro} % % \begin{macro}{\m@mscapopboxes} % Having determined how high the caption box must be raised with @@ -18348,7 +18463,12 @@ % \begin{macrocode} \def\endsidecontcaption{% \m@mscapend@fbox - \addtocounter{\@captype}{\m@ne}\refstepcounter\@captype + \addtocounter{\@captype}{\m@ne} +% \end{macrocode} +% \changes{3.8.2}{2023/09/10}{factor refstep counter as in \cs{endsidecaption}} +% \begin{macrocode} + \sidecaption@refstepcounter\@captype{memhycontfloat} + %\refstepcounter\@captype \m@mscaplabel % \end{macrocode} % \changes{v3.7b}{2013/05/30}{Forgot the side check} @@ -24152,20 +24272,24 @@ % \begin{macrocode} \newcommand{\m@make@footnotetext}[1]{% \@namelongdef{@footnotetext#1}##1{% - \insert\@nameuse{footins#1}{% - \def\baselinestretch{\m@m@footnote@spacing}% - \reset@font\@nameuse{foottextfont#1}% - \@preamfntext - \hsize\columnwidth - \def\@currentcounter{footnote}% - \protected@edef\@currentlabel{% - \csname p@footnote#1\endcsname\@nameuse{@thefnmark#1}}% - \color@begingroup - \@nameuse{@makefntext#1}{% - \rule\z@\footnotesep\ignorespaces\@nameuse{foottextfont#1 ##1}% - \@finalstrut\strutbox}% + \insert\@nameuse{footins#1}{% + \def\baselinestretch{\m@m@footnote@spacing}% + \reset@font\@nameuse{foottextfont#1}% + \@preamfntext + \hsize\columnwidth + \def\@currentcounter{footnote}% + \protected@edef\@currentlabel{% + \csname p@footnote#1\endcsname\@nameuse{@thefnmark#1}}% + \color@begingroup + \@nameuse{@makefntext#1}{% +% \end{macrocode} +% \changes{v3.8.2}{2024/01/03}{Bug: \#\#1 needs to be outside of \cs{@nameuse}, reported in \url{https://tex.stackexchange.com/questions/706033/footnotes-defined-with-newfootnoteseries-dont-work/}} +% \begin{macrocode} + \rule\z@\footnotesep\ignorespaces\@nameuse{foottextfont#1}##1% + \@finalstrut\strutbox}% \color@endgroup}% - \m@mmf@prepare}} + \m@mmf@prepare}% +} % \end{macrocode} % \end{macro} @@ -27563,522 +27687,80 @@ % \end{macrocode} % -% \section{Verbatims, boxes, and files} % -% All the code in this section was added for version 1.2 of the class. -% \changes{v1.2}{2002/07/27}{Section `Verbatims, boxes and files' added} +% \section{Verbatims, boxes, and files} % -% \subsection{Modified version of the verbatim package} % -% Much of this is from the \Lpack{verbatim} package code~\cite{VERBATIM}. -% Unless indicated otherwise, the code and commentary is from that +% Until January 2024 the class contained an embedded and modified +% version of the \Lpack{verbatim} package where PW had added some +% extra features to the verbatim system. As time have progressed the +% LaTeX team has taken all the required tool packages under their wing +% and continuously update them. Thus is it unfeasible to embed a +% package like \Lpack{verbatim} anymore. The embeded copy have +% therefore been replaced by simply loading the \Lpack{verbatim} % package. % +% Eventhough we could patch in the changed PW made to \Lpack{verbatim} +% we've decided against it. The two features he added was marking tabs +% using a number of spaces (turned off by default) and enabling line +% breaks at white space (turned off by default). It simply gets to +% messy trying to patch in both features, given that the number of +% users using it is probably very low. % -% \subsubsection{Preliminaries} -% -% \begin{macro}{\every@verbatim} -% \begin{macro}{\afterevery@verbatim} -% The hook (i.e., token register) \cs{every@verbatim} -% is initialized to \meta{empty}. -% -% PW added the \cs{afterevery@verbatim} hook. -% \begin{macrocode} -\newtoks\every@verbatim - \every@verbatim={} -\newtoks\afterevery@verbatim - \afterevery@verbatim={} - -% \end{macrocode} -% \end{macro} -% \end{macro} -% -% -% \begin{macro}{\@makeother} -% \cs{@makeother} takes as argument a character and changes -% its category code to $12$ (other). -% \begin{macrocode} -\def\@makeother#1{\catcode`#112\relax} -% \end{macrocode} -% \end{macro} -% -% -% \begin{macro}{\@vobeyspaces} -% The macro \cs{@vobeyspaces} causes spaces in the input -% to be printed as spaces in the output. -% \begin{macrocode} -\begingroup - \catcode`\ =\active% - \def\x{\def\@vobeyspaces{\catcode`\ \active\let \@xobeysp}} - \expandafter\endgroup\x -% \end{macrocode} -% \end{macro} -% -% -% \begin{macro}{\@xobeysp} -% The macro \cs{@xobeysp} produces exactly one space in -% the output, protected against breaking just before it. -% (\cs{@M} is an abbreviation for the number $10000$.) -% \begin{macrocode} -\def\@xobeysp{\leavevmode\penalty\@M\ } -% \end{macrocode} -% \end{macro} -% -% -% \begin{macro}{\verbatim@line} -% We use a newly defined token register called \cs{verbatim@line} -% that will be used as the character buffer. -% \begin{macrocode} -\newtoks\verbatim@line -% \end{macrocode} -% \end{macro} -% -% PW. I have extended the original \Lpack{verbatim} package code to handle -% TABs within verbatims. Normally TeX replaces a TAB by either a single space or -% ignores it altogether. For this purpose I have bits of code from the \Lpack{moreverb} -% package~\cite{MOREVERB} for handling TABs. -% -% \textit{Code and commentary from moreverb.} -% -% We define a few auxiliary macros and counters for expanding tabs. -% \begin{macrocode} -\newcount\tab@position -% \end{macrocode} -% -% \begin{macro}{\@xobeytab} -% \cs{@xobeytab} puts enough spaces in to get to the next nominal -% tab stop -% \begin{macrocode} -\def\@xobeytab{% - \loop - \toks@\expandafter{\the\toks@\@xobeysp}% - \advance\tab@position-1 - \ifnum\tab@position>0 \repeat -} -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\@vobeytabs} -% \cs{@vobeytabs} initialises use of \cs{@xobeytab}. Needs to be -% executed within a group, as mustn't be allowed to leak out into the -% wide world. -% -% \begin{macrocode} -\begingroup - \catcode`\^^I=\active - \gdef\@vobeytabs{\catcode`\^^I\active\let^^I\@xobeytab}% -\endgroup -% \end{macrocode} -% \end{macro} +% Note that our modified copy of \Lpack{verbatim} had all references +% to \cs{leftskip} and \cs{rightskip} replaced by \cs{memRTLleftskip} +% and \cs{memRTLrightskip}. For now we have no intention of patching +% these into the \Lpack{verbatim} code, but it should be straight +% forward if needed. % -% \begin{macro}{\verbatim@tabexpand} -% \cs{verbatim@tabexpand}\marg{body of line}\cs{@nil} processes every -% character of a line by tail recursion, counting the characters and -% juggling things when a tab is encountered. +% \subsection{Additions to the verbatim package} +% +% \changes{v3.8.2}{2024/01/24}{Replaced embedded altered copy of +% \Lpack{verbatim} with loading the package} +% Load the package instead of embedding it. % \begin{macrocode} -\def\verbatim@tabexpand#1{% - \ifx#1\@nil - \the\toks@ - \expandafter\par - \else - \ifx#1\@xobeytab - \@xobeytab - \else +\RequirePackage{verbatim} % \end{macrocode} % -% We can safely put \cs{@xobeysp} into the token register, since it -% does precisely what we need +% A future update (\verb|github #1245|) to \Lpack{verbatim} will enable +% \cs{verbatiminput*} to mark tabs as if it was spaces. If that +% version has not been released yet, we add the patch % \begin{macrocode} - \toks@\expandafter{\the\toks@#1}% - \advance\tab@position\m@ne - \fi - \ifnum\tab@position=0 \tab@position\tab@size \fi - \expandafter\verbatim@tabexpand - \fi +\@ifpackagelater{verbatim}{2024/01/21}{}{ + \def\verbatiminput{\begingroup + \@ifstar{\verbatim@input{\@setupverbvisiblespace\@vobeyspaces}}% + {\verbatim@input{\frenchspacing\@vobeyspaces}}} } % \end{macrocode} -% \end{macro} -% -% \textit{End of code and commentary from moreverb.} -% -% PW. Some macros for turning tabbing on and off. -% -% \begin{macro}{\tabson} -% \begin{macro}{\tabsoff} -% \begin{macro}{\@maybeobeytabs} -% \cs{tabson} turns tabbing on, and \cs{tabsoff} turns it off. Default -% is no tabbing. -% \begin{macrocode} -\newif\ift@bs -\newcommand{\tabson}[1][4]{% - \ifnum\@ne > #1\relax - \tabsoff - \else - \t@bstrue - \def\tab@size{#1\relax}% - \def\@maybeobeytabs{\@vobeytabs}% - \fi -} -\newcommand{\tabsoff}{% - \t@bsfalse - \def\tab@size{\z@}% - \def\@maybeobeytabs{}% -} -\tabsoff - -% \end{macrocode} -% \end{macro} -% \end{macro} -% \end{macro} -% -% \begin{macro}{\tabverbatim@processline} -% Process a line with TABs (extracted from \Lpack{moreverb}). -% \begin{macrocode} -\def\tabverbatim@processline{\tab@position\tab@size - \toks@{}% - \expandafter\verbatim@tabexpand\the\verbatim@line\@nil} -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\notabverbatim@processline} -% Processes a line ignoring TABs (this is the original \Lpack{verbatim} -% package definition of \cs{verbatim@processline}). -% \begin{macrocode} -\def\notabverbatim@processline{\the\verbatim@line\par} - -% \end{macrocode} -% \end{macro} -% -% \textit{We are now back to the \Lpack{verbatim} code.} -% -% The following four macros are defined globally in a way suitable for -% the \texttt{verbatim} and \texttt{verbatim*} environments. -% \begin{macro}{\verbatim@startline} -% \begin{macro}{\verbatim@addtoline} -% \begin{macro}{\verbatim@processline} -% \cs{verbatim@startline} initializes processing of a line -% by emptying the character buffer (\cs{verbatim@line}). -% \begin{macrocode} -\def\verbatim@startline{\verbatim@line{}} -% \end{macrocode} -% \cs{verbatim@addtoline} adds the tokens in its argument -% to our buffer register \cs{verbatim@line} without expanding -% them. -% \begin{macrocode} -\def\verbatim@addtoline#1{% - \verbatim@line\expandafter{\the\verbatim@line#1}} -% \end{macrocode} -% Processing a line inside a \texttt{verbatim} or \texttt{verbatim*} -% environment means printing it. -% Ending the line means that we have to begin a new paragraph. -% We use \cs{par} for this purpose. Note that \cs{par} -% is redefined in \cs{@verbatim} to force \TeX{} into horizontal -% mode and to insert an empty box so that empty lines in the input -% do appear in the output. -% (PW changed next line from \\ -% \verb?\def\verbatim@processline{\the\verbatim@line\par}? -% \begin{macrocode} -\def\verbatim@processline{\notabverbatim@processline} -% \end{macrocode} -% \end{macro} -% \end{macro} -% \end{macro} -% -% \begin{macro}{\verbatim@finish} -% As a default, \cs{verbatim@finish} processes the remaining -% characters. -% When this macro is called we are facing the following problem: -% when the \verb?\end{verbatim}? -% command is encountered \cs{verbatim@processline} is called -% to process the characters preceding the command on the same -% line. If there are none, an empty line would be output if we -% did not check for this case. -% -% If the line is empty \verb?\the\verbatim@line? expands to -% nothing. To test this we use a trick similar to that on p.\ 376 -% of the \TeX{}book, but with \verb?$?\ldots\verb?|$? instead of -% the \verb?!? tokens. These \verb?$? tokens can never have the same -% category code as a \verb?$? token that might possibly appear in the -% token register \cs{verbatim@line}, as such a token will always have -% been read with category code $12$ (other). -% Note that \cs{ifcat} expands the following tokens so that -% \verb?\the\verbatim@line? is replaced by the accumulated -% characters -% \begin{macrocode} -\def\verbatim@finish{\ifcat$\the\verbatim@line$\else - \verbatim@processline\fi} -% \end{macrocode} -% \end{macro} -% -% -% \subsubsection{The \texttt{verbatim} and \texttt{verbatim*} environments} -% -% \begin{macro}{\verbatim@font} -% We start by defining the macro \cs{verbatim@font} that is -% to select the font and to set font-dependent parameters. -% Then we go through \cs{verbatim@nolig@list} to avoid -% certain ligatures. -% \cs{verbatim@nolig@list} is a macro defined in the \LaTeXe{} kernel -% to expand to -% \begin{verbatim} -% \do\`\do\<\do\>\do\,\do\'\do\- -% \end{verbatim} -% All the characters in this list can be part of a ligature in some -% font or other. -% -% PW. This is the original version which I'm going to replace. -% \begin{verbatim} -% \def\verbatim@font{\normalfont\ttfamily -% \hyphenchar\font\m@ne -% \let\do\do@noligs -% \verbatim@nolig@list} -% \end{verbatim} -% Actually the kernel defines the macro \verb+\@noligs+ which just -% runs the last two lines of the \verb+\verbatim@font+ above. As other -% package may add stuff to \verb+\@noligs+, we will use that instead. -% \end{macro} +% it of course requires an updated kernel. % % \begin{macro}{\setverbatimfont} % \begin{macro}{\m@mverbfont} -% \begin{macro}{\verbatim@font} -% User level handle for changing the font used for verbatim text. -% \changes{v1.61803398}{2009/09/10}{Changed the last two lines of -% \cs{verbatim@font} into using \cs{@noligs} instead. This fixes -% problem with upquote.} +% We do provide an interface to set the font used in +% verbatims. Internally in \Lpack{verbatim} this is done via \cs{verbatim@font}. % \begin{macrocode} \newcommand{\setverbatimfont}[1]{\def\m@mverbfont{#1}} \setverbatimfont{\normalfont\ttfamily} - -\def\verbatim@font{\m@mverbfont - \hyphenchar\font\m@ne - \@noligs} - -% \end{macrocode} -% \end{macro} -% \end{macro} -% \end{macro} -% -% -% \begin{macro}{\@verbatim} -% The macro \cs{@verbatim} sets up things properly. -% First of all, the tokens of the \cs{every@verbatim} hook -% are inserted. -% Then a \texttt{trivlist} environment is started and its first -% \cs{item} command inserted. -% Each line of the \texttt{verbatim} or \texttt{verbatim*} -% environment will be treated as a separate paragraph. -% \changes{v1.61803398}{2009/07/18}{Added bidi support to \cs{@verbatim}} -% \begin{macrocode} -\def\@verbatim{\the\every@verbatim - \trivlist \item \relax -% \end{macrocode} -% The following extra vertical space is for compatibility with the -% \LaTeX kernel: otherwise, using the \Lpack{verbatim} package changes -% the vertical spacing of a \texttt{verbatim} environment nested within a -% \texttt{quote} environment. -% \begin{macrocode} - \if@minipage\else\vskip\parskip\fi -% \end{macrocode} -% The paragraph parameters are set appropriately: -% the penalty at the beginning of the environment, -% left and right margins, paragraph indentation, the glue to -% fill the last line, and the vertical space between paragraphs. -% The latter space has to be zero since we do not want to add -% extra space between lines. -% \begin{macrocode} - \@beginparpenalty \predisplaypenalty -%%% \leftskip\@totalleftmargin\rightskip\z@ - \memRTLleftskip\@totalleftmargin\memRTLrightskip\z@ - \parindent\z@\parfillskip\@flushglue\parskip\z@ -% \end{macrocode} -% There's one point to make here: -% the \texttt{list} environment uses \TeX's \cs{parshape} -% primitive to get a special indentation for the first line -% of the list. -% If the list begins with a \texttt{verbatim} environment -% this \cs{parshape} is still in effect. -% Therefore we have to reset this internal parameter explicitly. -% We could do this by assigning $0$ to \cs{parshape}. -% However, there is a simpler way to achieve this: -% we simply tell \TeX{} to start a new paragraph. -% As is explained on p.~103 of the \TeX{}book, this resets -% \cs{parshape} to zero. -% \begin{macrocode} - \@@par -% \end{macrocode} -% We now ensure that \cs{par} has the correct definition, -% namely to force \TeX{} into horizontal mode -% and to include an empty box. -% This is to ensure that empty lines do appear in the output. -% Afterwards, we insert the \cs{interlinepenalty} since \TeX{} -% does not add a penalty between paragraphs (here: lines) -% by its own initiative. Otherwise a \texttt{verbatim} environment -% could be broken across pages even if a \cs{samepage} -% declaration were present. -% -% However, in a top-aligned minipage, this will result in an extra -% empty line added at the top. Therefore, a slightly more -% complicated construct is necessary. -% One of the important things here is the inclusion of -% \cs{leavevmode} as the first macro in the first line, for example, -% a blank verbatim line is the first thing in a list item. -% \begin{macrocode} - \def\par{% - \if@tempswa - \leavevmode\null\@@par\penalty\interlinepenalty - \else - \@tempswatrue - \ifhmode\@@par\penalty\interlinepenalty\fi - \fi}% -% \end{macrocode} -% But to avoid an error message when the environment -% doesn't contain any text, we redefine \cs{@noitemerr} -% which will in this case be called by \cs{endtrivlist}. -% \begin{macrocode} - \def\@noitemerr{\@warning{No verbatim text}}% -% \end{macrocode} -% Now we call \cs{obeylines} to make the end of line character -% active, -% \begin{macrocode} - \obeylines -% \end{macrocode} -% change the category code of all special characters, -% to $12$ (other). -% \begin{macrocode} - \let\do\@makeother \dospecials -% \end{macrocode} -% and switch to the font to be used. -% \begin{macrocode} - \verbatim@font -% \end{macrocode} -% To avoid a breakpoint after the labels box, we remove the penalty -% put there by the list macros: another use of \cs{unpenalty}! -% \begin{macrocode} - \everypar \expandafter{\the\everypar \unpenalty}% -% \end{macrocode} -% PW added next code at end of \cs{@verbatim}. -% \begin{macrocode} - \wrapright\the\afterevery@verbatim} -% \end{macrocode} -% \end{macro} -% -% -% \begin{macro}{\verbatim} -% \begin{macro}{\verbatim*} -% Now we define the toplevel macros. -% \cs{verbatim} is slightly changed: -% after setting up things properly it calls -% \cs{verbatim@start}. -% This is done inside a group, so that \cs{verbatim} can be used -% directly, without \cs{begin}. -% -% PW. The following is the original code, but I want a version of -% \texttt{verbatim} that recognises TABs. -% \begin{verbatim} -% \begin{macrocode} -% \def\verbatim{% -% \begingroup\@verbatim \frenchspacing\@vobeyspaces -% \verbatim@start} -% \end{macrocode} -% \cs{verbatim*} is defined accordingly. -% \begin{macrocode} -% \@namedef{verbatim*}{\begingroup\@verbatim\verbatim@start} -% \def\endverbatim{\endtrivlist\endgroup} -% \expandafter\let\csname endverbatim*\endcsname=\endverbatim -% \end{macrocode} -% \end{verbatim} -% -% PW. My code for these is a modified version of the original \Lpack{verbatim} -% code. -% \begin{macrocode} -\def\verbatim{\begingroup - \ift@bs - \def\verbatim@processline{\tabverbatim@processline}% - \fi - \@verbatim \frenchspacing\@vobeyspaces\@maybeobeytabs\verbatim@start} -\@namedef{verbatim*}{\begingroup - \ift@bs - \def\verbatim@processline{\tabverbatim@processline}% - \fi - \@verbatim\@maybeobeytabs\verbatim@start} -% \end{macrocode} -% \end{macro} -% \end{macro} -% -% -% \begin{macro}{\endverbatim} -% \begin{macro}{\endverbatim*} -% To end the \texttt{verbatim} and \texttt{verbatim*} -% environments it is only necessary to finish the -% \texttt{trivlist} environment started in \cs{@verbatim} and -% close the corresponding group, and handle\footnote{Noted by -% Zarko Cucej (\url{zarko.cucej@uni-mb.si}).} following (non-) paragraph, -% by using \cs{@doendpe}. -% \changes{v1.4}{2003/11/22}{Added \cs{@doendpe} to \cs{endverbatim} -% (from patch v1.8)} -% \changes{v2.0a}{2004/03/01}{Refixed \cs{endverbatim}} -% \begin{macrocode} -\def\endverbatim{\endtrivlist\endgroup\@doendpe} -\@namelet{endverbatim*}\endverbatim +\patchcmd\verbatim@font{\normalfont\ttfamily}% + {\m@mverbfont}% + {}% + {\typeout{Paching \string\verbatim@font\space failed}} % \end{macrocode} % \end{macro} % \end{macro} % -% For abnormal \cs{parskip}s the NTG class included the following, but I'm -% not sure if it is relevant here, but if it is just how it should be included. -% \begin{verbatim} -% From NTG, where it is a \cs{def} -% \providecommand*{\verbatim}{% -% \topsep=-0.5\parskip -% \@verbatim -% \frenchspacing\@vobeyspaces \@xverbatim} -% \end{verbatim} -% -% -% \subsubsection{The \texttt{comment} environment} -% -% The \cs{comment} macro is similar to \cs{verbatim*}. -% However, we do not need to switch fonts or set special -% formatting parameters such as \cs{parindent} or \cs{parskip}. -% We need only set the category code of all special characters -% to $12$ (other) and that of \verb?^^M? (the end of line character) -% to $13$ (active). -% The latter is needed for macro parameter delimiter matching in -% the internal macros defined below. -% In contrast to the default definitions used by the -% \cs{verbatim} and \cs{verbatim*} macros, -% we define \cs{verbatim@addtoline} to throw away its argument -% and \cs{verbatim@processline}, \cs{verbatim@startline}, -% and \cs{verbatim@finish} to act as no-ops. -% Then we call \cs{verbatim@}. -% But the first thing we do is to call \cs{@bsphack} so that -% this environment has no influence whatsoever upon the spacing. -% -% PW: This is the original code for the \texttt{comment} environment, -% which I'm going to change. -% \begin{verbatim} -% \def\comment{\@bsphack -% \let\do\@makeother\dospecials\catcode`\^^M\active -% \let\verbatim@startline\relax -% \let\verbatim@addtoline\@gobble -% \let\verbatim@processline\relax -% \let\verbatim@finish\relax -% \verbatim@} -% \end{verbatim} -% \cs{endcomment} is very simple: it only calls -% \cs{@esphack} to take care of the spacing. -% The \cs{end} macro closes the group and therefore takes care -% of restoring everything we changed. -% \begin{verbatim} -% \let\endcomment=\@esphack -% \end{verbatim} -% -% PW: The remainder of this section is my code. -% -% \begin{macro}{\setupcomment} -% \cs{setupcomment} does all the \cs{let}s in the original \cs{comment} code. +% % \subsubsection{The \texttt{comment} environment} +% +% The \Lpack{verbatim} package provides the \Lenv{comment} environment +% that ignores its contents. This is a very useful feature, and we +% would like users to be able todefine their own \Lenv{comment} like +% envs. The following code is PWs original code, only difference is +% that we do not define \Lenv{comment} using the code. We leave the +% \Lpack{verbatim} alone. +% % \begin{macro}{\setupcomment} +% \cs{setupcomment} does all the \cs{let}s in the original \cs{comment} code. For reference see the \cite{VERBATIM} sources. % \begin{macrocode} \newcommand{\setupcomment}{% \let\do\@makeother\dospecials\catcode`\^^M\active @@ -28122,725 +27804,1471 @@ % \end{macrocode} % \end{macro} % -% We had better supply the \texttt{comment} environment, as promised. -% \begin{macrocode} -\newcomment{comment} - -% \end{macrocode} -% -% PW: That is the end of my changes and extensions to the original -% \texttt{comment} environment code. -% -% -% \subsubsection{The main loop} -% -% Here comes the tricky part: -% During the definition of the macros we need to use the special -% characters \verb?\?, \verb?{?, and \verb?}? not only with their -% normal category codes, -% but also with category code $12$ (other). -% We achieve this by the following trick: -% first we tell \TeX{} that \verb?\?, \verb?{?, and \verb?}? -% are the lowercase versions of \verb?!?, \verb?[?, and \verb?]?. -% Then we replace every occurrence of \verb?\?, \verb?{?, and \verb?}? -% that should be read with category code $12$ by \verb?!?, \verb?[?, -% and \verb?]?, respectively, -% and give the whole list of tokens to \cs{lowercase}, -% knowing that category codes are not altered by this primitive! -% -% But first we have ensure that -% \verb?!?, \verb?[?, and \verb?]? themselves have -% the correct category code! -% To allow special settings of these codes we hide their setting in -% the macro \cs{vrb@catcodes}. If it is already defined our new -% definition is skipped. -% \begin{macrocode} -\@ifundefined{vrb@catcodes}% - {\def\vrb@catcodes{% - \catcode`\!12\catcode`\[12\catcode`\]12}}{} -% \end{macrocode} -% This trick allows us to use this code for applications where other -% category codes are in effect. -% -% We start a group to keep the category code changes local. -% \begin{macrocode} -\begingroup - \vrb@catcodes - \lccode`\!=`\\ \lccode`\[=`\{ \lccode`\]=`\} -% \end{macrocode} -% We also need the end-of-line character \verb?^^M?, -% as an active character. -% If we were to simply write \verb?\catcode`\^^M=\active? -% then we would get an unwanted active end of line character -% at the end of every line of the following macro definitions. -% Therefore we use the same trick as above: -% we write a tilde \verb?~? instead of \verb?^^M? and -% pretend that the -% latter is the lowercase variant of the former. -% Thus we have to ensure now that the tilde character has -% category code $13$ (active). -% \begin{macrocode} - \catcode`\~=\active \lccode`\~=`\^^M -% \end{macrocode} -% The use of the \cs{lowercase} primitive leads to one problem: -% the uppercase character `\texttt{C}' needs to be used in the -% code below and its case must be preserved. -% So we add the command: -% \begin{macrocode} - \lccode`\C=`\C -% \end{macrocode} -% Now we start the token list passed to \cs{lowercase}. -% We use the following little trick (proposed by Bernd Raichle): -% The very first token in the token list we give to \cs{lowercase} is -% the \cs{endgroup} primitive. This means that it is processed by -% \TeX{} immediately after \cs{lowercase} has finished its operation, -% thus ending the group started by \cs{begingroup} above. This avoids -% the global definition of all macros. -% \begin{macrocode} - \lowercase{\endgroup -% \end{macrocode} -% \begin{macro}{\verbatim@start} -% The purpose of \cs{verbatim@start} is to check whether there -% are any characters on the same line as the \verb?\begin{verbatim}? -% and to pretend that they were on a line by themselves. -% On the other hand, if there are no characters remaining -% on the current line we shall just find an end of line character. -% \cs{verbatim@start} performs its task by first grabbing the -% following character (its argument). -% This argument is then compared to an active \verb?^^M?, -% the end of line character. -% \begin{macrocode} - \def\verbatim@start#1{% - \verbatim@startline - \if\noexpand#1\noexpand~% -% \end{macrocode} -% If this is true we transfer control to \cs{verbatim@} -% to process the next line. We use -% \cs{next} as the macro which will continue the work. -% \begin{macrocode} - \let\next\verbatim@ -% \end{macrocode} -% Otherwise, we define \cs{next} to expand to a call -% to \cs{verbatim@} followed by the character just -% read so that it is reinserted into the text. -% This means that those characters remaining on this line -% are handled as if they formed a line by themselves. -% \begin{macrocode} - \else \def\next{\verbatim@#1}\fi -% \end{macrocode} -% Finally we call \cs{next}. -% \begin{macrocode} - \next}% -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\verbatim@} -% The three macros \cs{verbatim@}, \cs{verbatim@@}, -% and \cs{verbatim@@@} form the ``main loop'' of the -% \texttt{verbatim} environment. -% The purpose of \cs{verbatim@} is to read exactly one line -% of input. -% \cs{verbatim@@} and \cs{verbatim@@@} work together to -% find out whether the four characters -% \cs{end} (all with category code $12$ (other)) occur in that -% line. -% If so, \cs{verbatim@@@} will call -% \cs{verbatim@test} to check whether this \cs{end} is -% part of \verb?\end{verbatim}? and will terminate the environment -% if this is the case. -% Otherwise we continue as if nothing had happened. -% So let's have a look at the definition of \cs{verbatim@}: -% \begin{macrocode} - \def\verbatim@#1~{\verbatim@@#1!end\@nil}% -% \end{macrocode} -% Note that the \verb?!? character will have been replaced by a -% \verb?\? with category code $12$ (other) by the \cs{lowercase} -% primitive governing this code before the definition of this -% macro actually takes place. -% That means that -% it takes the line, puts \cs{end} (four character tokens) -% and \cs{@nil} (one control sequence token) as a -% delimiter behind it, and -% then calls \cs{verbatim@@}. -% \end{macro} -% -% \begin{macro}{\verbatim@@} -% \cs{verbatim@@} takes everything up to the next occurrence of -% the four characters \cs{end} as its argument. -% \begin{macrocode} - \def\verbatim@@#1!end{% -% \end{macrocode} -% That means: if they do not occur in the original line, then -% argument \verb?#1? is the -% whole input line, and \cs{@nil} is the next token -% to be processed. -% However, if the four characters \cs{end} are part of the -% original line, then -% \verb?#1? consists of the characters in front of \cs{end}, -% and the next token is the following character (always remember -% that the line was lengthened by five tokens). -% Whatever \verb?#1? may be, it is verbatim text, -% so \verb?#1? is added to the line currently built. -% \begin{macrocode} - \verbatim@addtoline{#1}% -% \end{macrocode} -% The next token in the input stream -% is of special interest to us. -% Therefore \cs{futurelet} defines \cs{next} to be equal -% to it before calling \cs{verbatim@@@}. -% \begin{macrocode} - \futurelet\next\verbatim@@@}% -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\verbatim@@@} -% \cs{verbatim@@@} will now read the rest of the tokens on -% the current line, -% up to the final \cs{@nil} token. -% \begin{macrocode} - \def\verbatim@@@#1\@nil{% -% \end{macrocode} -% If the first of the above two cases occurred, i.e.\ no -% \cs{end} characters were on that line, \verb?#1? is empty -% and \cs{next} is equal to \cs{@nil}. -% This is easily checked. -% \begin{macrocode} - \ifx\next\@nil -% \end{macrocode} -% If so, this was a simple line. -% We finish it by processing the line we accumulated so far. -% Then we prepare to read the next line. -% \begin{macrocode} - \verbatim@processline - \verbatim@startline - \let\next\verbatim@ -% \end{macrocode} -% Otherwise we have to check what follows these \cs{end} -% tokens. -% \begin{macrocode} - \else -% \end{macrocode} -% Before we continue, it's a good idea to stop for a moment -% and remember where we are: -% We have just read the four character tokens \cs{end} -% and must now check whether the name of the environment (surrounded -% by braces) follows. -% To this end we define a macro called \cs{@tempa} -% that reads exactly one character and decides what to do next. -% This macro should do the following: skip spaces until -% it encounters either a left brace or the end of the line. -% But it is important to remember which characters are skipped. -% The \cs{end}\meta{optional spaces}\verb?{? characters -% may be part of the verbatim text, i.e.\ these characters -% must be printed. -% -% Assume for example that the current line contains -% \begin{verbatim*} -% \end {AVeryLongEnvironmentName} -%\end{verbatim*} -% As we shall soon see, the scanning mechanism implemented here -% will not find out that this is text to be printed until -% it has read the right brace. -% Therefore we need a way to accumulate the characters read -% so that we can reinsert them if necessary. -% The token register \cs{@temptokena} is used for this purpose. -% -% Before we do this we have to get rid of the superfluous -% \cs{end} tokens at the end of the line. -% To this end we define a temporary macro whose argument -% is delimited by \verb?\end\@nil? (four character tokens -% and one control sequence token) to be used below -% on the rest of the line, after appending a \cs{@nil} token to it. -% (Note that this token can never appear in \verb?#1?.) -% We use the following definition of -% \cs{@tempa} to get the rest of the line (after the first -% \cs{end}). -% \begin{macrocode} - \def\@tempa##1!end\@nil{##1}% -% \end{macrocode} -% We mentioned already that we use token register -% \cs{@temptokena} -% to remember the characters we skip, in case we need them again. -% We initialize this with the \cs{end} we have thrown away -% in the call to \cs{@tempa}. -% \begin{macrocode} - \@temptokena{!end}% -% \end{macrocode} -% We shall now call \cs{verbatim@test} -% to process the characters -% remaining on the current line. -% But wait a moment: we cannot simply call this macro -% since we have already read the whole line. -% Therefore we have to first expand the macro \cs{@tempa} to insert -% them again after the \cs{verbatim@test} token. -% A \verb?^^M? character is appended to denote the end of the line. -% (Remember that this character comes disguised as a tilde.) -% \begin{macrocode} - \def\next{\expandafter\verbatim@test\@tempa#1\@nil~}% -% \end{macrocode} -% That's almost all, but we still have to -% now call \cs{next} to do the work. -% \begin{macrocode} - \fi \next}% -% \end{macrocode} -% \end{macro} -% -% -% \begin{macro}{\verbatim@test} -% We define \cs{verbatim@test} to investigate every token -% in turn. -% \begin{macrocode} - \def\verbatim@test#1{% -% \end{macrocode} -% First of all we set \cs{next} equal to \cs{verbatim@test} -% in case this macro must call itself recursively in order to -% skip spaces. -% \begin{macrocode} - \let\next\verbatim@test -% \end{macrocode} -% We have to distinguish four cases: -% \begin{enumerate} -% \item The next token is a \verb?^^M?, i.e.\ we reached -% the end of the line. That means that nothing -% special was found. -% Note that we use \cs{if} for the following -% comparisons so that the category code of the -% characters is irrelevant. -% \begin{macrocode} - \if\noexpand#1\noexpand~% -% \end{macrocode} -% We add the characters accumulated in token register -% \cs{@temptokena} to the current line. Since -% \cs{verbatim@addtoline} does not expand its argument, -% we have to do the expansion at this point. Then we -% \cs{let} \cs{next} equal to \cs{verbatim@} -% to prepare to read the next line. -% \begin{macrocode} - \expandafter\verbatim@addtoline - \expandafter{\the\@temptokena}% - \verbatim@processline - \verbatim@startline - \let\next\verbatim@ -% \end{macrocode} -% \item A space character follows. -% This is allowed, so we add it to \cs{@temptokena} -% and continue. -% \begin{macrocode} - \else \if\noexpand#1 - \@temptokena\expandafter{\the\@temptokena#1}% -% \end{macrocode} -% \item An open brace follows. -% This is the most interesting case. -% We must now collect characters until we read the closing -% brace and check whether they form the environment name. -% This will be done by \cs{verbatim@testend}, so here -% we let \cs{next} equal this macro. -% Again we will process the rest of the line, character -% by character. -% The characters forming the name of the environment will -% be accumulated in \cs{@tempc}. -% We initialize this macro to expand to nothing. -% \begin{macrocode} - \else \if\noexpand#1\noexpand[% - \let\@tempc\@empty - \let\next\verbatim@testend -% \end{macrocode} -% Note that the \verb?[? character will be a \verb?{? when -% this macro is defined. -% \item Any other character means that the \cs{end} was part -% of the verbatim text. -% Add the characters to the current line and prepare to call -% \cs{verbatim@} to process the rest of the line. -% \begin{macrocode} - \else - \expandafter\verbatim@addtoline - \expandafter{\the\@temptokena}% - \def\next{\verbatim@#1}% - \fi\fi\fi -% \end{macrocode} -% \end{enumerate} -% The last thing this macro does is to call \cs{next} -% to continue processing. -% \begin{macrocode} - \next}% -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\verbatim@testend} -% \cs{verbatim@testend} is called when -% \cs{end}\meta{optional spaces}\verb?{? was seen. -% Its task is to scan everything up to the next \verb?}? -% and to call \cs{verbatim@@testend}. -% If no \verb?}? is found it must reinsert the characters it read -% and return to \cs{verbatim@}. -% The following definition is similar to that of -% \cs{verbatim@test}: -% it takes the next character and decides what to do. -% \begin{macrocode} - \def\verbatim@testend#1{% -% \end{macrocode} -% Again, we have four cases: -% \begin{enumerate} -% \item \verb?^^M?: As no \verb?}? is found in the current line, -% add the characters to the buffer. To avoid a -% complicated construction for expanding -% \cs{@temptokena} -% and \cs{@tempc} we do it in two steps. Then we -% continue with \cs{verbatim@} to process the -% next line. -% \begin{macrocode} - \if\noexpand#1\noexpand~% - \expandafter\verbatim@addtoline - \expandafter{\the\@temptokena[}% - \expandafter\verbatim@addtoline - \expandafter{\@tempc}% - \verbatim@processline - \verbatim@startline - \let\next\verbatim@ -% \end{macrocode} -% \item \verb?}?: Call \cs{verbatim@@testend} to check -% if this is the right environment name. -% \begin{macrocode} - \else\if\noexpand#1\noexpand]% - \let\next\verbatim@@testend -% \end{macrocode} -% \item \verb?\?: This character must not occur in the name of -% an environment. Thus we stop collecting characters. -% In principle, the same argument would apply to other -% characters as well, e.g., \verb?{?. -% However, \verb?\? is a special case, since it may be -% the first character of \cs{end}. This means that -% we have to look again for -% \cs{end}\marg{environment name} -% Note that we prefixed the \verb?!? by a \cs{noexpand} -% primitive, to protect ourselves against it being an -% active character. -% \begin{macrocode} - \else\if\noexpand#1\noexpand!% - \expandafter\verbatim@addtoline - \expandafter{\the\@temptokena[}% - \expandafter\verbatim@addtoline - \expandafter{\@tempc}% - \def\next{\verbatim@!}% -% \end{macrocode} -% \item Any other character: collect it and continue. -% We cannot use \cs{edef} to define \cs{@tempc} -% since its replacement text might contain active -% character tokens. -% \begin{macrocode} - \else \expandafter\def\expandafter\@tempc\expandafter - {\@tempc#1}\fi\fi\fi -% \end{macrocode} -% \end{enumerate} -% As before, the macro ends by calling itself, to -% process the next character if appropriate. -% \begin{macrocode} - \next}% -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\verbatim@@testend} -% Unlike the previous macros \cs{verbatim@@testend} is simple: -% it has only to check if the \cs{end}\marg{...} -% matches the corresponding \cs{begin}\marg{...} -% \begin{macrocode} - \def\verbatim@@testend{% -% \end{macrocode} -% We use \cs{next} again to define the things that are -% to be done. -% Remember that the name of the current environment is -% held in \cs{@currenvir}, the characters accumulated -% by \cs{verbatim@testend} are in \cs{@tempc}. -% So we simply compare these and prepare to execute -% \cs{end}\marg{current environment} -% macro if they match. -% Before we do this we call \cs{verbatim@finish} to process -% the last line. -% We define \cs{next} via \cs{edef} so that -% \cs{@currenvir} is replaced by its expansion. -% Therefore we need \cs{noexpand} to inhibit the expansion -% of \cs{end} at this point. -% \begin{macrocode} - \ifx\@tempc\@currenvir - \verbatim@finish - \edef\next{\noexpand\end{\@currenvir}% -% \end{macrocode} -% Without this trick the \cs{end} command would not be able -% to correctly check whether its argument matches the name of -% the current environment and you'd get an -% interesting \LaTeX{} error message such as: -% \begin{verbatim} -%! \begin{verbatim*} ended by \end{verbatim*}. -%\end{verbatim} -% But what do we do with the rest of the characters, those -% that remain on that line? -% We call \cs{verbatim@rescan} to take care of that. -% Its first argument is the name of the environment just -% ended, in case we need it again. -% \cs{verbatim@rescan} takes the list of characters to be -% reprocessed as its second argument. -% (This token list was inserted after the current macro -% by \cs{verbatim@@@}.) -% Since we are still in an \cs{edef} we protect it -% by means of\cs{noexpand}. -% \begin{macrocode} - \noexpand\verbatim@rescan{\@currenvir}}% -% \end{macrocode} -% If the names do not match, we reinsert everything read up -% to now and prepare to call \cs{verbatim@} to process -% the rest of the line. -% \begin{macrocode} - \else - \expandafter\verbatim@addtoline - \expandafter{\the\@temptokena[}% - \expandafter\verbatim@addtoline - \expandafter{\@tempc]}% - \let\next\verbatim@ - \fi -% \end{macrocode} -% Finally we call \cs{next}. -% \begin{macrocode} - \next}% -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\verbatim@rescan} -% In principle \cs{verbatim@rescan} could be used to -% analyse the characters remaining after the \verb?\end{...}? -% command and pretend that these were read -% ``properly'', assuming ``standard'' category codes are in -% force.\footnote{Remember that they were all read with -% category codes $11$ (letter) and $12$ (other) so -% that control sequences are not recognized as such.} -% But this is not always possible (when there are unmatched -% curly braces in the rest of the line). -% Besides, we think that this is not worth the effort: -% After a \texttt{verbatim} or \texttt{verbatim*} environment -% a new line in the output is begun anyway, -% and an \verb?\end{comment}? can easily be put on a line by itself. -% So there is no reason why there should be any text here. -% For the benefit of the user who did put something there -% (a comment, perhaps) -% we simply issue a warning and drop them. -% The method of testing is explained in Appendix~D, p.\ 376 of -% the \TeX{}book. We use \verb?^^M? instead of the \verb?!? -% character used there -% since this is a character that cannot appear in \verb?#1?. -% The two \cs{noexpand} primitives are necessary to avoid -% expansion of active characters and macros. -% -% One extra subtlety should be noted here: remember that -% the token list we are currently building will first be -% processed by the \cs{lowercase} primitive before \TeX{} -% carries out the definitions. -% This means that the `\texttt{C}' character in the -% argument to the \cs{@warning} macro must be protected against -% being changed to `\texttt{c}'. That's the reason why we added the -% \verb?\lccode`\C=`\C? assignment above. -% We can now finish the argument to \cs{lowercase} as well as the -% group in which the category codes were changed. -% \begin{macrocode} - \def\verbatim@rescan#1#2~{\if\noexpand~\noexpand#2~\else - \@warning{Characters dropped after `\string\end{#1}'}\fi}} -% \end{macrocode} -% \end{macro} -% -% \subsubsection{The \cs{verbatiminput} command} -% -% \begin{macro}{\verbatim@in@stream} -% We begin by allocating an input stream (out of the 16 available -% input streams). -% \begin{macrocode} -\newread\verbatim@in@stream -% \end{macrocode} -% \end{macro} +% +% +% \subsubsection{Disabled interface macros} % -% \begin{macro}{\verbatim@readfile} -% The macro \cs{verbatim@readfile} encloses the main loop by calls to -% the macros \cs{verbatim@startline} and \cs{verbatim@finish}, -% respectively. This makes sure -% that the user can initialize and finish the command when the file -% is empty or doesn't exist. The \texttt{verbatim} environment has a -% similar behaviour when called with an empty text. -% \begin{macrocode} -\def\verbatim@readfile#1{% - \verbatim@startline -% \end{macrocode} -% When the file is not found we issue a warning. -% \begin{macrocode} - \openin\verbatim@in@stream #1\relax - \ifeof\verbatim@in@stream - \typeout{No file #1.}% - \else -% \end{macrocode} -% At this point we pass the name of the file to \cs{@addtofilelist} -% so that its appears appears in the output of a \cs{listfiles} -% command. -% In addition, we use \cs{ProvidesFile} to make a log entry in the -% transcript file and to distinguish files read in via -% \cs{verbatiminput} from others. -% \begin{macrocode} - \@addtofilelist{#1}% - \ProvidesFile{#1}[(verbatim)]% -% \end{macrocode} -% While reading from the file it is useful to switch off the -% recognition of the end-of-line character. This saves us stripping -% off spaces from the contents of the line. +% These are macros that via the un-embedding are no longer +% used. Relevant macros are defined to to issue a warning, others just +% does not do anything. +% +% \changes{v3.8.2}{2024/01/24}{Added defaults for disabled macros} +% Macros for enabling marking tabs in verbatim, have been +% discontinued. % \begin{macrocode} - \expandafter\endlinechar\expandafter\m@ne - \expandafter\verbatim@read@file - \expandafter\endlinechar\the\endlinechar\relax - \closein\verbatim@in@stream - \fi - \verbatim@finish +\newcommand*\tabsoff{} % defined to do nothing +\newcommand*\tabson{ + \@memwarn{As of January 2024, \string\tabson\space has been discontinued.} } + % \end{macrocode} -% \end{macro} % -% \begin{macro}{\verbatim@read@file} -% All the work is done in \cs{verbatim@read@file}. It reads the input -% file line by line and recursively calls itself until the end of -% the file. -% \begin{macrocode} -\def\verbatim@read@file{% - \read\verbatim@in@stream to\next - \ifeof\verbatim@in@stream - \else -% \end{macrocode} -% For each line we call \cs{verbatim@addtoline} with the contents of -% the line. \hskip0pt plus 3cm\penalty0\hskip0pt plus -3cm -% \cs{verbatim@processline} is called next. -% \begin{macrocode} - \expandafter\verbatim@addtoline\expandafter{\next}% - \verbatim@processline -% \end{macrocode} -% After processing the line we call \cs{verbatim@startline} to -% initialize all before we read the next line. -% \begin{macrocode} - \verbatim@startline -% \end{macrocode} -% Without \cs{expandafter} each call of \cs{verbatim@read@file} uses -% space in \TeX's input stack.\footnote{A standard \TeX\ would -% report an overflow error if you try to read a file with more than -% ca.\ 200~lines. The same error occurs if the first line of code -% in \S 390 of \textsl{``TeX: The Program''\/} is missing.} +% Code for automatic line breaking in verbatim has been discontinued. % \begin{macrocode} - \expandafter\verbatim@read@file - \fi +\newlength\verbatimindent +\newcommand*\verbatimbreakchar{} % silently does nothing as it + % needs \wrappingon to be enabled +\newcommand*\setverbatimbreak{} % never used +\newcommand*\wrappingon{ + \@memwarn{As of January 2024, \string\wrappingon\space has been discontinued.} } +\newcommand*\wrappingoff{} % defined to do nothing +\def\wrapright{} % internal macro no longer used % \end{macrocode} -% \end{macro} -% % -% \begin{macro}{\verbatiminput} -% \cs{verbatiminput} first starts a group to keep font and category -% changes local. -% Then it calls the macro \cs{verbatim@input} with additional -% arguments, depending on whether an asterisk follows. -% -% PW. I added the TAB checking code. -% \begin{macrocode} -\def\verbatiminput{\begingroup - \ift@bs - \def\verbatim@processline{\tabverbatim@processline}% - \fi - \@ifstar{\verbatim@input{\@maybeobeytabs}}% - {\verbatim@input{\frenchspacing\@vobeyspaces\@maybeobeytabs}}} -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\verbatim@input} -% \cs{verbatim@input} first checks whether the file exists, using -% the standard macro cs{IfFileExists} which leaves the name of the -% file found in \cs{@filef@und}. -% Then everything is set up as in the \cs{verbatim} macro. -% \begin{macrocode} -\def\verbatim@input#1#2{% - \IfFileExists {#2}{\@verbatim #1\relax -% \end{macrocode} -% Then it reads in the file, finishes off the \texttt{trivlist} -% environment started by \cs{@verbatim} and closes the group. -% This restores everything to its normal settings. -% \begin{macrocode} - \verbatim@readfile{\@filef@und}\endtrivlist\endgroup\@doendpe}% -% \end{macrocode} -% If the file is not found a more or less helpful message is -% printed. The final \cs{endgroup} is needed to close the group -% started in \cs{verbatiminput} above. -% \begin{macrocode} - {\typeout {No file #2.}\endgroup}} -% \end{macrocode} -% \end{macro} +% +% \subsubsection{About the \texttt{verbatim} adjustments that have been removed} % -% \textit{That completes my borrowings from \Lpack{verbatim}.} +% The adjustments PW made that we removed (in January 2024) can +% actually be patched back in using the following code and +% patches. Left here for reference. Will probably be removed at some +% point. % -% The next bunch of code implements wrapping verbatim lines so they, hopefully, -% stay within the typeblock. +% First the code needed by the patches +% \begin{verbatim} +% % extra hook to be added at the end of verbatims +% \newtoks\afterevery@verbatim +% \afterevery@verbatim={} +% % code for marking tabs using a number of spaces +% \newcount\tab@position +% \def\mem@xobeytab{% +% \typeout{\the\tab@position} +% \loop +% \toks@\expandafter{\the\toks@\@xobeysp}% +% \advance\tab@position-1 +% \ifnum\tab@position>-1 \repeat% was 0, but that never gave 4 spaces +% } +% \def\verbatim@tabexpand#1{% +% \ifx#1\@nil +% \the\toks@ +% \expandafter\par +% \else +% \ifx#1\@xobeytab +% \@xobeytab +% \else +% \toks@\expandafter{\the\toks@#1}% +% \advance\tab@position\m@ne +% \fi +% \ifnum\tab@position=0 \tab@position\tab@size \fi +% \expandafter\verbatim@tabexpand +% \fi +% } +% \newif\ift@bs +% \def\@maybeobeytabs{}% +% % The code to enable marking tabs +% \newcommand{\tabson}[1][4]{% +% % firstly, has to be at least 1, so if less than one, we disable visible tabs +% \ifnum\@ne > #1\relax +% \typeout{#1 gives tabs off} +% \tabsoff +% \else +% \t@bstrue +% \let\@xobeytab\mem@xobeytab +% \def\tab@size{#1\relax}% +% \def\@maybeobeytabs{\@vobeytabs}% +% \fi +% } +% \newcommand{\tabsoff}{% +% \t@bsfalse +% \def\tab@size{\z@}% +% \def\@maybeobeytabs{}% +% } +% % default is off +% \tabsoff +% % \verbatim@processline is redefined to this in certain places if tabs are on +% \def\tabverbatim@processline{\tab@position\tab@size% +% \toks@{}% +% \expandafter\verbatim@tabexpand\the\verbatim@line\@nil} +% % Code for the wrapping system, \cs{raggedwrap} was moved +% % elsewhere in the code so is still there. +% \newcommand*{\wrappingon}{% +% \def\@xobeysp{~\discretionary{\verbatimbreakchar}% +% {\kern\verbatimindent}{}}% +% \def\wrapright{\raggedwrap}} +% \newcommand*{\wrappingoff}{% +% \def\@xobeysp{\leavevmode\penalty\@M\ }% +% \def\wrapright{}} +% \wrappingoff +% \end{verbatim} % -% \begin{macro}{\verbatimindent} -% \begin{macro}{\verbatimbreakchar} -% \begin{macro}{\setverbatimbreak} -% The length \cs{verbatimindent} is the distance continuation lines are indented -% from the left margin. \cs{verbatimbreakchar} is the character to indicate -% a wrapped line. -% \begin{macrocode} -\newlength{\verbatimindent} - \setlength{\verbatimindent}{3em} -\newcommand*{\verbatimbreakchar}{\char`\%} -\newcommand*{\setverbatimbreak}{% - \vspace*{-\baselineskip}% - \def\@xobeysp{~\discretionary{\verbatimbreakchar}% - {\kern\verbatimindent}{}}% -} - -% \end{macrocode} -% \end{macro} -% \end{macro} -% \end{macro} +% Next the actual patching +% \begin{verbatim} +% % % patch \@verbatim, two changes +% % firstly change leftskip into the memoir aliases +% \patchcmd\@verbatim{% +% \leftskip\@totalleftmargin\rightskip\z@% +% }{% +% \memRTLleftskip\@totalleftmargin\memRTLrightskip\z@% +% }{}{\typeout{first patch for \string\@verbatim\space failed}} +% % secondly add the wrapping code at the very end, we could probably +% % use the macro hook here +% \patchcmd\@verbatim{% +% \everypar \expandafter{\the\everypar \unpenalty}% +% }{% +% \everypar \expandafter{\the\everypar \unpenalty}% +% \wrapright\the\afterevery@verbatim% +% }{}{\typeout{second patch for \string\@verbatim\space failed}} +% +% % add tabs support for \verbatim +% \patchcmd\verbatim{\begingroup\@verbatim}{% +% \begingroup% +% \ift@bs% +% \def\verbatim@processline{\tabverbatim@processline}% +% \fi% +% \@verbatim% +% }{}{\typeout{Patch 1 for \string\verbatim\space failed}} +% % add tab support +% \patchcmd\verbatim{\@vobeyspaces}{% +% \@vobeyspaces\@maybeobeytabs% +% }{}{\typeout{Patch 2 for \string\verbatim\space failed}} +% +% \expandafter\patchcmd\expandafter{\csname verbatim*\endcsname}% +% {\begingroup\@verbatim}{% +% \begingroup% +% \ift@bs% +% \def\verbatim@processline{\tabverbatim@processline}% +% \def\@setupverbvisibletab{}% remove redef of \@xobeytab +% \fi% +% \@verbatim% +% }{}{\typeout{Patch 1 for \string\verbatim*\space failed}} +% \expandafter\patchcmd\expandafter{\csname verbatim*\endcsname}% +% {\@vobeyspaces}{% +% \@vobeyspaces\@maybeobeytabs% +% }{}{\typeout{Patch 2 for \string\verbatim*\space failed}} +% +% patches for \verbatiminput, there are 3 +% \patchcmd\verbatiminput{\begingroup\@ifstar}{% +% \begingroup% +% \ift@bs% +% \def\verbatim@processline{\tabverbatim@processline}% +% \fi% +% \@ifstar% +% }{}{\typeout{Patch 1 for \string\verbatiminput\space failed}} +% +% \patchcmd\verbatiminput{\@ifstar{\verbatim@input\relax}}{% +% \@ifstar{\verbatim@input{\@maybeobeytabs}}% +% }{}{\typeout{Patch 2 for \string\verbatiminput\space failed}} +% +% \patchcmd\verbatiminput{\frenchspacing\@vobeyspaces}{% +% \frenchspacing\@vobeyspaces\@maybeobeytabs% +% }{}{\typeout{Patch 3 for \string\verbatiminput\space failed}} +% +% \end{verbatim} +% % -% \begin{macro}{\raggedwrap} -% \begin{macro}{\wrappingon} -% \begin{macro}{\wrapright} -% \begin{macro}{\wrappingoff} -% \cs{wrappingon} and \cs{wrappingoff} enable/prohibit wrapping. The -% default is \cs{wrappingoff}. -% -% The macro -% \cs{wrapright} is used to set paragraph skips; without raggedright the -% lines -% may break at the first space \emph{outside} the text area. However, -% Paul (\url{paulaugust2003@yahoo.com}) found that wrapped verbatims -% in a list (e.g., \texttt{itemize}) were not indented although regular -% verbatims were indented. \cs{raggedwrap} is a variation on \cs{raggedright} -% (\cs{leftskip} is set to \cs{@totalleftmargin} instead of 0pt), and seems -% to have fixed the problem with the original code which used -% \cs{raggedright}. -% \changes{v1.61803}{2008/01/30}{Added \cs{raggedwrap} (mempatch v4.4)} -% \changes{v1.61803398}{2009/07/18}{Added bidi support to \cs{raggedwrap}} -% \begin{macrocode} -\newcommand*{\raggedwrap}{% - \@rightskip\@flushglue -%%% \rightskip\@rightskip - \memRTLrightskip\@rightskip -%%% \leftskip\@totalleftmargin - \memRTLleftskip\@totalleftmargin - \parindent\ragrparindent} -\newcommand*{\wrappingon}{% - \def\@xobeysp{~\discretionary{\verbatimbreakchar}% - {\kern\verbatimindent}{}}% - \def\wrapright{\raggedwrap}} -\newcommand*{\wrappingoff}{% - \def\@xobeysp{\leavevmode\penalty\@M\ }% - \def\wrapright{}} -\wrappingoff - -% \end{macrocode} -% \end{macro} -% \end{macro} -% \end{macro} -% \end{macro} % % +% ^^A % All the code in this section was added for version 1.2 of the class. +% ^^A % \changes{v1.2}{2002/07/27}{Section `Verbatims, boxes and files' added} +% ^^A % +% ^^A % \subsection{Modified version of the verbatim package} +% ^^A % +% ^^A % \noindent{\color{red}\rule\textwidth{5mm}} +% ^^A % +% ^^A % Much of this is from the \Lpack{verbatim} package code~\cite{VERBATIM}. +% ^^A % Unless indicated otherwise, the code and commentary is from that +% ^^A % package. +% ^^A % +% ^^A % +% ^^A % \subsubsection{Preliminaries} +% ^^A % +% ^^A % \begin{macro}{\every@verbatim} +% ^^A % \begin{macro}{\afterevery@verbatim} +% ^^A % The hook (i.e., token register) \cs{every@verbatim} +% ^^A % is initialized to \meta{empty}. +% ^^A % +% ^^A % PW added the \cs{afterevery@verbatim} hook. +% ^^A % \begin{macrocode} +% ^^A \newtoks\every@verbatim +% ^^A \every@verbatim={} +% ^^A \newtoks\afterevery@verbatim +% ^^A \afterevery@verbatim={} +% ^^A +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % \end{macro} +% ^^A % +% ^^A % +% ^^A % \begin{macro}{\@makeother} +% ^^A % \cs{@makeother} takes as argument a character and changes +% ^^A % its category code to $12$ (other). +% ^^A % \begin{macrocode} +% ^^A \def\@makeother#1{\catcode`#112\relax} +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % +% ^^A % \begin{macro}{\@vobeyspaces} +% ^^A % The macro \cs{@vobeyspaces} causes spaces in the input +% ^^A % to be printed as spaces in the output. +% ^^A % +% ^^A % In the Nov-2023 kernel update, some changes were made to how +% ^^A % \verb|\verb| handles tabs. We need to adjust accordingly. Note +% ^^A % that it will be better to just load the \Lpack{verbatim} package +% ^^A % and make adjustments to it. The fix comes from \url{https://github.com/latex3/latex2e/issues/1160#issuecomment-1793564381}. +% ^^A % \changes{v3.8.2}{2023/11/07}{Added fix for kernel update} +% ^^A % \begin{macrocode} +% ^^A \begingroup +% ^^A \catcode`\ =\active% +% ^^A \IfFormatAtLeastTF{2023-11-01}% +% ^^A % active spaces at line beginning are absorbed as macro arguments +% ^^A {\def\x{\def\@vobeyspaces{\catcode`\ \active\let \@xobeysp\@vobeytabs}}}% +% ^^A {\def\x{\def\@vobeyspaces{\catcode`\ \active\let \@xobeysp}}}% +% ^^A % was: \def\x{\def\@vobeyspaces{\catcode`\ \active\let \@xobeysp}} +% ^^A \expandafter\endgroup\x +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % +% ^^A % \begin{macro}{\@xobeysp} +% ^^A % The macro \cs{@xobeysp} produces exactly one space in +% ^^A % the output, protected against breaking just before it. +% ^^A % (\cs{@M} is an abbreviation for the number $10000$.) +% ^^A % \begin{macrocode} +% ^^A \def\@xobeysp{\leavevmode\penalty\@M\ } +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % +% ^^A % \begin{macro}{\verbatim@line} +% ^^A % We use a newly defined token register called \cs{verbatim@line} +% ^^A % that will be used as the character buffer. +% ^^A % \begin{macrocode} +% ^^A \newtoks\verbatim@line +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % PW. I have extended the original \Lpack{verbatim} package code to handle +% ^^A % TABs within verbatims. Normally TeX replaces a TAB by either a single space or +% ^^A % ignores it altogether. For this purpose I have bits of code from the \Lpack{moreverb} +% ^^A % package~\cite{MOREVERB} for handling TABs. +% ^^A % +% ^^A % \textit{Code and commentary from moreverb.} +% ^^A % +% ^^A % We define a few auxiliary macros and counters for expanding tabs. +% ^^A % \begin{macrocode} +% ^^A \newcount\tab@position +% ^^A % \end{macrocode} +% ^^A % +% ^^A % \begin{macro}{\@xobeytab} +% ^^A % \cs{@xobeytab} puts enough spaces in to get to the next nominal +% ^^A % tab stop +% ^^A % \begin{macrocode} +% ^^A \def\@xobeytab{% +% ^^A \loop +% ^^A \toks@\expandafter{\the\toks@\@xobeysp}% +% ^^A \advance\tab@position-1 +% ^^A \ifnum\tab@position>0 \repeat +% ^^A } +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % \begin{macro}{\@vobeytabs} +% ^^A % \cs{@vobeytabs} initialises use of \cs{@xobeytab}. Needs to be +% ^^A % executed within a group, as mustn't be allowed to leak out into the +% ^^A % wide world. +% ^^A % +% ^^A % \begin{macrocode} +% ^^A \begingroup +% ^^A \catcode`\^^I=\active +% ^^A \gdef\@vobeytabs{\catcode`\^^I\active\let^^I\@xobeytab}% +% ^^A \endgroup +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % \begin{macro}{\verbatim@tabexpand} +% ^^A % \cs{verbatim@tabexpand}\marg{body of line}\cs{@nil} processes every +% ^^A % character of a line by tail recursion, counting the characters and +% ^^A % juggling things when a tab is encountered. +% ^^A % \begin{macrocode} +% ^^A \def\verbatim@tabexpand#1{% +% ^^A \ifx#1\@nil +% ^^A \the\toks@ +% ^^A \expandafter\par +% ^^A \else +% ^^A \ifx#1\@xobeytab +% ^^A \@xobeytab +% ^^A \else +% ^^A % \end{macrocode} +% ^^A % +% ^^A % We can safely put \cs{@xobeysp} into the token register, since it +% ^^A % does precisely what we need +% ^^A % \begin{macrocode} +% ^^A \toks@\expandafter{\the\toks@#1}% +% ^^A \advance\tab@position\m@ne +% ^^A \fi +% ^^A \ifnum\tab@position=0 \tab@position\tab@size \fi +% ^^A \expandafter\verbatim@tabexpand +% ^^A \fi +% ^^A } +% ^^A +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % \textit{End of code and commentary from moreverb.} +% ^^A % +% ^^A % PW. Some macros for turning tabbing on and off. +% ^^A % +% ^^A % \begin{macro}{\tabson} +% ^^A % \begin{macro}{\tabsoff} +% ^^A % \begin{macro}{\@maybeobeytabs} +% ^^A % \cs{tabson} turns tabbing on, and \cs{tabsoff} turns it off. Default +% ^^A % is no tabbing. +% ^^A % \begin{macrocode} +% ^^A \newif\ift@bs +% ^^A \newcommand{\tabson}[1][4]{% +% ^^A \ifnum\@ne > #1\relax +% ^^A \tabsoff +% ^^A \else +% ^^A \t@bstrue +% ^^A \def\tab@size{#1\relax}% +% ^^A \def\@maybeobeytabs{\@vobeytabs}% +% ^^A \fi +% ^^A } +% ^^A \newcommand{\tabsoff}{% +% ^^A \t@bsfalse +% ^^A \def\tab@size{\z@}% +% ^^A \def\@maybeobeytabs{}% +% ^^A } +% ^^A \tabsoff +% ^^A +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % \end{macro} +% ^^A % \end{macro} +% ^^A % +% ^^A % \begin{macro}{\tabverbatim@processline} +% ^^A % Process a line with TABs (extracted from \Lpack{moreverb}). +% ^^A % \begin{macrocode} +% ^^A \def\tabverbatim@processline{\tab@position\tab@size +% ^^A \toks@{}% +% ^^A \expandafter\verbatim@tabexpand\the\verbatim@line\@nil} +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % \begin{macro}{\notabverbatim@processline} +% ^^A % Processes a line ignoring TABs (this is the original \Lpack{verbatim} +% ^^A % package definition of \cs{verbatim@processline}). +% ^^A % \begin{macrocode} +% ^^A \def\notabverbatim@processline{\the\verbatim@line\par} +% ^^A +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % \textit{We are now back to the \Lpack{verbatim} code.} +% ^^A % +% ^^A % The following four macros are defined globally in a way suitable for +% ^^A % the \texttt{verbatim} and \texttt{verbatim*} environments. +% ^^A % \begin{macro}{\verbatim@startline} +% ^^A % \begin{macro}{\verbatim@addtoline} +% ^^A % \begin{macro}{\verbatim@processline} +% ^^A % \cs{verbatim@startline} initializes processing of a line +% ^^A % by emptying the character buffer (\cs{verbatim@line}). +% ^^A % \begin{macrocode} +% ^^A \def\verbatim@startline{\verbatim@line{}} +% ^^A % \end{macrocode} +% ^^A % \cs{verbatim@addtoline} adds the tokens in its argument +% ^^A % to our buffer register \cs{verbatim@line} without expanding +% ^^A % them. +% ^^A % \begin{macrocode} +% ^^A \def\verbatim@addtoline#1{% +% ^^A \verbatim@line\expandafter{\the\verbatim@line#1}} +% ^^A % \end{macrocode} +% ^^A % Processing a line inside a \texttt{verbatim} or \texttt{verbatim*} +% ^^A % environment means printing it. +% ^^A % Ending the line means that we have to begin a new paragraph. +% ^^A % We use \cs{par} for this purpose. Note that \cs{par} +% ^^A % is redefined in \cs{@verbatim} to force \TeX{} into horizontal +% ^^A % mode and to insert an empty box so that empty lines in the input +% ^^A % do appear in the output. +% ^^A % (PW changed next line from \\ +% ^^A % \verb?\def\verbatim@processline{\the\verbatim@line\par}? +% ^^A % \begin{macrocode} +% ^^A \def\verbatim@processline{\notabverbatim@processline} +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % \end{macro} +% ^^A % \end{macro} +% ^^A % +% ^^A % \begin{macro}{\verbatim@finish} +% ^^A % As a default, \cs{verbatim@finish} processes the remaining +% ^^A % characters. +% ^^A % When this macro is called we are facing the following problem: +% ^^A % when the \verb?\end{verbatim}? +% ^^A % command is encountered \cs{verbatim@processline} is called +% ^^A % to process the characters preceding the command on the same +% ^^A % line. If there are none, an empty line would be output if we +% ^^A % did not check for this case. +% ^^A % +% ^^A % If the line is empty \verb?\the\verbatim@line? expands to +% ^^A % nothing. To test this we use a trick similar to that on p.\ 376 +% ^^A % of the \TeX{}book, but with \verb?$?\ldots\verb?|$? instead of +% ^^A % the \verb?!? tokens. These \verb?$? tokens can never have the same +% ^^A % category code as a \verb?$? token that might possibly appear in the +% ^^A % token register \cs{verbatim@line}, as such a token will always have +% ^^A % been read with category code $12$ (other). +% ^^A % Note that \cs{ifcat} expands the following tokens so that +% ^^A % \verb?\the\verbatim@line? is replaced by the accumulated +% ^^A % characters +% ^^A % \begin{macrocode} +% ^^A \def\verbatim@finish{\ifcat$\the\verbatim@line$\else +% ^^A \verbatim@processline\fi} +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % +% ^^A % \subsubsection{The \texttt{verbatim} and \texttt{verbatim*} environments} +% ^^A % +% ^^A % \begin{macro}{\verbatim@font} +% ^^A % We start by defining the macro \cs{verbatim@font} that is +% ^^A % to select the font and to set font-dependent parameters. +% ^^A % Then we go through \cs{verbatim@nolig@list} to avoid +% ^^A % certain ligatures. +% ^^A % \cs{verbatim@nolig@list} is a macro defined in the \LaTeXe{} kernel +% ^^A % to expand to +% ^^A % \begin{verbatim} +% ^^A % \do\`\do\<\do\>\do\,\do\'\do\- +% ^^A % \end{verbatim} +% ^^A % All the characters in this list can be part of a ligature in some +% ^^A % font or other. +% ^^A % +% ^^A % PW. This is the original version which I'm going to replace. +% ^^A % \begin{verbatim} +% ^^A % \def\verbatim@font{\normalfont\ttfamily +% ^^A % \hyphenchar\font\m@ne +% ^^A % \let\do\do@noligs +% ^^A % \verbatim@nolig@list} +% ^^A % \end{verbatim} +% ^^A % Actually the kernel defines the macro \verb+\@noligs+ which just +% ^^A % runs the last two lines of the \verb+\verbatim@font+ above. As other +% ^^A % package may add stuff to \verb+\@noligs+, we will use that instead. +% ^^A % \end{macro} +% ^^A % +% ^^A % \begin{macro}{\setverbatimfont} +% ^^A % \begin{macro}{\m@mverbfont} +% ^^A % \begin{macro}{\verbatim@font} +% ^^A % User level handle for changing the font used for verbatim text. +% ^^A % \changes{v1.61803398}{2009/09/10}{Changed the last two lines of +% ^^A % \cs{verbatim@font} into using \cs{@noligs} instead. This fixes +% ^^A % problem with upquote.} +% ^^A % \begin{macrocode} +% ^^A \newcommand{\setverbatimfont}[1]{\def\m@mverbfont{#1}} +% ^^A \setverbatimfont{\normalfont\ttfamily} +% ^^A +% ^^A \def\verbatim@font{\m@mverbfont +% ^^A \hyphenchar\font\m@ne +% ^^A \@noligs} +% ^^A +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % \end{macro} +% ^^A % \end{macro} +% ^^A % +% ^^A % +% ^^A % \begin{macro}{\@verbatim} +% ^^A % The macro \cs{@verbatim} sets up things properly. +% ^^A % First of all, the tokens of the \cs{every@verbatim} hook +% ^^A % are inserted. +% ^^A % Then a \texttt{trivlist} environment is started and its first +% ^^A % \cs{item} command inserted. +% ^^A % Each line of the \texttt{verbatim} or \texttt{verbatim*} +% ^^A % environment will be treated as a separate paragraph. +% ^^A % \changes{v1.61803398}{2009/07/18}{Added bidi support to \cs{@verbatim}} +% ^^A % \begin{macrocode} +% ^^A \def\@verbatim{\the\every@verbatim +% ^^A \trivlist \item \relax +% ^^A % \end{macrocode} +% ^^A % The following extra vertical space is for compatibility with the +% ^^A % \LaTeX kernel: otherwise, using the \Lpack{verbatim} package changes +% ^^A % the vertical spacing of a \texttt{verbatim} environment nested within a +% ^^A % \texttt{quote} environment. +% ^^A % \begin{macrocode} +% ^^A \if@minipage\else\vskip\parskip\fi +% ^^A % \end{macrocode} +% ^^A % The paragraph parameters are set appropriately: +% ^^A % the penalty at the beginning of the environment, +% ^^A % left and right margins, paragraph indentation, the glue to +% ^^A % fill the last line, and the vertical space between paragraphs. +% ^^A % The latter space has to be zero since we do not want to add +% ^^A % extra space between lines. +% ^^A % \begin{macrocode} +% ^^A \@beginparpenalty \predisplaypenalty +% ^^A %%% \leftskip\@totalleftmargin\rightskip\z@ +% ^^A \memRTLleftskip\@totalleftmargin\memRTLrightskip\z@ +% ^^A \parindent\z@\parfillskip\@flushglue\parskip\z@ +% ^^A % \end{macrocode} +% ^^A % There's one point to make here: +% ^^A % the \texttt{list} environment uses \TeX's \cs{parshape} +% ^^A % primitive to get a special indentation for the first line +% ^^A % of the list. +% ^^A % If the list begins with a \texttt{verbatim} environment +% ^^A % this \cs{parshape} is still in effect. +% ^^A % Therefore we have to reset this internal parameter explicitly. +% ^^A % We could do this by assigning $0$ to \cs{parshape}. +% ^^A % However, there is a simpler way to achieve this: +% ^^A % we simply tell \TeX{} to start a new paragraph. +% ^^A % As is explained on p.~103 of the \TeX{}book, this resets +% ^^A % \cs{parshape} to zero. +% ^^A % \begin{macrocode} +% ^^A \@@par +% ^^A % \end{macrocode} +% ^^A % We now ensure that \cs{par} has the correct definition, +% ^^A % namely to force \TeX{} into horizontal mode +% ^^A % and to include an empty box. +% ^^A % This is to ensure that empty lines do appear in the output. +% ^^A % Afterwards, we insert the \cs{interlinepenalty} since \TeX{} +% ^^A % does not add a penalty between paragraphs (here: lines) +% ^^A % by its own initiative. Otherwise a \texttt{verbatim} environment +% ^^A % could be broken across pages even if a \cs{samepage} +% ^^A % declaration were present. +% ^^A % +% ^^A % However, in a top-aligned minipage, this will result in an extra +% ^^A % empty line added at the top. Therefore, a slightly more +% ^^A % complicated construct is necessary. +% ^^A % One of the important things here is the inclusion of +% ^^A % \cs{leavevmode} as the first macro in the first line, for example, +% ^^A % a blank verbatim line is the first thing in a list item. +% ^^A % \begin{macrocode} +% ^^A \def\par{% +% ^^A \if@tempswa +% ^^A \leavevmode\null\@@par\penalty\interlinepenalty +% ^^A \else +% ^^A \@tempswatrue +% ^^A \ifhmode\@@par\penalty\interlinepenalty\fi +% ^^A \fi}% +% ^^A % \end{macrocode} +% ^^A % But to avoid an error message when the environment +% ^^A % doesn't contain any text, we redefine \cs{@noitemerr} +% ^^A % which will in this case be called by \cs{endtrivlist}. +% ^^A % \begin{macrocode} +% ^^A \def\@noitemerr{\@warning{No verbatim text}}% +% ^^A % \end{macrocode} +% ^^A % Now we call \cs{obeylines} to make the end of line character +% ^^A % active, +% ^^A % \begin{macrocode} +% ^^A \obeylines +% ^^A % \end{macrocode} +% ^^A % change the category code of all special characters, +% ^^A % to $12$ (other). +% ^^A % \begin{macrocode} +% ^^A \let\do\@makeother \dospecials +% ^^A % \end{macrocode} +% ^^A % and switch to the font to be used. +% ^^A % \begin{macrocode} +% ^^A \verbatim@font +% ^^A % \end{macrocode} +% ^^A % To avoid a breakpoint after the labels box, we remove the penalty +% ^^A % put there by the list macros: another use of \cs{unpenalty}! +% ^^A % \begin{macrocode} +% ^^A \everypar \expandafter{\the\everypar \unpenalty}% +% ^^A % \end{macrocode} +% ^^A % PW added next code at end of \cs{@verbatim}. +% ^^A % \begin{macrocode} +% ^^A \wrapright\the\afterevery@verbatim} +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % +% ^^A % \begin{macro}{\verbatim} +% ^^A % \begin{macro}{\verbatim*} +% ^^A % Now we define the toplevel macros. +% ^^A % \cs{verbatim} is slightly changed: +% ^^A % after setting up things properly it calls +% ^^A % \cs{verbatim@start}. +% ^^A % This is done inside a group, so that \cs{verbatim} can be used +% ^^A % directly, without \cs{begin}. +% ^^A % +% ^^A % PW. The following is the original code, but I want a version of +% ^^A % \texttt{verbatim} that recognises TABs. +% ^^A % \begin{verbatim} +% ^^A % \begin{macrocode} +% ^^A % \def\verbatim{% +% ^^A % \begingroup\@verbatim \frenchspacing\@vobeyspaces +% ^^A % \verbatim@start} +% ^^A % \end{macrocode} +% ^^A % \cs{verbatim*} is defined accordingly. +% ^^A % \begin{macrocode} +% ^^A % \@namedef{verbatim*}{\begingroup\@verbatim\verbatim@start} +% ^^A % \def\endverbatim{\endtrivlist\endgroup} +% ^^A % \expandafter\let\csname endverbatim*\endcsname=\endverbatim +% ^^A % \end{macrocode} +% ^^A % \end{verbatim} +% ^^A % +% ^^A % PW. My code for these is a modified version of the original \Lpack{verbatim} +% ^^A % code. +% ^^A % \begin{macrocode} +% ^^A \def\verbatim{\begingroup +% ^^A \ift@bs +% ^^A \def\verbatim@processline{\tabverbatim@processline}% +% ^^A \fi +% ^^A \@verbatim \frenchspacing\@vobeyspaces\@maybeobeytabs\verbatim@start} +% ^^A \@namedef{verbatim*}{\begingroup +% ^^A \ift@bs +% ^^A \def\verbatim@processline{\tabverbatim@processline}% +% ^^A \fi +% ^^A \@verbatim\@maybeobeytabs\verbatim@start} +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % \end{macro} +% ^^A % +% ^^A % +% ^^A % \begin{macro}{\endverbatim} +% ^^A % \begin{macro}{\endverbatim*} +% ^^A % To end the \texttt{verbatim} and \texttt{verbatim*} +% ^^A % environments it is only necessary to finish the +% ^^A % \texttt{trivlist} environment started in \cs{@verbatim} and +% ^^A % close the corresponding group, and handle\footnote{Noted by +% ^^A % Zarko Cucej (\url{zarko.cucej@uni-mb.si}).} following (non-) paragraph, +% ^^A % by using \cs{@doendpe}. +% ^^A % \changes{v1.4}{2003/11/22}{Added \cs{@doendpe} to \cs{endverbatim} +% ^^A % (from patch v1.8)} +% ^^A % \changes{v2.0a}{2004/03/01}{Refixed \cs{endverbatim}} +% ^^A % \begin{macrocode} +% ^^A \def\endverbatim{\endtrivlist\endgroup\@doendpe} +% ^^A \@namelet{endverbatim*}\endverbatim +% ^^A +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % \end{macro} +% ^^A % +% ^^A % For abnormal \cs{parskip}s the NTG class included the following, but I'm +% ^^A % not sure if it is relevant here, but if it is just how it should be included. +% ^^A % \begin{verbatim} +% ^^A % From NTG, where it is a \cs{def} +% ^^A % \providecommand*{\verbatim}{% +% ^^A % \topsep=-0.5\parskip +% ^^A % \@verbatim +% ^^A % \frenchspacing\@vobeyspaces \@xverbatim} +% ^^A % \end{verbatim} +% ^^A % +% ^^A % +% ^^A % \subsubsection{The \texttt{comment} environment} +% ^^A % +% ^^A % The \cs{comment} macro is similar to \cs{verbatim*}. +% ^^A % However, we do not need to switch fonts or set special +% ^^A % formatting parameters such as \cs{parindent} or \cs{parskip}. +% ^^A % We need only set the category code of all special characters +% ^^A % to $12$ (other) and that of \verb?^^M? (the end of line character) +% ^^A % to $13$ (active). +% ^^A % The latter is needed for macro parameter delimiter matching in +% ^^A % the internal macros defined below. +% ^^A % In contrast to the default definitions used by the +% ^^A % \cs{verbatim} and \cs{verbatim*} macros, +% ^^A % we define \cs{verbatim@addtoline} to throw away its argument +% ^^A % and \cs{verbatim@processline}, \cs{verbatim@startline}, +% ^^A % and \cs{verbatim@finish} to act as no-ops. +% ^^A % Then we call \cs{verbatim@}. +% ^^A % But the first thing we do is to call \cs{@bsphack} so that +% ^^A % this environment has no influence whatsoever upon the spacing. +% ^^A % +% ^^A % PW: This is the original code for the \texttt{comment} environment, +% ^^A % which I'm going to change. +% ^^A % \begin{verbatim} +% ^^A % \def\comment{\@bsphack +% ^^A % \let\do\@makeother\dospecials\catcode`\^^M\active +% ^^A % \let\verbatim@startline\relax +% ^^A % \let\verbatim@addtoline\@gobble +% ^^A % \let\verbatim@processline\relax +% ^^A % \let\verbatim@finish\relax +% ^^A % \verbatim@} +% ^^A % \end{verbatim} +% ^^A % \cs{endcomment} is very simple: it only calls +% ^^A % \cs{@esphack} to take care of the spacing. +% ^^A % The \cs{end} macro closes the group and therefore takes care +% ^^A % of restoring everything we changed. +% ^^A % \begin{verbatim} +% ^^A % \let\endcomment=\@esphack +% ^^A % \end{verbatim} +% ^^A % +% ^^A % PW: The remainder of this section is my code. +% ^^A % +% ^^A % \begin{macro}{\setupcomment} +% ^^A % \cs{setupcomment} does all the \cs{let}s in the original \cs{comment} code. +% ^^A % \begin{macrocode} +% ^^A \newcommand{\setupcomment}{% +% ^^A \let\do\@makeother\dospecials\catcode`\^^M\active +% ^^A \let\verbatim@startline\relax +% ^^A \let\verbatim@addtoline\@gobble +% ^^A \let\verbatim@processline\relax +% ^^A \let\verbatim@finish\relax} +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % The macros below do no checking to see if something has (not) been defined +% ^^A % previously. It's `user beware' time. +% ^^A % +% ^^A % \begin{macro}{\newcomment} +% ^^A % \cs{newcomment}\marg{name} creates a new comment environment called +% ^^A % \meta{name}. This is a generalisation of the original comment code. +% ^^A % \begin{macrocode} +% ^^A \newcommand{\newcomment}[1]{% +% ^^A \expandafter\def\csname #1\endcsname{\@bsphack\setupcomment\verbatim@}% +% ^^A \expandafter\let\csname end#1\endcsname=\@esphack} +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % \begin{macro}{\commentsoff} +% ^^A % \cs{commentsoff}\marg{name} switches off the \meta{name} comment +% ^^A % environment by defining the relevent macros to do nothing. +% ^^A % \begin{macrocode} +% ^^A \newcommand{\commentsoff}[1]{% +% ^^A \expandafter\def\csname #1\endcsname{}% +% ^^A \expandafter\def\csname end#1\endcsname{}} +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % \begin{macro}{\commentson} +% ^^A % \cs{commentson}\marg{name} switches on the \meta{name} comment +% ^^A % environment. It has to do the same things as \cs{newcomment} does, +% ^^A % so let \cs{newcomment} do the work. +% ^^A % \begin{macrocode} +% ^^A \newcommand{\commentson}[1]{\newcomment{#1}} +% ^^A +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % We had better supply the \texttt{comment} environment, as promised. +% ^^A % \begin{macrocode} +% ^^A \newcomment{comment} +% ^^A +% ^^A % \end{macrocode} +% ^^A % +% ^^A % PW: That is the end of my changes and extensions to the original +% ^^A % \texttt{comment} environment code. +% ^^A % +% ^^A % +% ^^A % \subsubsection{The main loop} +% ^^A % +% ^^A % Here comes the tricky part: +% ^^A % During the definition of the macros we need to use the special +% ^^A % characters \verb?\?, \verb?{?, and \verb?}? not only with their +% ^^A % normal category codes, +% ^^A % but also with category code $12$ (other). +% ^^A % We achieve this by the following trick: +% ^^A % first we tell \TeX{} that \verb?\?, \verb?{?, and \verb?}? +% ^^A % are the lowercase versions of \verb?!?, \verb?[?, and \verb?]?. +% ^^A % Then we replace every occurrence of \verb?\?, \verb?{?, and \verb?}? +% ^^A % that should be read with category code $12$ by \verb?!?, \verb?[?, +% ^^A % and \verb?]?, respectively, +% ^^A % and give the whole list of tokens to \cs{lowercase}, +% ^^A % knowing that category codes are not altered by this primitive! +% ^^A % +% ^^A % But first we have ensure that +% ^^A % \verb?!?, \verb?[?, and \verb?]? themselves have +% ^^A % the correct category code! +% ^^A % To allow special settings of these codes we hide their setting in +% ^^A % the macro \cs{vrb@catcodes}. If it is already defined our new +% ^^A % definition is skipped. +% ^^A % \begin{macrocode} +% ^^A \@ifundefined{vrb@catcodes}% +% ^^A {\def\vrb@catcodes{% +% ^^A \catcode`\!12\catcode`\[12\catcode`\]12}}{} +% ^^A % \end{macrocode} +% ^^A % This trick allows us to use this code for applications where other +% ^^A % category codes are in effect. +% ^^A % +% ^^A % We start a group to keep the category code changes local. +% ^^A % \begin{macrocode} +% ^^A \begingroup +% ^^A \vrb@catcodes +% ^^A \lccode`\!=`\\ \lccode`\[=`\{ \lccode`\]=`\} +% ^^A % \end{macrocode} +% ^^A % We also need the end-of-line character \verb?^^M?, +% ^^A % as an active character. +% ^^A % If we were to simply write \verb?\catcode`\^^M=\active? +% ^^A % then we would get an unwanted active end of line character +% ^^A % at the end of every line of the following macro definitions. +% ^^A % Therefore we use the same trick as above: +% ^^A % we write a tilde \verb?~? instead of \verb?^^M? and +% ^^A % pretend that the +% ^^A % latter is the lowercase variant of the former. +% ^^A % Thus we have to ensure now that the tilde character has +% ^^A % category code $13$ (active). +% ^^A % \begin{macrocode} +% ^^A \catcode`\~=\active \lccode`\~=`\^^M +% ^^A % \end{macrocode} +% ^^A % The use of the \cs{lowercase} primitive leads to one problem: +% ^^A % the uppercase character `\texttt{C}' needs to be used in the +% ^^A % code below and its case must be preserved. +% ^^A % So we add the command: +% ^^A % \begin{macrocode} +% ^^A \lccode`\C=`\C +% ^^A % \end{macrocode} +% ^^A % Now we start the token list passed to \cs{lowercase}. +% ^^A % We use the following little trick (proposed by Bernd Raichle): +% ^^A % The very first token in the token list we give to \cs{lowercase} is +% ^^A % the \cs{endgroup} primitive. This means that it is processed by +% ^^A % \TeX{} immediately after \cs{lowercase} has finished its operation, +% ^^A % thus ending the group started by \cs{begingroup} above. This avoids +% ^^A % the global definition of all macros. +% ^^A % \begin{macrocode} +% ^^A \lowercase{\endgroup +% ^^A % \end{macrocode} +% ^^A % \begin{macro}{\verbatim@start} +% ^^A % The purpose of \cs{verbatim@start} is to check whether there +% ^^A % are any characters on the same line as the \verb?\begin{verbatim}? +% ^^A % and to pretend that they were on a line by themselves. +% ^^A % On the other hand, if there are no characters remaining +% ^^A % on the current line we shall just find an end of line character. +% ^^A % \cs{verbatim@start} performs its task by first grabbing the +% ^^A % following character (its argument). +% ^^A % This argument is then compared to an active \verb?^^M?, +% ^^A % the end of line character. +% ^^A % \begin{macrocode} +% ^^A \def\verbatim@start#1{% +% ^^A \verbatim@startline +% ^^A \if\noexpand#1\noexpand~% +% ^^A % \end{macrocode} +% ^^A % If this is true we transfer control to \cs{verbatim@} +% ^^A % to process the next line. We use +% ^^A % \cs{next} as the macro which will continue the work. +% ^^A % \begin{macrocode} +% ^^A \let\next\verbatim@ +% ^^A % \end{macrocode} +% ^^A % Otherwise, we define \cs{next} to expand to a call +% ^^A % to \cs{verbatim@} followed by the character just +% ^^A % read so that it is reinserted into the text. +% ^^A % This means that those characters remaining on this line +% ^^A % are handled as if they formed a line by themselves. +% ^^A % \begin{macrocode} +% ^^A \else \def\next{\verbatim@#1}\fi +% ^^A % \end{macrocode} +% ^^A % Finally we call \cs{next}. +% ^^A % \begin{macrocode} +% ^^A \next}% +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % \begin{macro}{\verbatim@} +% ^^A % The three macros \cs{verbatim@}, \cs{verbatim@@}, +% ^^A % and \cs{verbatim@@@} form the ``main loop'' of the +% ^^A % \texttt{verbatim} environment. +% ^^A % The purpose of \cs{verbatim@} is to read exactly one line +% ^^A % of input. +% ^^A % \cs{verbatim@@} and \cs{verbatim@@@} work together to +% ^^A % find out whether the four characters +% ^^A % \cs{end} (all with category code $12$ (other)) occur in that +% ^^A % line. +% ^^A % If so, \cs{verbatim@@@} will call +% ^^A % \cs{verbatim@test} to check whether this \cs{end} is +% ^^A % part of \verb?\end{verbatim}? and will terminate the environment +% ^^A % if this is the case. +% ^^A % Otherwise we continue as if nothing had happened. +% ^^A % So let's have a look at the definition of \cs{verbatim@}: +% ^^A % \begin{macrocode} +% ^^A \def\verbatim@#1~{\verbatim@@#1!end\@nil}% +% ^^A % \end{macrocode} +% ^^A % Note that the \verb?!? character will have been replaced by a +% ^^A % \verb?\? with category code $12$ (other) by the \cs{lowercase} +% ^^A % primitive governing this code before the definition of this +% ^^A % macro actually takes place. +% ^^A % That means that +% ^^A % it takes the line, puts \cs{end} (four character tokens) +% ^^A % and \cs{@nil} (one control sequence token) as a +% ^^A % delimiter behind it, and +% ^^A % then calls \cs{verbatim@@}. +% ^^A % \end{macro} +% ^^A % +% ^^A % \begin{macro}{\verbatim@@} +% ^^A % \cs{verbatim@@} takes everything up to the next occurrence of +% ^^A % the four characters \cs{end} as its argument. +% ^^A % \begin{macrocode} +% ^^A \def\verbatim@@#1!end{% +% ^^A % \end{macrocode} +% ^^A % That means: if they do not occur in the original line, then +% ^^A % argument \verb?#1? is the +% ^^A % whole input line, and \cs{@nil} is the next token +% ^^A % to be processed. +% ^^A % However, if the four characters \cs{end} are part of the +% ^^A % original line, then +% ^^A % \verb?#1? consists of the characters in front of \cs{end}, +% ^^A % and the next token is the following character (always remember +% ^^A % that the line was lengthened by five tokens). +% ^^A % Whatever \verb?#1? may be, it is verbatim text, +% ^^A % so \verb?#1? is added to the line currently built. +% ^^A % \begin{macrocode} +% ^^A \verbatim@addtoline{#1}% +% ^^A % \end{macrocode} +% ^^A % The next token in the input stream +% ^^A % is of special interest to us. +% ^^A % Therefore \cs{futurelet} defines \cs{next} to be equal +% ^^A % to it before calling \cs{verbatim@@@}. +% ^^A % \begin{macrocode} +% ^^A \futurelet\next\verbatim@@@}% +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % \begin{macro}{\verbatim@@@} +% ^^A % \cs{verbatim@@@} will now read the rest of the tokens on +% ^^A % the current line, +% ^^A % up to the final \cs{@nil} token. +% ^^A % \begin{macrocode} +% ^^A \def\verbatim@@@#1\@nil{% +% ^^A % \end{macrocode} +% ^^A % If the first of the above two cases occurred, i.e.\ no +% ^^A % \cs{end} characters were on that line, \verb?#1? is empty +% ^^A % and \cs{next} is equal to \cs{@nil}. +% ^^A % This is easily checked. +% ^^A % \begin{macrocode} +% ^^A \ifx\next\@nil +% ^^A % \end{macrocode} +% ^^A % If so, this was a simple line. +% ^^A % We finish it by processing the line we accumulated so far. +% ^^A % Then we prepare to read the next line. +% ^^A % \begin{macrocode} +% ^^A \verbatim@processline +% ^^A \verbatim@startline +% ^^A \let\next\verbatim@ +% ^^A % \end{macrocode} +% ^^A % Otherwise we have to check what follows these \cs{end} +% ^^A % tokens. +% ^^A % \begin{macrocode} +% ^^A \else +% ^^A % \end{macrocode} +% ^^A % Before we continue, it's a good idea to stop for a moment +% ^^A % and remember where we are: +% ^^A % We have just read the four character tokens \cs{end} +% ^^A % and must now check whether the name of the environment (surrounded +% ^^A % by braces) follows. +% ^^A % To this end we define a macro called \cs{@tempa} +% ^^A % that reads exactly one character and decides what to do next. +% ^^A % This macro should do the following: skip spaces until +% ^^A % it encounters either a left brace or the end of the line. +% ^^A % But it is important to remember which characters are skipped. +% ^^A % The \cs{end}\meta{optional spaces}\verb?{? characters +% ^^A % may be part of the verbatim text, i.e.\ these characters +% ^^A % must be printed. +% ^^A % +% ^^A % Assume for example that the current line contains +% ^^A % \begin{verbatim*} +% ^^A % \end {AVeryLongEnvironmentName} +% ^^A %\end{verbatim*} +% ^^A % As we shall soon see, the scanning mechanism implemented here +% ^^A % will not find out that this is text to be printed until +% ^^A % it has read the right brace. +% ^^A % Therefore we need a way to accumulate the characters read +% ^^A % so that we can reinsert them if necessary. +% ^^A % The token register \cs{@temptokena} is used for this purpose. +% ^^A % +% ^^A % Before we do this we have to get rid of the superfluous +% ^^A % \cs{end} tokens at the end of the line. +% ^^A % To this end we define a temporary macro whose argument +% ^^A % is delimited by \verb?\end\@nil? (four character tokens +% ^^A % and one control sequence token) to be used below +% ^^A % on the rest of the line, after appending a \cs{@nil} token to it. +% ^^A % (Note that this token can never appear in \verb?#1?.) +% ^^A % We use the following definition of +% ^^A % \cs{@tempa} to get the rest of the line (after the first +% ^^A % \cs{end}). +% ^^A % \begin{macrocode} +% ^^A \def\@tempa##1!end\@nil{##1}% +% ^^A % \end{macrocode} +% ^^A % We mentioned already that we use token register +% ^^A % \cs{@temptokena} +% ^^A % to remember the characters we skip, in case we need them again. +% ^^A % We initialize this with the \cs{end} we have thrown away +% ^^A % in the call to \cs{@tempa}. +% ^^A % \begin{macrocode} +% ^^A \@temptokena{!end}% +% ^^A % \end{macrocode} +% ^^A % We shall now call \cs{verbatim@test} +% ^^A % to process the characters +% ^^A % remaining on the current line. +% ^^A % But wait a moment: we cannot simply call this macro +% ^^A % since we have already read the whole line. +% ^^A % Therefore we have to first expand the macro \cs{@tempa} to insert +% ^^A % them again after the \cs{verbatim@test} token. +% ^^A % A \verb?^^M? character is appended to denote the end of the line. +% ^^A % (Remember that this character comes disguised as a tilde.) +% ^^A % \begin{macrocode} +% ^^A \def\next{\expandafter\verbatim@test\@tempa#1\@nil~}% +% ^^A % \end{macrocode} +% ^^A % That's almost all, but we still have to +% ^^A % now call \cs{next} to do the work. +% ^^A % \begin{macrocode} +% ^^A \fi \next}% +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % +% ^^A % \begin{macro}{\verbatim@test} +% ^^A % We define \cs{verbatim@test} to investigate every token +% ^^A % in turn. +% ^^A % \begin{macrocode} +% ^^A \def\verbatim@test#1{% +% ^^A % \end{macrocode} +% ^^A % First of all we set \cs{next} equal to \cs{verbatim@test} +% ^^A % in case this macro must call itself recursively in order to +% ^^A % skip spaces. +% ^^A % \begin{macrocode} +% ^^A \let\next\verbatim@test +% ^^A % \end{macrocode} +% ^^A % We have to distinguish four cases: +% ^^A % \begin{enumerate} +% ^^A % \item The next token is a \verb?^^M?, i.e.\ we reached +% ^^A % the end of the line. That means that nothing +% ^^A % special was found. +% ^^A % Note that we use \cs{if} for the following +% ^^A % comparisons so that the category code of the +% ^^A % characters is irrelevant. +% ^^A % \begin{macrocode} +% ^^A \if\noexpand#1\noexpand~% +% ^^A % \end{macrocode} +% ^^A % We add the characters accumulated in token register +% ^^A % \cs{@temptokena} to the current line. Since +% ^^A % \cs{verbatim@addtoline} does not expand its argument, +% ^^A % we have to do the expansion at this point. Then we +% ^^A % \cs{let} \cs{next} equal to \cs{verbatim@} +% ^^A % to prepare to read the next line. +% ^^A % \begin{macrocode} +% ^^A \expandafter\verbatim@addtoline +% ^^A \expandafter{\the\@temptokena}% +% ^^A \verbatim@processline +% ^^A \verbatim@startline +% ^^A \let\next\verbatim@ +% ^^A % \end{macrocode} +% ^^A % \item A space character follows. +% ^^A % This is allowed, so we add it to \cs{@temptokena} +% ^^A % and continue. +% ^^A % \begin{macrocode} +% ^^A \else \if\noexpand#1 +% ^^A \@temptokena\expandafter{\the\@temptokena#1}% +% ^^A % \end{macrocode} +% ^^A % \item An open brace follows. +% ^^A % This is the most interesting case. +% ^^A % We must now collect characters until we read the closing +% ^^A % brace and check whether they form the environment name. +% ^^A % This will be done by \cs{verbatim@testend}, so here +% ^^A % we let \cs{next} equal this macro. +% ^^A % Again we will process the rest of the line, character +% ^^A % by character. +% ^^A % The characters forming the name of the environment will +% ^^A % be accumulated in \cs{@tempc}. +% ^^A % We initialize this macro to expand to nothing. +% ^^A % \begin{macrocode} +% ^^A \else \if\noexpand#1\noexpand[% +% ^^A \let\@tempc\@empty +% ^^A \let\next\verbatim@testend +% ^^A % \end{macrocode} +% ^^A % Note that the \verb?[? character will be a \verb?{? when +% ^^A % this macro is defined. +% ^^A % \item Any other character means that the \cs{end} was part +% ^^A % of the verbatim text. +% ^^A % Add the characters to the current line and prepare to call +% ^^A % \cs{verbatim@} to process the rest of the line. +% ^^A % \begin{macrocode} +% ^^A \else +% ^^A \expandafter\verbatim@addtoline +% ^^A \expandafter{\the\@temptokena}% +% ^^A \def\next{\verbatim@#1}% +% ^^A \fi\fi\fi +% ^^A % \end{macrocode} +% ^^A % \end{enumerate} +% ^^A % The last thing this macro does is to call \cs{next} +% ^^A % to continue processing. +% ^^A % \begin{macrocode} +% ^^A \next}% +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % \begin{macro}{\verbatim@testend} +% ^^A % \cs{verbatim@testend} is called when +% ^^A % \cs{end}\meta{optional spaces}\verb?{? was seen. +% ^^A % Its task is to scan everything up to the next \verb?}? +% ^^A % and to call \cs{verbatim@@testend}. +% ^^A % If no \verb?}? is found it must reinsert the characters it read +% ^^A % and return to \cs{verbatim@}. +% ^^A % The following definition is similar to that of +% ^^A % \cs{verbatim@test}: +% ^^A % it takes the next character and decides what to do. +% ^^A % \begin{macrocode} +% ^^A \def\verbatim@testend#1{% +% ^^A % \end{macrocode} +% ^^A % Again, we have four cases: +% ^^A % \begin{enumerate} +% ^^A % \item \verb?^^M?: As no \verb?}? is found in the current line, +% ^^A % add the characters to the buffer. To avoid a +% ^^A % complicated construction for expanding +% ^^A % \cs{@temptokena} +% ^^A % and \cs{@tempc} we do it in two steps. Then we +% ^^A % continue with \cs{verbatim@} to process the +% ^^A % next line. +% ^^A % \begin{macrocode} +% ^^A \if\noexpand#1\noexpand~% +% ^^A \expandafter\verbatim@addtoline +% ^^A \expandafter{\the\@temptokena[}% +% ^^A \expandafter\verbatim@addtoline +% ^^A \expandafter{\@tempc}% +% ^^A \verbatim@processline +% ^^A \verbatim@startline +% ^^A \let\next\verbatim@ +% ^^A % \end{macrocode} +% ^^A % \item \verb?}?: Call \cs{verbatim@@testend} to check +% ^^A % if this is the right environment name. +% ^^A % \begin{macrocode} +% ^^A \else\if\noexpand#1\noexpand]% +% ^^A \let\next\verbatim@@testend +% ^^A % \end{macrocode} +% ^^A % \item \verb?\?: This character must not occur in the name of +% ^^A % an environment. Thus we stop collecting characters. +% ^^A % In principle, the same argument would apply to other +% ^^A % characters as well, e.g., \verb?{?. +% ^^A % However, \verb?\? is a special case, since it may be +% ^^A % the first character of \cs{end}. This means that +% ^^A % we have to look again for +% ^^A % \cs{end}\marg{environment name} +% ^^A % Note that we prefixed the \verb?!? by a \cs{noexpand} +% ^^A % primitive, to protect ourselves against it being an +% ^^A % active character. +% ^^A % \begin{macrocode} +% ^^A \else\if\noexpand#1\noexpand!% +% ^^A \expandafter\verbatim@addtoline +% ^^A \expandafter{\the\@temptokena[}% +% ^^A \expandafter\verbatim@addtoline +% ^^A \expandafter{\@tempc}% +% ^^A \def\next{\verbatim@!}% +% ^^A % \end{macrocode} +% ^^A % \item Any other character: collect it and continue. +% ^^A % We cannot use \cs{edef} to define \cs{@tempc} +% ^^A % since its replacement text might contain active +% ^^A % character tokens. +% ^^A % \begin{macrocode} +% ^^A \else \expandafter\def\expandafter\@tempc\expandafter +% ^^A {\@tempc#1}\fi\fi\fi +% ^^A % \end{macrocode} +% ^^A % \end{enumerate} +% ^^A % As before, the macro ends by calling itself, to +% ^^A % process the next character if appropriate. +% ^^A % \begin{macrocode} +% ^^A \next}% +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % \begin{macro}{\verbatim@@testend} +% ^^A % Unlike the previous macros \cs{verbatim@@testend} is simple: +% ^^A % it has only to check if the \cs{end}\marg{...} +% ^^A % matches the corresponding \cs{begin}\marg{...} +% ^^A % \begin{macrocode} +% ^^A \def\verbatim@@testend{% +% ^^A % \end{macrocode} +% ^^A % We use \cs{next} again to define the things that are +% ^^A % to be done. +% ^^A % Remember that the name of the current environment is +% ^^A % held in \cs{@currenvir}, the characters accumulated +% ^^A % by \cs{verbatim@testend} are in \cs{@tempc}. +% ^^A % So we simply compare these and prepare to execute +% ^^A % \cs{end}\marg{current environment} +% ^^A % macro if they match. +% ^^A % Before we do this we call \cs{verbatim@finish} to process +% ^^A % the last line. +% ^^A % We define \cs{next} via \cs{edef} so that +% ^^A % \cs{@currenvir} is replaced by its expansion. +% ^^A % Therefore we need \cs{noexpand} to inhibit the expansion +% ^^A % of \cs{end} at this point. +% ^^A % \begin{macrocode} +% ^^A \ifx\@tempc\@currenvir +% ^^A \verbatim@finish +% ^^A \edef\next{\noexpand\end{\@currenvir}% +% ^^A % \end{macrocode} +% ^^A % Without this trick the \cs{end} command would not be able +% ^^A % to correctly check whether its argument matches the name of +% ^^A % the current environment and you'd get an +% ^^A % interesting \LaTeX{} error message such as: +% ^^A % \begin{verbatim} +% ^^A %! \begin{verbatim*} ended by \end{verbatim*}. +% ^^A %\end{verbatim} +% ^^A % But what do we do with the rest of the characters, those +% ^^A % that remain on that line? +% ^^A % We call \cs{verbatim@rescan} to take care of that. +% ^^A % Its first argument is the name of the environment just +% ^^A % ended, in case we need it again. +% ^^A % \cs{verbatim@rescan} takes the list of characters to be +% ^^A % reprocessed as its second argument. +% ^^A % (This token list was inserted after the current macro +% ^^A % by \cs{verbatim@@@}.) +% ^^A % Since we are still in an \cs{edef} we protect it +% ^^A % by means of\cs{noexpand}. +% ^^A % \begin{macrocode} +% ^^A \noexpand\verbatim@rescan{\@currenvir}}% +% ^^A % \end{macrocode} +% ^^A % If the names do not match, we reinsert everything read up +% ^^A % to now and prepare to call \cs{verbatim@} to process +% ^^A % the rest of the line. +% ^^A % \begin{macrocode} +% ^^A \else +% ^^A \expandafter\verbatim@addtoline +% ^^A \expandafter{\the\@temptokena[}% +% ^^A \expandafter\verbatim@addtoline +% ^^A \expandafter{\@tempc]}% +% ^^A \let\next\verbatim@ +% ^^A \fi +% ^^A % \end{macrocode} +% ^^A % Finally we call \cs{next}. +% ^^A % \begin{macrocode} +% ^^A \next}% +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % \begin{macro}{\verbatim@rescan} +% ^^A % In principle \cs{verbatim@rescan} could be used to +% ^^A % analyse the characters remaining after the \verb?\end{...}? +% ^^A % command and pretend that these were read +% ^^A % ``properly'', assuming ``standard'' category codes are in +% ^^A % force.\footnote{Remember that they were all read with +% ^^A % category codes $11$ (letter) and $12$ (other) so +% ^^A % that control sequences are not recognized as such.} +% ^^A % But this is not always possible (when there are unmatched +% ^^A % curly braces in the rest of the line). +% ^^A % Besides, we think that this is not worth the effort: +% ^^A % After a \texttt{verbatim} or \texttt{verbatim*} environment +% ^^A % a new line in the output is begun anyway, +% ^^A % and an \verb?\end{comment}? can easily be put on a line by itself. +% ^^A % So there is no reason why there should be any text here. +% ^^A % For the benefit of the user who did put something there +% ^^A % (a comment, perhaps) +% ^^A % we simply issue a warning and drop them. +% ^^A % The method of testing is explained in Appendix~D, p.\ 376 of +% ^^A % the \TeX{}book. We use \verb?^^M? instead of the \verb?!? +% ^^A % character used there +% ^^A % since this is a character that cannot appear in \verb?#1?. +% ^^A % The two \cs{noexpand} primitives are necessary to avoid +% ^^A % expansion of active characters and macros. +% ^^A % +% ^^A % One extra subtlety should be noted here: remember that +% ^^A % the token list we are currently building will first be +% ^^A % processed by the \cs{lowercase} primitive before \TeX{} +% ^^A % carries out the definitions. +% ^^A % This means that the `\texttt{C}' character in the +% ^^A % argument to the \cs{@warning} macro must be protected against +% ^^A % being changed to `\texttt{c}'. That's the reason why we added the +% ^^A % \verb?\lccode`\C=`\C? assignment above. +% ^^A % We can now finish the argument to \cs{lowercase} as well as the +% ^^A % group in which the category codes were changed. +% ^^A % \begin{macrocode} +% ^^A \def\verbatim@rescan#1#2~{\if\noexpand~\noexpand#2~\else +% ^^A \@warning{Characters dropped after `\string\end{#1}'}\fi}} +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % \subsubsection{The \cs{verbatiminput} command} +% ^^A % +% ^^A % \begin{macro}{\verbatim@in@stream} +% ^^A % We begin by allocating an input stream (out of the 16 available +% ^^A % input streams). +% ^^A % \begin{macrocode} +% ^^A \newread\verbatim@in@stream +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % \begin{macro}{\verbatim@readfile} +% ^^A % The macro \cs{verbatim@readfile} encloses the main loop by calls to +% ^^A % the macros \cs{verbatim@startline} and \cs{verbatim@finish}, +% ^^A % respectively. This makes sure +% ^^A % that the user can initialize and finish the command when the file +% ^^A % is empty or doesn't exist. The \texttt{verbatim} environment has a +% ^^A % similar behaviour when called with an empty text. +% ^^A % \begin{macrocode} +% ^^A \def\verbatim@readfile#1{% +% ^^A \verbatim@startline +% ^^A % \end{macrocode} +% ^^A % When the file is not found we issue a warning. +% ^^A % \begin{macrocode} +% ^^A \openin\verbatim@in@stream #1\relax +% ^^A \ifeof\verbatim@in@stream +% ^^A \typeout{No file #1.}% +% ^^A \else +% ^^A % \end{macrocode} +% ^^A % At this point we pass the name of the file to \cs{@addtofilelist} +% ^^A % so that its appears appears in the output of a \cs{listfiles} +% ^^A % command. +% ^^A % In addition, we use \cs{ProvidesFile} to make a log entry in the +% ^^A % transcript file and to distinguish files read in via +% ^^A % \cs{verbatiminput} from others. +% ^^A % \begin{macrocode} +% ^^A \@addtofilelist{#1}% +% ^^A \ProvidesFile{#1}[(verbatim)]% +% ^^A % \end{macrocode} +% ^^A % While reading from the file it is useful to switch off the +% ^^A % recognition of the end-of-line character. This saves us stripping +% ^^A % off spaces from the contents of the line. +% ^^A % \begin{macrocode} +% ^^A \expandafter\endlinechar\expandafter\m@ne +% ^^A \expandafter\verbatim@read@file +% ^^A \expandafter\endlinechar\the\endlinechar\relax +% ^^A \closein\verbatim@in@stream +% ^^A \fi +% ^^A \verbatim@finish +% ^^A } +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % \begin{macro}{\verbatim@read@file} +% ^^A % All the work is done in \cs{verbatim@read@file}. It reads the input +% ^^A % file line by line and recursively calls itself until the end of +% ^^A % the file. +% ^^A % \begin{macrocode} +% ^^A \def\verbatim@read@file{% +% ^^A \read\verbatim@in@stream to\next +% ^^A \ifeof\verbatim@in@stream +% ^^A \else +% ^^A % \end{macrocode} +% ^^A % For each line we call \cs{verbatim@addtoline} with the contents of +% ^^A % the line. \hskip0pt plus 3cm\penalty0\hskip0pt plus -3cm +% ^^A % \cs{verbatim@processline} is called next. +% ^^A % \begin{macrocode} +% ^^A \expandafter\verbatim@addtoline\expandafter{\next}% +% ^^A \verbatim@processline +% ^^A % \end{macrocode} +% ^^A % After processing the line we call \cs{verbatim@startline} to +% ^^A % initialize all before we read the next line. +% ^^A % \begin{macrocode} +% ^^A \verbatim@startline +% ^^A % \end{macrocode} +% ^^A % Without \cs{expandafter} each call of \cs{verbatim@read@file} uses +% ^^A % space in \TeX's input stack.\footnote{A standard \TeX\ would +% ^^A % report an overflow error if you try to read a file with more than +% ^^A % ca.\ 200~lines. The same error occurs if the first line of code +% ^^A % in \S 390 of \textsl{``TeX: The Program''\/} is missing.} +% ^^A % \begin{macrocode} +% ^^A \expandafter\verbatim@read@file +% ^^A \fi +% ^^A } +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % +% ^^A % \begin{macro}{\verbatiminput} +% ^^A % \cs{verbatiminput} first starts a group to keep font and category +% ^^A % changes local. +% ^^A % Then it calls the macro \cs{verbatim@input} with additional +% ^^A % arguments, depending on whether an asterisk follows. +% ^^A % +% ^^A % PW. I added the TAB checking code. +% ^^A % \begin{macrocode} +% ^^A \def\verbatiminput{\begingroup +% ^^A \ift@bs +% ^^A \def\verbatim@processline{\tabverbatim@processline}% +% ^^A \fi +% ^^A \@ifstar{\verbatim@input{\@maybeobeytabs}}% +% ^^A {\verbatim@input{\frenchspacing\@vobeyspaces\@maybeobeytabs}}} +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % \begin{macro}{\verbatim@input} +% ^^A % \cs{verbatim@input} first checks whether the file exists, using +% ^^A % the standard macro cs{IfFileExists} which leaves the name of the +% ^^A % file found in \cs{@filef@und}. +% ^^A % Then everything is set up as in the \cs{verbatim} macro. +% ^^A % \begin{macrocode} +% ^^A \def\verbatim@input#1#2{% +% ^^A \IfFileExists {#2}{\@verbatim #1\relax +% ^^A % \end{macrocode} +% ^^A % Then it reads in the file, finishes off the \texttt{trivlist} +% ^^A % environment started by \cs{@verbatim} and closes the group. +% ^^A % This restores everything to its normal settings. +% ^^A % \begin{macrocode} +% ^^A \verbatim@readfile{\@filef@und}\endtrivlist\endgroup\@doendpe}% +% ^^A % \end{macrocode} +% ^^A % If the file is not found a more or less helpful message is +% ^^A % printed. The final \cs{endgroup} is needed to close the group +% ^^A % started in \cs{verbatiminput} above. +% ^^A % \begin{macrocode} +% ^^A {\typeout {No file #2.}\endgroup}} +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % \textit{That completes my borrowings from \Lpack{verbatim}.} +% ^^A % +% ^^A +% ^^A % ^^A end embedded verbatim +% ^^A +% ^^A % The next bunch of code implements wrapping verbatim lines so they, hopefully, +% ^^A % stay within the typeblock. +% ^^A % +% ^^A % \begin{macro}{\verbatimindent} +% ^^A % \begin{macro}{\verbatimbreakchar} +% ^^A % \begin{macro}{\setverbatimbreak} +% ^^A % The length \cs{verbatimindent} is the distance continuation lines are indented +% ^^A % from the left margin. \cs{verbatimbreakchar} is the character to indicate +% ^^A % a wrapped line. +% ^^A % \begin{macrocode} +% ^^A \newlength{\verbatimindent} +% ^^A \setlength{\verbatimindent}{3em} +% ^^A \newcommand*{\verbatimbreakchar}{\char`\%} +% ^^A \newcommand*{\setverbatimbreak}{% +% ^^A \vspace*{-\baselineskip}% +% ^^A \def\@xobeysp{~\discretionary{\verbatimbreakchar}% +% ^^A {\kern\verbatimindent}{}}% +% ^^A } +% ^^A +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % \end{macro} +% ^^A % \end{macro} +% ^^A % +% ^^A % ^^A \begin{macro}{\wrappingon} +% ^^A % \begin{macro}{\wrapright} +% ^^A % \begin{macro}{\wrappingoff} +% ^^A % \cs{wrappingon} and \cs{wrappingoff} enable/prohibit wrapping. The +% ^^A % default is \cs{wrappingoff}. +% ^^A % +% ^^A % The macro +% ^^A % \cs{wrapright} is used to set paragraph skips; without raggedright the +% ^^A % lines +% ^^A % may break at the first space \emph{outside} the text area. However, +% ^^A % Paul (\url{paulaugust2003@yahoo.com}) found that wrapped verbatims +% ^^A % in a list (e.g., \texttt{itemize}) were not indented although regular +% ^^A % verbatims were indented. \cs{raggedwrap} is a variation on \cs{raggedright} +% ^^A % (\cs{leftskip} is set to \cs{@totalleftmargin} instead of 0pt), and seems +% ^^A % to have fixed the problem with the original code which used +% ^^A % \cs{raggedright}. +% ^^A % \changes{v1.61803}{2008/01/30}{Added \cs{raggedwrap} (mempatch v4.4)} +% ^^A % \changes{v1.61803398}{2009/07/18}{Added bidi support to \cs{raggedwrap}} +% ^^A % \begin{macrocode} +% ^^A % \newcommand*{\raggedwrap}{% +% ^^A % \@rightskip\@flushglue +% ^^A % %%% \rightskip\@rightskip +% ^^A % \memRTLrightskip\@rightskip +% ^^A % %%% \leftskip\@totalleftmargin +% ^^A % \memRTLleftskip\@totalleftmargin +% ^^A % \parindent\ragrparindent} +% ^^A \newcommand*{\wrappingon}{% +% ^^A \def\@xobeysp{~\discretionary{\verbatimbreakchar}% +% ^^A {\kern\verbatimindent}{}}% +% ^^A \def\wrapright{\raggedwrap}} +% ^^A \newcommand*{\wrappingoff}{% +% ^^A \def\@xobeysp{\leavevmode\penalty\@M\ }% +% ^^A \def\wrapright{}} +% ^^A \wrappingoff +% ^^A +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % \end{macro} +% ^^A % \end{macro} +% ^^A % ^^A \end{macro} +% ^^A % +% ^^A % \noindent{\color{red}\rule\textwidth{5mm}} +% % \subsection{Writing and boxing verbatim} % % This bunch of code is from the \Lpack{moreverb} package. @@ -28926,152 +29354,180 @@ \fbox{\box0}% <<<=== change here for centering,... \endgroup} % \end{macrocode} + % \end{environment} % % % % \subsection{The shortvrb package} % -% The following is the \Lpack{shortvrb} package code (from \texttt{doc.dtx} -% by Frank Mittelbach). It has been so useful to me that I wanted -% to include it in the class. -% -% CODE AND COMMENTARY IS BY FRANK MITTELBACH +% +% \changes{v3.8.2}{2024/01/10}{Replaced embedded copy if +% \Lpack{shortvrb} with loading the package. The embedded code is just +% outcommented for now.} % -% \begin{macro}{\MakeShortVerb} -% \begin{macrocode} -\def\MakeShortVerb#1{% - \expandafter\ifx\csname cc\string#1\endcsname\relax -% \end{macrocode} -% \begin{macrocode} - \@shortvrbinfo{Made }{#1}% - \add@special{#1}% -% \end{macrocode} -% Then the character's current catcode is stored in \verb?\cc\?\meta{c}. -% \begin{macrocode} - \expandafter - \xdef\csname cc\string#1\endcsname{\the\catcode`#1}% -% \end{macrocode} -% The character is spliced into the definition using the same trick as -% used in \cs{verb} (for instance), having activated \verb?~? in a group. -% \begin{macrocode} - \begingroup - \catcode`\~\active \lccode`\~`#1% - \lowercase{% -% \end{macrocode} -% The character's old meaning is recorded in \verb?\ac\?\meta{c} prior to -% assigning it a new one. -% \begin{macrocode} - \global\expandafter\let - \csname ac\string#1\endcsname~% - \gdef~{\verb~}}% - \endgroup -% \end{macrocode} -% Finally the character is made active. -% \begin{macrocode} - \global\catcode`#1\active -% \end{macrocode} -% If we suspect that \meta{c} is already a short reference, we tell -% the user. Now he or she is responsible if anything goes wrong\,\dots -% \begin{macrocode} - \else -% \end{macrocode} -% \begin{macrocode} - \@shortvrbinfo\@empty{#1 already}% - \fi} -% \end{macrocode} -% \end{macro} -% \begin{macro}{\DeleteShortVerb} -% Here's the means of undoing a \cs{MakeShortVerb}, for instance in a -% region where you need to use the character outside a verbatim -% environment. It arranges for \cs{dospecials} and \cs{@sanitize} to be -% altered appropriately, restores the saved catcode and, if necessary, -% the character's meaning (as stored by -% \cs{MakeShortVerb}). If the catcode wasn't stored in -% \verb?\cc\?\meta{c} (by \cs{MakeShortVerb}) the command is silently -% ignored. -% \begin{macrocode} -\def\DeleteShortVerb#1{% - \expandafter\ifx\csname cc\string#1\endcsname\relax - \else -% \end{macrocode} -% \begin{macrocode} - \@shortvrbinfo{Deleted }{#1 as}% - \rem@special{#1}% - \global\catcode`#1\csname cc\string#1\endcsname -% \end{macrocode} -% We must not forget to reset \verb?\cc\?\meta{c}, otherwise the check in -% \cs{MakeShortVerb} for a repeated definition will not work. -% \begin{macrocode} - \global \expandafter\let \csname cc\string#1\endcsname \relax - \ifnum\catcode`#1=\active - \begingroup - \catcode`\~\active \lccode`\~`#1% - \lowercase{% - \global\expandafter\let\expandafter~% - \csname ac\string#1\endcsname}% - \endgroup \fi \fi} -% \end{macrocode} -% \end{macro} +% In earlier versions of the class we had an embedded copy of the code +% from the \Lpack{shortvrb} package, as the functionality is very +% useful. % -% \begin{macro}{\@shortvrbinfo} -% Helper function for info messages. -% \begin{macrocode} -\def\@shortvrbinfo#1#2{% - \ClassInfo{memoir}{% - #1\expandafter\@gobble\string#2 a short reference - for \string\verb}} -% \end{macrocode} -% \end{macro} +% As of 2024 we load the package instead. This also gives us access to +% the starred version of \verb!\MakeShortVerb!. For details see +% \cite{SHORTVRB}. % -% \begin{macro}{\add@special} -% This helper macro adds its argument to the -% \cs{dospecials} macro which is conventionally used by verbatim macros -% to alter the catcodes of the currently active characters. We need -% to add \verb?\do\?\meta{c} to the expansion of \cs{dospecials} after -% removing the character if it was already there to avoid multiple -% copies building up should \cs{MakeShortVerb} not be balanced by -% \cs{DeleteShortVerb} (in case anything that uses \cs{dospecials} cares -% about repetitions). -% \begin{macrocode} -\def\add@special#1{% - \rem@special{#1}% - \expandafter\gdef\expandafter\dospecials\expandafter - {\dospecials \do #1}% -% \end{macrocode} -% Similarly we have to add \verb?\@makeother\?\meta{c} to \cs{@sanitize} -% (which is used in things like \cs{index} to re-catcode all special -% characters except braces). -% \begin{macrocode} - \expandafter\gdef\expandafter\@sanitize\expandafter - {\@sanitize \@makeother #1}} -% \end{macrocode} -% \end{macro} -% \begin{macro}{\rem@special} -% The inverse of cs{add@special} is slightly trickier. \cs{do} is -% re-defined to expand to nothing if its argument is the character of -% interest, otherwise to expand simply to the argument. We can then -% re-define \cs{dospecials} to be the expansion of itself. The space -% after \verb?=`##1? prevents an expansion to \cs{relax}! -% \begin{macrocode} -\def\rem@special#1{% - \def\do##1{% - \ifnum`#1=`##1 \else \noexpand\do\noexpand##1\fi}% - \xdef\dospecials{\dospecials}% -% \end{macrocode} -% Fixing \cs{@sanitize} is the same except that we need to re-define -% \cs{@makeother} which obviously needs to be done in a group. +% It adds the following macros +% \begin{verbatim} +% \MakeShortVerb +% \MakeShortVerb* +% \DeleteShortVerb +% \end{verbatim} % \begin{macrocode} - \begingroup - \def\@makeother##1{% - \ifnum`#1=`##1 \else \noexpand\@makeother\noexpand##1\fi}% - \xdef\@sanitize{\@sanitize}% - \endgroup} + % load shortvrb instead of embedding it +\RequirePackage{shortvrb} + % \end{macrocode} -% \end{macro} -% -% END OF MITTELBACH CODE AND COMMENTARY. -% +% +% ^^A % The following is the \Lpack{shortvrb} package code (from \texttt{doc.dtx} +% ^^A % by Frank Mittelbach). It has been so useful to me that I wanted +% ^^A % to include it in the class. +% ^^A % +% ^^A % CODE AND COMMENTARY IS BY FRANK MITTELBACH +% ^^A % start shortvrb code +% ^^A % +% ^^A % \begin{macro}{\MakeShortVerb} +% ^^A % \begin{macrocode} +% ^^A \def\MakeShortVerb#1{% +% ^^A \expandafter\ifx\csname cc\string#1\endcsname\relax +% ^^A % \end{macrocode} +% ^^A % \begin{macrocode} +% ^^A \@shortvrbinfo{Made }{#1}% +% ^^A \add@special{#1}% +% ^^A % \end{macrocode} +% ^^A % Then the character's current catcode is stored in \verb?\cc\?\meta{c}. +% ^^A % \begin{macrocode} +% ^^A \expandafter +% ^^A \xdef\csname cc\string#1\endcsname{\the\catcode`#1}% +% ^^A % \end{macrocode} +% ^^A % The character is spliced into the definition using the same trick as +% ^^A % used in \cs{verb} (for instance), having activated \verb?~? in a group. +% ^^A % \begin{macrocode} +% ^^A \begingroup +% ^^A \catcode`\~\active \lccode`\~`#1% +% ^^A \lowercase{% +% ^^A % \end{macrocode} +% ^^A % The character's old meaning is recorded in \verb?\ac\?\meta{c} prior to +% ^^A % assigning it a new one. +% ^^A % \begin{macrocode} +% ^^A \global\expandafter\let +% ^^A \csname ac\string#1\endcsname~% +% ^^A \gdef~{\verb~}}% +% ^^A \endgroup +% ^^A % \end{macrocode} +% ^^A % Finally the character is made active. +% ^^A % \begin{macrocode} +% ^^A \global\catcode`#1\active +% ^^A % \end{macrocode} +% ^^A % If we suspect that \meta{c} is already a short reference, we tell +% ^^A % the user. Now he or she is responsible if anything goes wrong\,\dots +% ^^A % \begin{macrocode} +% ^^A \else +% ^^A % \end{macrocode} +% ^^A % \begin{macrocode} +% ^^A \@shortvrbinfo\@empty{#1 already}% +% ^^A \fi} +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % \begin{macro}{\DeleteShortVerb} +% ^^A % Here's the means of undoing a \cs{MakeShortVerb}, for instance in a +% ^^A % region where you need to use the character outside a verbatim +% ^^A % environment. It arranges for \cs{dospecials} and \cs{@sanitize} to be +% ^^A % altered appropriately, restores the saved catcode and, if necessary, +% ^^A % the character's meaning (as stored by +% ^^A % \cs{MakeShortVerb}). If the catcode wasn't stored in +% ^^A % \verb?\cc\?\meta{c} (by \cs{MakeShortVerb}) the command is silently +% ^^A % ignored. +% ^^A % \begin{macrocode} +% ^^A \def\DeleteShortVerb#1{% +% ^^A \expandafter\ifx\csname cc\string#1\endcsname\relax +% ^^A \else +% ^^A % \end{macrocode} +% ^^A % \begin{macrocode} +% ^^A \@shortvrbinfo{Deleted }{#1 as}% +% ^^A \rem@special{#1}% +% ^^A \global\catcode`#1\csname cc\string#1\endcsname +% ^^A % \end{macrocode} +% ^^A % We must not forget to reset \verb?\cc\?\meta{c}, otherwise the check in +% ^^A % \cs{MakeShortVerb} for a repeated definition will not work. +% ^^A % \begin{macrocode} +% ^^A \global \expandafter\let \csname cc\string#1\endcsname \relax +% ^^A \ifnum\catcode`#1=\active +% ^^A \begingroup +% ^^A \catcode`\~\active \lccode`\~`#1% +% ^^A \lowercase{% +% ^^A \global\expandafter\let\expandafter~% +% ^^A \csname ac\string#1\endcsname}% +% ^^A \endgroup \fi \fi} +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % \begin{macro}{\@shortvrbinfo} +% ^^A % Helper function for info messages. +% ^^A % \begin{macrocode} +% ^^A \def\@shortvrbinfo#1#2{% +% ^^A \ClassInfo{memoir}{% +% ^^A #1\expandafter\@gobble\string#2 a short reference +% ^^A for \string\verb}} +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % \begin{macro}{\add@special} +% ^^A % This helper macro adds its argument to the +% ^^A % \cs{dospecials} macro which is conventionally used by verbatim macros +% ^^A % to alter the catcodes of the currently active characters. We need +% ^^A % to add \verb?\do\?\meta{c} to the expansion of \cs{dospecials} after +% ^^A % removing the character if it was already there to avoid multiple +% ^^A % copies building up should \cs{MakeShortVerb} not be balanced by +% ^^A % \cs{DeleteShortVerb} (in case anything that uses \cs{dospecials} cares +% ^^A % about repetitions). +% ^^A % \begin{macrocode} +% ^^A \def\add@special#1{% +% ^^A \rem@special{#1}% +% ^^A \expandafter\gdef\expandafter\dospecials\expandafter +% ^^A {\dospecials \do #1}% +% ^^A % \end{macrocode} +% ^^A % Similarly we have to add \verb?\@makeother\?\meta{c} to \cs{@sanitize} +% ^^A % (which is used in things like \cs{index} to re-catcode all special +% ^^A % characters except braces). +% ^^A % \begin{macrocode} +% ^^A \expandafter\gdef\expandafter\@sanitize\expandafter +% ^^A {\@sanitize \@makeother #1}} +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % \begin{macro}{\rem@special} +% ^^A % The inverse of cs{add@special} is slightly trickier. \cs{do} is +% ^^A % re-defined to expand to nothing if its argument is the character of +% ^^A % interest, otherwise to expand simply to the argument. We can then +% ^^A % re-define \cs{dospecials} to be the expansion of itself. The space +% ^^A % after \verb?=`##1? prevents an expansion to \cs{relax}! +% ^^A % \begin{macrocode} +% ^^A \def\rem@special#1{% +% ^^A \def\do##1{% +% ^^A \ifnum`#1=`##1 \else \noexpand\do\noexpand##1\fi}% +% ^^A \xdef\dospecials{\dospecials}% +% ^^A % \end{macrocode} +% ^^A % Fixing \cs{@sanitize} is the same except that we need to re-define +% ^^A % \cs{@makeother} which obviously needs to be done in a group. +% ^^A % \begin{macrocode} +% ^^A \begingroup +% ^^A \def\@makeother##1{% +% ^^A \ifnum`#1=`##1 \else \noexpand\@makeother\noexpand##1\fi}% +% ^^A \xdef\@sanitize{\@sanitize}% +% ^^A \endgroup} +% ^^A % \end{macrocode} +% ^^A % \end{macro} +% ^^A % +% ^^A % end shortvrb code +% ^^A % END OF MITTELBACH CODE AND COMMENTARY. +% % \subsection{General verbatim boxing and line numbering} % % A while ago I wrote a package that I never released. Here it is @@ -29284,6 +29740,7 @@ \fi % \end{macrocode} % \begin{macro}{\verbatim@processline} +% \changes{v3.8.2}{2024/01/25}{Removed tab support} % \begin{macrocode} \def\verbatim@processline{\leavevmode \b@vdocount% @@ -29291,11 +29748,11 @@ \linewidth-.8\p@ \@@line {\b@vdooutside\strut\kern\bvboxsep% \b@vdoinside% - \ift@bs - \tabverbatim@processline - \else + %\ift@bs + % \tabverbatim@processline + %\else \the\verbatim@line - \fi + %\fi \hss}% \kern\bvboxsep}\bvrightsidehook\par}} @@ -29306,14 +29763,16 @@ % % \begin{macro}{\setupbox@verb} % Use a macro for the second main part of DA's code, and integrate it -% with the other verbatim codes (e.g., include \cs{@maybeobeytags}). +% with the other verbatim codes. +% +% \changes{v3.8.2}{2024/01/25}{Removed \cs{@maybeobeytags}} % \begin{macrocode} \newcommand{\setupbox@verb}{% \leftskip\z@skip \rightskip\z@skip \interlinepenalty\boxverbflag \parfillskip\z@ plus\p@ minus\p@ \lineskip-\bvboxsep \baselineskip\z@skip - \frenchspacing\@vobeyspaces\@maybeobeytabs + \frenchspacing\@vobeyspaces%\@maybeobeytabs \boxverb@toprule} % \end{macrocode} @@ -30384,13 +30843,15 @@ % \cs{stre@mverb@input}\marg{setup}\marg{stream} and % \cs{verbatim@readstre@m}\marg{stream}. Finally, \cs{verbatim@read@file} % is a \Lpack{verbatim} package macro. +% \changes{v3.8.2}{2024/01/26}{Removed tabs support and added the tab +% marking support to the starred version like we did for \cs{verbatiminput}} % \begin{macrocode} \def\readverbatim{\begingroup - \ift@bs - \def\verbatim@processline{\tabverbatim@processline}% - \fi - \@ifstar{\stre@mverb@input{\@maybeobeytabs}}% - {\stre@mverb@input{\frenchspacing\@vobeyspaces\@maybeobeytabs}}} + %\ift@bs + % \def\verbatim@processline{\tabverbatim@processline}% + %\fi + \@ifstar{\stre@mverb@input{\@setupverbvisiblespace\@vobeyspaces}}%{\@maybeobeytabs}}% + {\stre@mverb@input{\frenchspacing\@vobeyspaces}}}%\@maybeobeytabs}}} % \end{macrocode} % \end{macro} @@ -33559,7 +34020,7 @@ keyword "\\glossaryentry" % \newblock \emph{The ltfilehook package} % \newblock July 2020. % -% \bibitem[Mit2023]{LTHOOKS} +% \bibitem[Mit2023a]{LTHOOKS} % Frank Mittelbach % \newblock \emph{\LaTeX's hook management} % \newblock June 2023. @@ -33568,7 +34029,12 @@ keyword "\\glossaryentry" % Frank Mittelbach % \newblock \emph{The ltshipout package} % \newblock July 2020. -% +% +% \bibitem[Mit2023b]{SHORTVRB} +% Frank Mittelbach +% \newblock \emph{The doc and shortvrb Packages} +% \newblock November 2023. +% % \bibitem[Oos96]{FANCYHDR} % Piet van Oostrum. % \newblock \emph{Page layout in LaTeX}. |