diff options
Diffstat (limited to 'support/splint/tex/noweb.sty')
-rw-r--r-- | support/splint/tex/noweb.sty | 186 |
1 files changed, 141 insertions, 45 deletions
diff --git a/support/splint/tex/noweb.sty b/support/splint/tex/noweb.sty index a0f2c7cf43..b7dce9623b 100644 --- a/support/splint/tex/noweb.sty +++ b/support/splint/tex/noweb.sty @@ -1,4 +1,4 @@ -% Copyright 2012-2020, Alexander Shibakov +% Copyright 2012-2024, Alexander Shibakov % This file is part of SPLinT % % SPLinT is free software: you can redistribute it and/or modify @@ -14,6 +14,43 @@ % You should have received a copy of the GNU General Public License % along with SPLinT. If not, see <http://www.gnu.org/licenses/>. +\def\yyuniontag{\auxunionctl} +\defp\xrefunionctl{}% sequence to activate/deactivate/take other action for + % xref set of macros + +\defc\xrefunionctl{% + \restorecslist{aux:global:xrefs}\xrefunion +} +\savecs{aux:global:activate}\xrefunionctl + +\defc\xrefunionctl{% + \restorecslist{aux:global:xrefs:neutral}\xrefunion +} +\savecs{aux:global:deactivate}\xrefunionctl + +\defc\xrefunionctl{% this command should not make any page material contributions + \message{xrefs...}% +} +\savecs{aux:global:preend}\xrefunionctl + +\defc\xrefunionctl{% writing a header, etc. + \message{xrefs...}% + \toksa\expandafter{\xrefunion}% + \immediate\write\auxstream{\harmlesscomment\the\toksa}% +} +\savecs{aux:global:prestart}\xrefunionctl + +\yyuniondeclare\xrefunion{aux:global:xrefs} + +\defp\MNM#1#2#3#4{} +\defp\XXX#1#2#3{} +\defp\BBB#1#2#3#4{} +\defp\SSS{} + +\toyyunion{aux:global:xrefs:neutral} + +% end global stream union macros for cross referencing + \def\stseclap{\rightskip=0pt % get out of C mode (cf. \B) \sfcode`;=1500 \pretolerance 200 \hyphenpenalty 50 \exhyphenpenalty 50 \noindent{\let\*=\empty\llap{\tentitle\setsafesecno{\secno}\quad}}% push it to the margins @@ -33,17 +70,25 @@ \fi } +\ifx\customchapterstyle\UNDEFINED + \def\customchapterstyle{0} +\fi + +\ifx\customsubchapterstyle\UNDEFINED + \let\customsubchapterstyle\empty +\fi + \def\stsecchap#1#2{\rightskip=0pt % get out of C mode (cf. \B) \sfcode`;=1500 \pretolerance 200 \hyphenpenalty 50 \exhyphenpenalty 50 % \ifnum#1>\z@ % the `level' if this section is below that of a chapter \noindent{\let\*=\empty\llap{\tentitle - \setsafesecno{\secno}\quad}}{\ttl #2}% push it to the margins - \putxref{\MNM}{}{}.% generate a location reference for noweb cross referencing style - \smallskip\noindent + \setsafesecno{\secno}\quad}}{\stsecchapttl{#1}#2\stsecchapterminator{#1}}% push it to the margins + \putxref{\MNM}{\customsubchapterstyle}{}.% generate a location reference for noweb cross referencing style + \stsecchapseparator{#1}% \else \setchaptertitle{\secno}{#2}% - \putxref{\MNM}{0}{}.% generate a chapter location reference for noweb cross referencing style + \putxref{\MNM}{\customchapterstyle}{}.% generate a chapter location reference for noweb cross referencing style \fi % \ifpdftex\smash{\raise\baselineskip\hbox to0pt{% @@ -52,6 +97,13 @@ \let\*=\empty\special{% pdf: dest (\romannumeral\secstar) [ @thispage /FitH @ypos ]}}}\fi\fi} +\def\stsecchapterminator#1{} % for deeply nested sections one may put a dot at the end +\def\stsecchapseparator#1{% + \smallskip + \noindent +} +\def\stsecchapttl#1{\ttl} + \def\setchaptertitle#1#2{% \global\chapterheadtrue \null @@ -71,17 +123,20 @@ }% \prevdepth=0pt \bigskip - \noindent{\let\*=\empty\llap{\tentitle\setsafesecno{\secno}\quad}}% + \noindent%{\let\*=\empty\llap{\tentitle\setsafesecno{\secno}\quad}}% } \let\startsection\stseclap \expandafter\def\expandafter\oldB\expandafter{\oldB\global\csectionstarttrue\putxref{\BBB}{}{}.} +% the command that writes references to the reference stream (file): +% \<reference name>{page}{section}{param1}{param2} +% \def\putxref#1#2.{% it is important that #2 contains at least two braced groups (as in {}{}) % otherwise the parameter scanning mechanism will strip the outside braces \ifxreflocal - {\edef\next{\write\xrefstream{\nx\nx\nx#1{\nx\the\nx\pageno}{\secno}#2\harmlesscomment}}\next}% + {\edef\next{\write\auxstream{\nx\nx\nx#1{\nx\the\nx\pageno}{\secno}#2\harmlesscomment}}\next}% \fi } @@ -94,7 +149,7 @@ {\def\sname{#2}% \def\stripprefix##1>{ }% \let\*\empty - \edef\next{\write\xrefstream{\nx\nx\nx\XXX{\nx\the\nx\pageno}{\secno}{#1}\harmlesscomment + \edef\next{\write\auxstream{\nx\nx\nx\XXX{\nx\the\nx\pageno}{\secno}{#1}\harmlesscomment \expandafter\stripprefix\meaning\sname}}\next}% \fi } @@ -141,7 +196,7 @@ \def\setdownlink#1#2#3{% {\setbox0\vtop{ \sevenpoint\halign{#3\cr - \xref@nowebsection{\csname xchain[#1][#2]down\endcsname}\cr + \setsafesecorchapno{\csname xchain[#1][#2]down\endcsname}\cr \relax\ifacro \pdflink{\csname xchain[#1][#2]down\endcsname}{\raise3.5pt\hbox{$\scriptscriptstyle\bigtriangledown$}}% \else @@ -162,14 +217,16 @@ \lower1.3pt\hbox{$\scriptscriptstyle\bigtriangleup$}% \fi \cr - \xref@nowebsection{\csname xchain[#1][#2]up\endcsname}\cr + \setsafesecorchapno{\csname xchain[#1][#2]up\endcsname}\cr } }% \box0}% } +% modify \makenote (used by \pdfnote) to use \noweb\ style references. + \def\makenote{% - \addtokens\toksB{\noexpand\pdflink{\the\toksC}{\setsafesecno{\the\toksC}}}% + \addtokens\toksB{\noexpand\pdflink{\the\toksC}{\setsafesecorchapno{\the\toksC}}}% \toksC={}\global\countC=0 } @@ -195,22 +252,11 @@ \ \ifacro\pdflink{#3}{#3}\else#3\fi\hbox to3em{\hss#4}}} \newif\ifxreflocal % are we generating references in noweb style (as page no., position pairs)? - -\newread\trystream % generic stream to test for an existence of a file - -\def\readlxrefs{% see if the local reference file exists - \openin\trystream=\jobname.xxr - \ifeof\trystream - \else - \closein\trystream - \input \jobname.xxr - \fi -} - \newif\ifcsecactive -\def\BBB#1#2#3#4{% #1 is the page number - % #2 is the section number +\defc\BBB#1#2#3#4{% #1 is the page number + % #2 is the section number + % #3, #4 are reserved \csecactivetrue } @@ -221,10 +267,14 @@ \lxrcurrentindex=\z@ -\def\MNM#1#2#3#4{% #1 is the page number - % #2 is the section number - % #3 is the chapter flag or empty - % #4 is reserved +% the command that processes the reference stream by setting +% chapter numbers, etc. based on the section number (which is +% unique across all sections); see also \BBB\ above + +\defc\MNM#1#2#3#4{% #1 is the page number + % #2 is the section number + % #3 is the chapter flag or empty + % #4 is a possible custom reference \ifnum#1=\lxrcurrentpage \else \lxrcurrentindex=\z@ @@ -235,21 +285,25 @@ \def\nnext{\expandafter\noexpand\csname lxref[#2]\endcsname}% \yystringempty{#3}{% \let\nnnext\empty + \toksa{\advance\lxrcurrentindex\@ne}% }{% - \global\advance\chaptercount\@ne - \def\nnnext{\the\chaptercount}% + \ifnum#3=\z@ + \toksa{\advance\chaptercount\@ne}% + \def\nnnext{\the\chaptercount}% + \else + \processcustomchapterref{#3}{#4}{\nnnext}% + \fi }% - \edef\next{\def\nnext{{#1}{\next}{\nnnext}}}% + \edef\next{\def\nnext{{#1}{\next}{\nnnext}{#3}}\the\toksa}% \expandafter }\next - \advance\lxrcurrentindex\@ne } \def\xref@nowebsection#1{% translate the \CWEB\ section number into a \noweb\ reference \expandafter\xr@f@nowebsection\romannumeral-1\csname lxref[#1]\endcsname.% } -\def\xr@f@nowebsection#1#2#3.{% +\def\xr@f@nowebsection#1#2#3#4.{% {#1}{#2}% } @@ -263,15 +317,45 @@ }% } -\def\setsafesecno#1{% +\def\xref@sectionorchapter#1{% translate the \CWEB\ section number into a chapter number + % if the section begins a chapter or a \noweb\ section reference otherwise + \expandafter\xr@f@sectionorchapter\romannumeral-1\csname lxref[#1]\endcsname.% +} + +\ifx\customchlabel\UNDEFINED + \def\customchlabel#1#2#3#4{% + ch#3% + } +\fi + +\def\xr@f@sectionorchapter#1#2#3#4.{% + \yystringempty{#3}{{#1}{#1#2}}{% + {#1}{\customchlabel{#1}{#2}{#3}{#4}}% + }% +} + +\def\setsafesecno#1{% extract the noweb style section reference from the \CWEB\ section index + % used to typeset marginal section references \expandafter\ifx\csname lxref[#1]\endcsname\relax #1% \else - \xref@nowebsection{#1}% + \expandafter\lmarginref\romannumeral-1\xref@nowebsection{#1}% \fi } -\def\setsafechapno#1{% +\def\lmarginref#1#2{{\sscmd\rm#1}\rlap{\sscmd\rm#2}\ } + +\def\setsafesecorchapno#1{% if the section begins a chapter, extract the chapter reference, + % otherwise, extract the \noweb\ style reference + \expandafter\ifx\csname lxref[#1]\endcsname\relax + #1% + \else + \expandafter\eatone\romannumeral-1\xref@sectionorchapter{#1}% + \fi +} + +\def\setsafechapno#1{% extract the chapter index + % used to typeset chapter headers \expandafter\ifx\csname lxref[#1]\endcsname\relax #1% \else @@ -297,19 +381,29 @@ \repeat } -\def\XXX#1#2#3{% +\defc\XXX#1#2#3{% \ifcsecactive % previous command was \BBB (produced by the \B macro) % \expandafter\def\csname lxref[][]\endcsname{}% \csecactivefalse \fi } -\def\SSS{\let\XXX\xxxchain} % reference separator +% the next command takes advantage of the format for section references +% in the list of all sections: instead of a specific section number that +% points to the section where the given chunk of code started, the +% references contain ordered lists of all the section numbers that +% constitute the contents of the named section; +% this command should be placed in the main .w file before the list +% of all sections is included but after all the regular section references. \def\lxrefseparator{% - \write\xrefstream{\nx\SSS}% + \write\auxstream{\nx\SSS}% } +% forming chain references to be used for navigation through a given named section + +\defc\SSS{\let\XXX\xxxchain} % reference separator + \def\xxxchain#1#2#3{% \xxxch@in{}{}#3, .% } @@ -349,7 +443,7 @@ % replace the default reference setting macros in gindex.sty; % typeset references so that, for example, \(77){8, 9} becomes -% \(\pdflink{77}{8c}), \(\pdfpagelink{9}) provided section 77 +% \(\compoundlink{77}{8c}), \(\pagelink{9}) provided section 77 % is section 8c by noweb's reckoning. \def\consumeonexref#1#2{% #1 is the accumulated references @@ -357,12 +451,12 @@ \expandafter\ifx\csname lxref[#2]\endcsname\relax \errmessage{Section #2 does not have a local index.}% \else - \yybreak{\expandafter\c@nsumeonexref\romannumeral-1\xref@nowebsection{#2}{#2}{#1}}% + \yybreak{\expandafter\c@nsumeonexref\romannumeral-1\xref@sectionorchapter{#2}{#2}{#1}}% \yycontinue } \def\c@nsumeonexref#1#2#3#4#5{% #1 is the page number of the beginning of the section - % #2 is the (\noweb) section number (within the page) where the term appears + % #2 is the (\noweb) section or chapter reference where the term appears % #3 is the (\CWEB) section number there the term appears % #4 is the accumulated references % #5 is a list of pages where this term appears @@ -370,13 +464,13 @@ } \def\c@nsume@nexref#1#2#3#4#5#6, {% #1 is the page number of the beginning of the section - % #2 is the (\noweb) section number (within the page) where the term appears + % #2 is the (\noweb) section or chapter reference where the term appears % #3 is the (\CWEB) section number where the term appears % #4 is a total list of processed references % #5 is a local list of processed references % #6 is a page number from the list \ifnum#1=#6 % the term appears on the same page where the section begins - \yybreak{\c@nsume@nexr@f{#1}{#2}{#3}#4{#5}{\compoundlink{#3}{#1#2}}}% + \yybreak{\c@nsume@nexr@f{#1}{#2}{#3}#4{#5}{\compoundlink{#3}{#2}}}% \else \yybreak{\c@nsume@nexr@f{#1}{#2}{#3}#4{#5}{\pagelink{#6}}}% \yycontinue @@ -397,3 +491,5 @@ \def\attachlocallist#1#2#3#4#5#6#7{% \grabfinexrefs{#6#7}% } + +\toyyunion{aux:global:xrefs} |