Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

If it's worth hacking on well, it's worth hacking on for money.


computers / comp.text.tex / Re: Recognising \end{macrocode}

SubjectAuthor
* Recognising \end{macrocode}Peter Flynn
+* Re: Recognising \end{macrocode}Peter Flynn
|+- Re: Recognising \end{macrocode}Ulrich D i e z
|`- Re: Recognising \end{macrocode}Ulrich D i e z
+* Re: Recognising \end{macrocode}Ulrich D i e z
|`- Re: Recognising \end{macrocode}Peter Flynn
`- Re: Recognising \end{macrocode}Ulrich D i e z

1
Recognising \end{macrocode}

<l2amvdF3d5aU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=8097&group=comp.text.tex#8097

  copy link   Newsgroups: comp.text.tex
Path: i2pn2.org!i2pn.org!news.niel.me!news.gegeweb.eu!gegeweb.org!news.mb-net.net!open-news-network.org!news.mind.de!bolzen.all.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: peter@silmaril.ie (Peter Flynn)
Newsgroups: comp.text.tex
Subject: Recognising \end{macrocode}
Date: Mon, 5 Feb 2024 00:03:57 +0000
Lines: 30
Message-ID: <l2amvdF3d5aU1@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net W9FFzEreWb8Hy3NuVkDWugS9UE2Hfr1AXTW8K8m3g/OfSPiNc5
Cancel-Lock: sha1:j6CM0TSq2BHKUM/Pa2GJeti2CFs= sha256:w0x6JYUkpC6c7rLwQXjtu+wHHRjmLekSvDd+qYQUpPw=
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Content-Language: en-US
 by: Peter Flynn - Mon, 5 Feb 2024 00:03 UTC

I'm using doc and dox to document a package which includes some XSLT
code which generates a .dtx file, and therefore includes the strings
'% \begin{macrocode}' and '% \end{macrocode}' inside the code to
be documented, eg

% \begin{macrocode}
<xsl:text>% \begin{macrocode}&#xa;</xsl:text>
<xsl:if test="db:constraintdef[db:cmdsynopsis[db:command]]">
<xsl:for-each select="db:constraintdef/db:cmdsynopsis/db:command">
<xsl:value-of select="."/>
<xsl:text>&#xa;</xsl:text>
</xsl:for-each>
</xsl:if>
<xsl:text>% \end{macrocode}&#xa;</xsl:text>
% \end{macrocode}

Although the string '% \end{macrocode}' occurs *within* the line, and
not at the start of the line, it is still being recognised as the end of
the containing macrocode environment:

> ! Misplaced alignment tab character &.
> l.15885 ... <xsl:text>% \end{macrocode}&
> #xa;</xsl:text>
> I can't figure out why you would want to use a tab mark

Is there a way to configure doc/dox to recognise the end of the
environment only when the '% \end{macrocode}' occurs at the beginning
of a line?

Peter

Re: Recognising \end{macrocode}

<l2cinaFdar2U1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=8101&group=comp.text.tex#8101

  copy link   Newsgroups: comp.text.tex
Path: i2pn2.org!rocksolid2!news.neodome.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: peter@silmaril.ie (Peter Flynn)
Newsgroups: comp.text.tex
Subject: Re: Recognising \end{macrocode}
Date: Mon, 5 Feb 2024 17:03:38 +0000
Lines: 154
Message-ID: <l2cinaFdar2U1@mid.individual.net>
References: <l2amvdF3d5aU1@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net WkiuxD0LIZDZqyxMNoNzPA5FXDtGtnUmHhuHHPd61SmRJVXMYb
Cancel-Lock: sha1:XkyrJjdNvLvS7oqgmSyOYaTj+Qg= sha256:5yCjf/NzW4e1mSXAn8FWHhHMWhHgKTs01wojX5ejPzs=
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Content-Language: en-US
In-Reply-To: <l2amvdF3d5aU1@mid.individual.net>
 by: Peter Flynn - Mon, 5 Feb 2024 17:03 UTC

On 05/02/2024 00:03, Peter Flynn wrote:
> I'm using doc and dox to document a package which includes some XSLT
> code which generates a .dtx file, and therefore includes the
> strings '% \begin{macrocode}' and '% \end{macrocode}' inside
> the code to be documented,
[...]
> Although the string '% \end{macrocode}' occurs *within* the line,
> and not at the start of the line, it is still being recognised as the
> end of the containing macrocode environment:

I have managed to create a MWE for this.

------------------------------8<------------------------------
% \iffalse meta-comment
% A test
% \fi
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}[2015/01/01]
%<package>\ProvidesPackage{test}[2023/12/30 v1.26
%<package> Test]
%<*driver>
\PassOptionsToPackage{svgnames}{xcolor}
\documentclass[11pt]{ltxdoc}
\usepackage{dox}%
\usepackage{fontspec}%
\usepackage{xcolor}%
\usepackage{hypdoc}%
\hypersetup{linkcolor=DarkGreen,citecolor=DarkRed,
urlcolor=Blue,colorlinks=true}
\usepackage{hyperref}%
\hypersetup{linkcolor=DarkGreen,citecolor=DarkRed,
urlcolor=Blue,colorlinks=true}
\hypersetup{pdfauthor={Peter Flynn},
pdftitle={The test LaTeX2e document package},
pdfsubject={Testing123},
pdfkeywords={latex,typesetting},
pdfproducer={XeLateX with hyperref},
pdfcreator={Emacs with psgml, ClassPack with Saxon, LaTeX from
TeX Live}}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}\raggedright
\DocInput{test.dtx}
\end{document}
%</driver>
% \fi
% % \CheckSum{7}
% % \CharacterTable
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
% Digits \0\1\2\3\4\5\6\7\8\9
% Exclamation \! Double quote \" Hash (number) \#
% Dollar \$ Percent \% Ampersand \&
% Acute accent \' Left paren \( Right paren \)
% Asterisk \* Plus \+ Comma \,
% Minus \- Point \. Solidus \/
% Colon \: Semicolon \; Less than \<
% Equals \= Greater than \> Question mark \?
% Commercial at \@ Left bracket \[ Backslash \\
% Right bracket \] Circumflex \^ Underscore \_
% Grave accent \` Left brace \{ Vertical bar \|
% Right brace \} Tilde \~}
% % \GetFileInfo{test.dtx}
% \def\fileversion{1.26}
% \def\filedate{2023/12/30}
% \title{The \textsf{test} \LaTeXe\ package\thanks{%
% This document corresponds to \textsf{test}
% \textit{v.}\ \fileversion , dated \filedate.}
% \\[1em]\Large
% Testing dox/doc
% \\[1ex]\large
% on XSLT generating DTX}
% \author{Peter Flynn}
% \maketitle
% \renewcommand{\abstractname}{Summary}\thispagestyle{empty}
% \begin{abstract}
% Test
% \end{abstract}
% \clearpage
% \tableofcontents
% \clearpage
% \section{Test}
% Test
% \clearpage
% \StopEventually{\label{endcode}%
% \clearpage
% \addcontentsline{toc}{section}{Change History}%
% \label{changehistory}%
% \PrintChanges
% \clearpage
% \label{codeindex}%
% \addcontentsline{toc}{section}{Index}%
% \PrintIndex}
% \iffalse
%<*package>
% \fi
% \clearpage
% \section{The \textsf{test} macros}
% \iffalse
%</package>
% \fi
% \iffalse
%<*testscript>
% \fi
% \clearpage
% \section{The \emph{test.xsl} script}
% \setcounter{CodelineNo}{0}
% Now look: this normal usage works fine
% Identify the file origin, date, time, etc.\par
% \begin{macrocode}
<!-- The test.xsl script 24-02-04T21:01:06 -->
% \end{macrocode}
% Here we show the XSLT to handle a DocBook <sect1>
% IMPORTANT: it is supposed to generate the DTX code as-is
% between <xsl:text> and </xsl:text>
% \begin{macrocode}
<xsl:template match="db:sect1">
<!-- process sect1 content -->
<xsl:apply-templates/>
<xsl:if test="@xml:id='options'">
<xsl:text>% Now invoke the options.\par
% \iffalse
%% Now invoke the options.
% \fi
% \begin{macrocode}
\ExecuteOptions{</xsl:text>
<xsl:value-of
select="descendant::db:annotation/@xreflabel"/>
<xsl:text>}
\ProcessOptions\relax
% \end{macrocode}&#xa;</xsl:text>
</xsl:if>
<xsl:call-template name="checkpackages">
<xsl:with-param name="pos" select="'after'"/>
<xsl:with-param name="loc" select="."/>
</xsl:call-template>
</xsl:if>
</xsl:template>
% \end{macrocode}
% That's all, folks!
% \iffalse
%</db2dtxscript>
% \fi
% \Finale
------------------------------8<------------------------------

Cut that out into test.dtx and run through XeLaTeX.

Peter

Re: Recognising \end{macrocode}

<upr7cr$1cpmm$1@solani.org>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=8102&group=comp.text.tex#8102

  copy link   Newsgroups: comp.text.tex
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: ud.usenetcorrespondence@web.de (Ulrich D i e z)
Newsgroups: comp.text.tex
Subject: Re: Recognising \end{macrocode}
Date: Mon, 5 Feb 2024 18:55:02 +0100
Message-ID: <upr7cr$1cpmm$1@solani.org>
References: <l2amvdF3d5aU1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 5 Feb 2024 17:54:35 -0000 (UTC)
Injection-Info: solani.org;
logging-data="1468118"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:60.0) Gecko/20100101
Thunderbird/60.9.0
Cancel-Lock: sha1:XyZ4mEzSCNXpukwYvI6IDxJ6nHw=
Content-Language: en-US
In-Reply-To: <l2amvdF3d5aU1@mid.individual.net>
X-User-ID: eJwNwoERwEAEBMCW8O68ckjov4RkdnGofMIJOvZXJRghzYIYJBtuG/c9g84FRrvyuuiR8v0ACZMQdg==
 by: Ulrich D i e z - Mon, 5 Feb 2024 17:55 UTC

Peter Flynn wrote:

> I'm using doc and dox to document a package which includes some XSLT code which generates a .dtx file, and therefore includes the strings
> '%    \begin{macrocode}' and '%    \end{macrocode}' inside the code to be documented, eg
>
> %    \begin{macrocode}
>   <xsl:text>%    \begin{macrocode}&#xa;</xsl:text>
>    <xsl:if test="db:constraintdef[db:cmdsynopsis[db:command]]">
>     <xsl:for-each select="db:constraintdef/db:cmdsynopsis/db:command">
>       <xsl:value-of select="."/>
>       <xsl:text>&#xa;</xsl:text>
>     </xsl:for-each>
>   </xsl:if>
>   <xsl:text>%    \end{macrocode}&#xa;</xsl:text>
> %    \end{macrocode}
>
> Although the string '%    \end{macrocode}' occurs *within* the line, and not at the start of the line, it is still being recognised as the end of the containing macrocode environment:
>
>> ! Misplaced alignment tab character &.
>> l.15885 ...    <xsl:text>%    \end{macrocode}&
>>                                                   #xa;</xsl:text>
>> I can't figure out why you would want to use a tab mark
>
> Is there a way to configure doc/dox to recognise the end of the environment only when the '%    \end{macrocode}' occurs at the beginning of a line?

I don't know dox.

As far as I know, the package doc does not provide facilities for
configuring such behavior.

How about patching the environments macrocode and macrocode* of the
package doc so that you can specify the amount of ending-phrases
of these environments that should be ignored when scanning for the end
of an instance of such an environment.

However, patching these environments is a crucial action as with the
development of the package doc the internals of these environments
may be subject to change so that patching needs to be adapted to those
changes.

I assume that the doc package version number v3.0m dated 2022/11/13
is in use (currently - February 5, 2024 - the most recent one) and
wrote a patch so that by (re)defining the macro \SkipMacrocodeEndings
accordingly you can have these environments ignore as many instances
of the ending phrase of the environment in question as denoted by
\SkipMacrocodeEndings while scanning for the end of that environment.

Internally this is done by scanning for delimiters
% \end{macrocode}
respective
% \end{macrocode*}
(tokenized in verbatim catciode-régime with categories of
spaces and backslashes as determined by the environments)
and replacing m of category 11(letter) by m of category 12(other)
so that the delimiter-matching of the mechanism that scans for the
end of the environment won't match.

With this patch you can do things like

% \begingroup
% \def\SkipMacrocodeEndings{3}
% \begin{macrocode}
something
% \end{macrocode} % 1st ending phrase not considered the end.
% \end{macrocode} % 2nd ending phrase not considered the end.
% \end{macrocode} % 3rd ending phrase not considered the end.
% \end{macrocode} % this ending-phrase is considered the end.
% \endgroup

I **think** this patch does not interfere with the indexing-
and glossary-machineries of the package doc, but be picky anyway
when checking whether the output is as desired.

-----[Snip]-Begin of file mytest.tex------------------------------------
%\errorcontextlines=10000

% Let's create a file myfile.dtx:
\begin{filecontents*}{myfile.dtx}
% \begingroup
% \def\SkipMacrocodeEndings{1}%
% \begin{macrocode}
<xsl:text>% \begin{macrocode}&#xa;</xsl:text>
<xsl:if test="db:constraintdef[db:cmdsynopsis[db:command]]">
<xsl:for-each select="db:constraintdef/db:cmdsynopsis/db:command">
<xsl:value-of select="."/>
<xsl:text>&#xa;</xsl:text>
</xsl:for-each>
</xsl:if>
<xsl:text>% \end{macrocode}&#xa;</xsl:text>
% \end{macrocode}
% \endgroup
\end{filecontents*}

\documentclass[a4paper]{article}
\usepackage{doc}

\makeatletter
%=======================================================================
% \MyReplicate{<amount>}{<tokens>}
% After triggering two expansion-steps <tokens> are appended to the
% token stream <amount> times.
% E.g., \MyReplicate{10}{X} yields XXXXXXXXXX
%-----------------------------------------------------------------------
% Define a TeX-number-quantity of non-positive value
\@ifdefinable\MyStopromannumeral{\chardef\MyStopromannumeral=`\^^00}%
%-----------------------------------------------------------------------
% Define Paraphernalia:
\newcommand\Myfot[2]{#1}%
\newcommand\Mysot[2]{#2}%
\newcommand\Myexchg[2]{#2#1}%
%-----------------------------------------------------------------------
% Define the loop:
\newcommand\MyReplicate[2]{%
% #1 amount of replications
% #2 tokens to replicate
\romannumeral\expandafter\Myexchg
\expandafter{\romannumeral\number\number#1 000\relax}%
{\MyReplicateloop{#2}{}}%
}%
\newcommand\MyReplicateloop[3]{%
% #1 tokens to replicate
% #2 replications gathered so far
% #3 lowercase letter m or \relax
\ifx#3\relax\expandafter\Mysot\else\expandafter\Myfot\fi
{\MyReplicateloop{#1}{#2#1}}%
{\MyStopromannumeral#2}%
}%
%=======================================================================
% \NeutralizeOneUnstarredEndMacrocode replaces the delimiter
% % \end{macrocode} by the same but with m of catcode 11 replaced
% by m of catcode 12.
%-----------------------------------------------------------------------
% \NeutralizeOneStarredEndMacrocode replaces the delimiter
% % \end{macrocode*} by the same but with m of catcode 11 replaced
% by m of catcode 12.
%-----------------------------------------------------------------------
\begingroup
\catcode`\|=0
\catcode`\[=1
\catcode`\]=2
\catcode`\{=12
\catcode`\}=12
\catcode`\%=12
\catcode`\Y=14
\catcode`\\=\active
|def|NeutralizerDefiner#1#2#3#4[Y
|gdef#1##1%#2#2#2#2\end{macrocode#4}[##1%#2#2#2#2\end{#3acrocode#4}]Y
]Y
|catcode`|m =12Y
|catcode`| =|active
|@ifdefinable|NeutralizeOneUnstarredEndMacrocode[Y
|NeutralizerDefiner[|NeutralizeOneUnstarredEndMacrocode][ ][m][]Y
]Y
|catcode`| =12Y
|@ifdefinable|NeutralizeOneStarredEndMacrocode[Y
|NeutralizerDefiner[|NeutralizeOneStarredEndMacrocode][ ][m][*]Y
]Y
|endgroup
%=======================================================================
% \NeutralizeInstancesOfUnstarredEndMacrocode{<amount>} replaces
% <amount> instances of the delimiter % \end{macrocode} by the same
% but with m of catcode 11 replaced by m of catcode 12.
%-----------------------------------------------------------------------
% \NeutralizeInstancesOfStarredEndMacrocode{<amount>} replaces
% <amount> instances of the delimiter % \end{macrocode*} by the same
% but with m of catcode 11 replaced by m of catcode 12.
%-----------------------------------------------------------------------
\newcommand\NeutralizeInstancesOfUnstarredEndMacrocode[1]{%
\MyReplicate{#1}{\NeutralizeOneUnstarredEndMacrocode}%
}%
\newcommand\NeutralizeInstancesOfStarredEndMacrocode[1]{%
\MyReplicate{#1}{\NeutralizeOneStarredEndMacrocode}%
}%
%=======================================================================
% Patch the environments macrocode and macrocode* of the package doc
% so that by redefining the macro \SkipMacrocodeEndings accordingly
% you can have these environments ignore as many instances of the
% ending phrase of the environment in question as denoted by
% \SkipMacrocodeEndings while scanning for the end of that environment.
\def\SkipMacrocodeEndings{0}%
\@namedef{macrocode*}{%
\macro@code
\NeutralizeInstancesOfStarredEndMacrocode\SkipMacrocodeEndings
\sxmacro@code
}%
\def\macrocode{%
\macro@code
\frenchspacing\@vobeyspaces
\NeutralizeInstancesOfUnstarredEndMacrocode\SkipMacrocodeEndings
\xmacro@code
}%
\makeatother

\EnableCrossrefs
\CodelineIndex

\begin{document}

\DocInput{myfile.dtx}

% Index: makeindex -s gind.ist -o mytest.ind mytest.idx
% Change-history: makeindex -s gglo.ist -o mytest.gls mytest.glo
\PrintIndex

\end{document}
-----[Snap]-End of file mytest.tex--------------------------------------

Here you can see an image of the output I get on my system
when compiling the example above:
<https://i.stack.imgur.com/azQEv.png>

Sincerely

Ulrich

Re: Recognising \end{macrocode}

<upr8r2$1cqfb$1@solani.org>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=8103&group=comp.text.tex#8103

  copy link   Newsgroups: comp.text.tex
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: ud.usenetcorrespondence@web.de (Ulrich D i e z)
Newsgroups: comp.text.tex
Subject: Re: Recognising \end{macrocode}
Date: Mon, 5 Feb 2024 19:19:42 +0100
Message-ID: <upr8r2$1cqfb$1@solani.org>
References: <l2amvdF3d5aU1@mid.individual.net>
<l2cinaFdar2U1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 5 Feb 2024 18:19:15 -0000 (UTC)
Injection-Info: solani.org;
logging-data="1468907"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:60.0) Gecko/20100101
Thunderbird/60.9.0
Cancel-Lock: sha1:vMGyU7264uua86Qmt6ne+WLN6lo=
X-User-ID: eJwFwYEBwCAIA7CXwFLQc9CO/09YQqTnq0hmcDhoPzYkrdhrH+qz8A1Xj+4Nl+wM8JorhfoBC7IQxQ==
Content-Language: en-US
In-Reply-To: <l2cinaFdar2U1@mid.individual.net>
 by: Ulrich D i e z - Mon, 5 Feb 2024 18:19 UTC

Peter Flynn schrieb:

> I have managed to create a MWE for this.
[...]
> Cut that out into test.dtx and run through XeLaTeX.

Does the following code do what you want?

Sincerely

Ulrich

% \iffalse meta-comment
% A test
% \fi
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}[2015/01/01]
%<package>\ProvidesPackage{test}[2023/12/30 v1.26
%<package> Test]
%<*driver>
\PassOptionsToPackage{svgnames}{xcolor}
\documentclass[11pt]{ltxdoc}

\makeatletter
%=======================================================================
% \MyReplicate{<amount>}{<tokens>}
% After triggering two expansion-steps <tokens> are appended to the
% token stream <amount> times.
% E.g., \MyReplicate{10}{X} yields XXXXXXXXXX
%-----------------------------------------------------------------------
% Define a TeX-number-quantity of non-positive value
\@ifdefinable\MyStopromannumeral{\chardef\MyStopromannumeral=`\^^00}%
%-----------------------------------------------------------------------
% Define Paraphernalia:
\newcommand\Myfot[2]{#1}%
\newcommand\Mysot[2]{#2}%
\newcommand\Myexchg[2]{#2#1}%
%-----------------------------------------------------------------------
% Define the loop:
\newcommand\MyReplicate[2]{%
% #1 amount of replications
% #2 tokens to replicate
\romannumeral\expandafter\Myexchg
\expandafter{\romannumeral\number\number#1 000\relax}%
{\MyReplicateloop{#2}{}}%
}%
\newcommand\MyReplicateloop[3]{%
% #1 tokens to replicate
% #2 replications gathered so far
% #3 lowercase letter m or \relax
\ifx#3\relax\expandafter\Mysot\else\expandafter\Myfot\fi
{\MyReplicateloop{#1}{#2#1}}%
{\MyStopromannumeral#2}%
}%
%=======================================================================
% \NeutralizeOneUnstarredEndMacrocode replaces the delimiter
% % \end{macrocode} by the same but with m of catcode 11 replaced
% by m of catcode 12.
%-----------------------------------------------------------------------
% \NeutralizeOneStarredEndMacrocode replaces the delimiter
% % \end{macrocode*} by the same but with m of catcode 11 replaced
% by m of catcode 12.
%-----------------------------------------------------------------------
\begingroup
\catcode`\|=0
\catcode`\[=1
\catcode`\]=2
\catcode`\{=12
\catcode`\}=12
\catcode`\%=12
\catcode`\Y=14
\catcode`\\=\active
|def|NeutralizerDefiner#1#2#3#4[Y
|gdef#1##1%#2#2#2#2\end{macrocode#4}[##1%#2#2#2#2\end{#3acrocode#4}]Y
]Y
|catcode`|m =12Y
|catcode`| =|active
|@ifdefinable|NeutralizeOneUnstarredEndMacrocode[Y
|NeutralizerDefiner[|NeutralizeOneUnstarredEndMacrocode][ ][m][]Y
]Y
|catcode`| =12Y
|@ifdefinable|NeutralizeOneStarredEndMacrocode[Y
|NeutralizerDefiner[|NeutralizeOneStarredEndMacrocode][ ][m][*]Y
]Y
|endgroup
%=======================================================================
% \NeutralizeInstancesOfUnstarredEndMacrocode{<amount>} replaces
% <amount> instances of the delimiter % \end{macrocode} by the same
% but with m of catcode 11 replaced by m of catcode 12.
%-----------------------------------------------------------------------
% \NeutralizeInstancesOfStarredEndMacrocode{<amount>} replaces
% <amount> instances of the delimiter % \end{macrocode*} by the same
% but with m of catcode 11 replaced by m of catcode 12.
%-----------------------------------------------------------------------
\newcommand\NeutralizeInstancesOfUnstarredEndMacrocode[1]{%
\MyReplicate{#1}{\NeutralizeOneUnstarredEndMacrocode}%
}%
\newcommand\NeutralizeInstancesOfStarredEndMacrocode[1]{%
\MyReplicate{#1}{\NeutralizeOneStarredEndMacrocode}%
}%
%=======================================================================
% Patch the environments macrocode and macrocode* of the package doc
% so that by redefining the macro \SkipMacrocodeEndings accordingly
% you can have these environments ignore as many instances of the
% ending phrase of the environment in question as denoted by
% \SkipMacrocodeEndings while scanning for the end of that environment.
\def\SkipMacrocodeEndings{0}%
\@namedef{macrocode*}{%
\macro@code
\NeutralizeInstancesOfStarredEndMacrocode\SkipMacrocodeEndings
\sxmacro@code
}%
\def\macrocode{%
\macro@code
\frenchspacing\@vobeyspaces
\NeutralizeInstancesOfUnstarredEndMacrocode\SkipMacrocodeEndings
\xmacro@code
}%
\makeatother

\usepackage{dox}%
\usepackage{fontspec}%
\usepackage{xcolor}%
\usepackage{hypdoc}%
\hypersetup{linkcolor=DarkGreen,citecolor=DarkRed,
urlcolor=Blue,colorlinks=true}
\usepackage{hyperref}%
\hypersetup{linkcolor=DarkGreen,citecolor=DarkRed,
urlcolor=Blue,colorlinks=true}
\hypersetup{pdfauthor={Peter Flynn},
pdftitle={The test LaTeX2e document package},
pdfsubject={Testing123},
pdfkeywords={latex,typesetting},
pdfproducer={XeLateX with hyperref},
pdfcreator={Emacs with psgml, ClassPack with Saxon, LaTeX from TeX Live}}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}\raggedright
\DocInput{test.dtx}
\end{document}
%</driver>
% \fi
% % \CheckSum{8}
% % \CharacterTable
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
% Digits \0\1\2\3\4\5\6\7\8\9
% Exclamation \! Double quote \" Hash (number) \#
% Dollar \$ Percent \% Ampersand \&
% Acute accent \' Left paren \( Right paren \)
% Asterisk \* Plus \+ Comma \,
% Minus \- Point \. Solidus \/
% Colon \: Semicolon \; Less than \<
% Equals \= Greater than \> Question mark \?
% Commercial at \@ Left bracket \[ Backslash \\
% Right bracket \] Circumflex \^ Underscore \_
% Grave accent \` Left brace \{ Vertical bar \|
% Right brace \} Tilde \~}
% % \GetFileInfo{test.dtx}
% \def\fileversion{1.26}
% \def\filedate{2023/12/30}
% \title{The \textsf{test} \LaTeXe\ package\thanks{%
% This document corresponds to \textsf{test}
% \textit{v.}\ \fileversion , dated \filedate.}
% \\[1em]\Large
% Testing dox/doc
% \\[1ex]\large
% on XSLT generating DTX}
% \author{Peter Flynn}
% \maketitle
% \renewcommand{\abstractname}{Summary}\thispagestyle{empty}
% \begin{abstract}
% Test
% \end{abstract}
% \clearpage
% \tableofcontents
% \clearpage
% \section{Test}
% Test
% \clearpage
% \StopEventually{\label{endcode}%
% \clearpage
% \addcontentsline{toc}{section}{Change History}%
% \label{changehistory}%
% \PrintChanges
% \clearpage
% \label{codeindex}%
% \addcontentsline{toc}{section}{Index}%
% \PrintIndex}
% \iffalse
%<*package>
% \fi
% \clearpage
% \section{The \textsf{test} macros}
% \iffalse
%</package>
% \fi
% \iffalse
%<*testscript>
% \fi
% \clearpage
% \section{The \emph{test.xsl} script}
% \setcounter{CodelineNo}{0}
% Now look: this normal usage works fine
% Identify the file origin, date, time, etc.\par
% \begin{macrocode}
<!-- The test.xsl script 24-02-04T21:01:06 -->
% \end{macrocode}
% Here we show the XSLT to handle a DocBook <sect1>
% IMPORTANT: it is supposed to generate the DTX code as-is
% between <xsl:text> and </xsl:text>
% \begingroup ^^A-----------------------------------------------
% \def\SkipMacrocodeEndings{1}%
% \begin{macrocode}
<xsl:template match="db:sect1">
<!-- process sect1 content -->
<xsl:apply-templates/>
<xsl:if test="@xml:id='options'">
<xsl:text>% Now invoke the options.\par
% \iffalse
%% Now invoke the options.
% \fi
% \begin{macrocode}
\ExecuteOptions{</xsl:text>
<xsl:value-of
select="descendant::db:annotation/@xreflabel"/>
<xsl:text>}
\ProcessOptions\relax
% \end{macrocode}&#xa;</xsl:text>
</xsl:if>
<xsl:call-template name="checkpackages">
<xsl:with-param name="pos" select="'after'"/>
<xsl:with-param name="loc" select="."/>
</xsl:call-template>
</xsl:if>
</xsl:template>
% \end{macrocode}
% \endgroup ^^A-------------------------------------------------
% That's all, folks!
% \iffalse
%</db2dtxscript>
% \fi
% \Finale

Re: Recognising \end{macrocode}

<uprcbm$1cscb$1@solani.org>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=8105&group=comp.text.tex#8105

  copy link   Newsgroups: comp.text.tex
Path: i2pn2.org!i2pn.org!paganini.bofh.team!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: ud.usenetcorrespondence@web.de (Ulrich D i e z)
Newsgroups: comp.text.tex
Subject: Re: Recognising \end{macrocode}
Date: Mon, 5 Feb 2024 20:19:45 +0100
Message-ID: <uprcbm$1cscb$1@solani.org>
References: <l2amvdF3d5aU1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 5 Feb 2024 19:19:19 -0000 (UTC)
Injection-Info: solani.org;
logging-data="1470859"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:60.0) Gecko/20100101
Thunderbird/60.9.0
Cancel-Lock: sha1:KC+PL3FHjmyxWAAoMGgrqIo2c6w=
Content-Language: en-US
X-User-ID: eJwNyskBwDAIA7CVOE07TsFh/xFSvZUOxVQgEbm5R9yUeG12yd5uCwV7OOKe/Xc+tWAdfuJ1ATRSEeQ=
In-Reply-To: <l2amvdF3d5aU1@mid.individual.net>
 by: Ulrich D i e z - Mon, 5 Feb 2024 19:19 UTC

[I just realized that the code for macrocode* lacks \relax, so let's fix this:]

Peter Flynn wrote:

> I'm using doc and dox to document a package which includes some XSLT code which generates a .dtx file, and therefore includes the strings
> '% \begin{macrocode}' and '% \end{macrocode}' inside the code to be documented, eg
>
> % \begin{macrocode}
> <xsl:text>% \begin{macrocode}&#xa;</xsl:text>
> <xsl:if test="db:constraintdef[db:cmdsynopsis[db:command]]">
> <xsl:for-each select="db:constraintdef/db:cmdsynopsis/db:command">
> <xsl:value-of select="."/>
> <xsl:text>&#xa;</xsl:text>
> </xsl:for-each>
> </xsl:if>
> <xsl:text>% \end{macrocode}&#xa;</xsl:text>
> % \end{macrocode}
>
> Although the string '% \end{macrocode}' occurs *within* the line, and not at the start of the line, it is still being recognised as the end of the containing macrocode environment:
>
>> ! Misplaced alignment tab character &.
>> l.15885 ... <xsl:text>% \end{macrocode}&
>> #xa;</xsl:text>
>> I can't figure out why you would want to use a tab mark
>
> Is there a way to configure doc/dox to recognise the end of the environment only when the '% \end{macrocode}' occurs at the beginning of a line?

I don't know dox.

As far as I know, the package doc does not provide facilities for
configuring such behavior.

How about patching the environments macrocode and macrocode* of the
package doc so that you can specify the amount of ending-phrases
of these environments that should be ignored when scanning for the end
of an instance of such an environment.

However, patching these environments is a crucial action as with the
development of the package doc the internals of these environments
may be subject to change so that patching needs to be adapted to those
changes.

I assume that the doc package version number v3.0m dated 2022/11/13
is in use (currently - February 5, 2024 - the most recent one) and
wrote a patch so that by (re)defining the macro \SkipMacrocodeEndings
accordingly you can have these environments ignore as many instances
of the ending phrase of the environment in question as denoted by
\SkipMacrocodeEndings while scanning for the end of that environment.

Internally this is done by scanning for delimiters
% \end{macrocode}
respective
% \end{macrocode*}
(tokenized in verbatim catciode-régime with categories of
spaces and backslashes as determined by the environments)
and replacing m of category 11(letter) by m of category 12(other)
so that the delimiter-matching of the mechanism that scans for the
end of the environment won't match.

With this patch you can do things like

% \begingroup
% \def\SkipMacrocodeEndings{3}
% \begin{macrocode}
something
% \end{macrocode} % 1st ending phrase not considered the end.
% \end{macrocode} % 2nd ending phrase not considered the end.
% \end{macrocode} % 3rd ending phrase not considered the end.
% \end{macrocode} % this ending-phrase is considered the end.
% \endgroup

I **think** this patch does not interfere with the indexing-
and glossary-machineries of the package doc, but be picky anyway
when checking whether the output is as desired.

-----[Snip]-Begin of file mytest.tex------------------------------------
%\errorcontextlines=10000

% Let's create a file myfile.dtx:
\begin{filecontents*}{myfile.dtx}
% \begingroup
% \def\SkipMacrocodeEndings{1}%
% \begin{macrocode}
<xsl:text>% \begin{macrocode}&#xa;</xsl:text>
<xsl:if test="db:constraintdef[db:cmdsynopsis[db:command]]">
<xsl:for-each select="db:constraintdef/db:cmdsynopsis/db:command">
<xsl:value-of select="."/>
<xsl:text>&#xa;</xsl:text>
</xsl:for-each>
</xsl:if>
<xsl:text>% \end{macrocode}&#xa;</xsl:text>
% \end{macrocode}
% \endgroup
\end{filecontents*}

\documentclass[a4paper]{article}
\usepackage{doc}

\makeatletter
%=======================================================================
% \MyReplicate{<amount>}{<tokens>}
% After triggering two expansion-steps <tokens> are appended to the
% token stream <amount> times.
% E.g., \MyReplicate{10}{X} yields XXXXXXXXXX
%-----------------------------------------------------------------------
% Define a TeX-number-quantity of non-positive value
\@ifdefinable\MyStopromannumeral{\chardef\MyStopromannumeral=`\^^00}%
%-----------------------------------------------------------------------
% Define Paraphernalia:
\newcommand\Myfot[2]{#1}%
\newcommand\Mysot[2]{#2}%
\newcommand\Myexchg[2]{#2#1}%
%-----------------------------------------------------------------------
% Define the loop:
\newcommand\MyReplicate[2]{%
% #1 amount of replications
% #2 tokens to replicate
\romannumeral\expandafter\Myexchg
\expandafter{\romannumeral\number\number#1 000\relax}%
{\MyReplicateloop{#2}{}}%
}%
\newcommand\MyReplicateloop[3]{%
% #1 tokens to replicate
% #2 replications gathered so far
% #3 lowercase letter m or \relax
\ifx#3\relax\expandafter\Mysot\else\expandafter\Myfot\fi
{\MyReplicateloop{#1}{#2#1}}%
{\MyStopromannumeral#2}%
}%
%=======================================================================
% \NeutralizeOneUnstarredEndMacrocode replaces the delimiter
% % \end{macrocode} by the same but with m of catcode 11 replaced
% by m of catcode 12.
%-----------------------------------------------------------------------
% \NeutralizeOneStarredEndMacrocode replaces the delimiter
% % \end{macrocode*} by the same but with m of catcode 11 replaced
% by m of catcode 12.
%-----------------------------------------------------------------------
\begingroup
\catcode`\|=0
\catcode`\[=1
\catcode`\]=2
\catcode`\{=12
\catcode`\}=12
\catcode`\%=12
\catcode`\Y=14
\catcode`\\=\active
|def|NeutralizerDefiner#1#2#3#4[Y
|gdef#1##1%#2#2#2#2\end{macrocode#4}[##1%#2#2#2#2\end{#3acrocode#4}]Y
]Y
|catcode`|m =12|relaxY
|catcode`| =|activeY
|@ifdefinable|NeutralizeOneUnstarredEndMacrocode[Y
|NeutralizerDefiner[|NeutralizeOneUnstarredEndMacrocode][ ][m][]Y
]Y
|catcode`| =12|relaxY
|@ifdefinable|NeutralizeOneStarredEndMacrocode[Y
|NeutralizerDefiner[|NeutralizeOneStarredEndMacrocode][ ][m][*]Y
]Y
|endgroup
%=======================================================================
% \NeutralizeInstancesOfUnstarredEndMacrocode{<amount>} replaces
% <amount> instances of the delimiter % \end{macrocode} by the same
% but with m of catcode 11 replaced by m of catcode 12.
%-----------------------------------------------------------------------
% \NeutralizeInstancesOfStarredEndMacrocode{<amount>} replaces
% <amount> instances of the delimiter % \end{macrocode*} by the same
% but with m of catcode 11 replaced by m of catcode 12.
%-----------------------------------------------------------------------
\newcommand\NeutralizeInstancesOfUnstarredEndMacrocode[1]{%
\MyReplicate{#1}{\NeutralizeOneUnstarredEndMacrocode}%
}%
\newcommand\NeutralizeInstancesOfStarredEndMacrocode[1]{%
\MyReplicate{#1}{\NeutralizeOneStarredEndMacrocode}%
}%
%=======================================================================
% Patch the environments macrocode and macrocode* of the package doc
% so that by redefining the macro \SkipMacrocodeEndings accordingly
% you can have these environments ignore as many instances of the
% ending phrase of the environment in question as denoted by
% \SkipMacrocodeEndings while scanning for the end of that environment.
\def\SkipMacrocodeEndings{0}%
\@namedef{macrocode*}{%
\macro@code
\NeutralizeInstancesOfStarredEndMacrocode\SkipMacrocodeEndings
\sxmacro@code
}%
\def\macrocode{%
\macro@code
\frenchspacing\@vobeyspaces
\NeutralizeInstancesOfUnstarredEndMacrocode\SkipMacrocodeEndings
\xmacro@code
}%
\makeatother

\EnableCrossrefs
\CodelineIndex

\begin{document}

\DocInput{myfile.dtx}

% Index: makeindex -s gind.ist -o mytest.ind mytest.idx
% Change-history: makeindex -s gglo.ist -o mytest.gls mytest.glo
\PrintIndex

\end{document}
-----[Snap]-End of file mytest.tex--------------------------------------

Here you can see an image of the output I get on my system
when compiling the example above:
<https://i.stack.imgur.com/azQEv.png>

Sincerely

Ulrich

Re: Recognising \end{macrocode}

<uprci9$1cscb$2@solani.org>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=8106&group=comp.text.tex#8106

  copy link   Newsgroups: comp.text.tex
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: ud.usenetcorrespondence@web.de (Ulrich D i e z)
Newsgroups: comp.text.tex
Subject: Re: Recognising \end{macrocode}
Date: Mon, 5 Feb 2024 20:23:17 +0100
Message-ID: <uprci9$1cscb$2@solani.org>
References: <l2amvdF3d5aU1@mid.individual.net>
<l2cinaFdar2U1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 5 Feb 2024 19:22:50 -0000 (UTC)
Injection-Info: solani.org;
logging-data="1470859"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:60.0) Gecko/20100101
Thunderbird/60.9.0
Cancel-Lock: sha1:ancvsmwFGC0jRQPG0A5aNrwa1io=
X-User-ID: eJwFwQkBwDAIA0BLfAnMTkvjX8LukHTeLoIFQTvVEnIYsBdZvGcZo6/n0ZzZab6vZceX9gMJeRBN
In-Reply-To: <l2cinaFdar2U1@mid.individual.net>
Content-Language: en-US
 by: Ulrich D i e z - Mon, 5 Feb 2024 19:23 UTC

[I just realized that the code for macrocode* lacks \relax, so let's fix this:]

Peter Flynn wrote:

> I have managed to create a MWE for this.
[...]
> Cut that out into test.dtx and run through XeLaTeX.

Does the following code do what you want?

Sincerely

Ulrich

% \iffalse meta-comment
% A test
% \fi
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}[2015/01/01]
%<package>\ProvidesPackage{test}[2023/12/30 v1.26
%<package> Test]
%<*driver>
\PassOptionsToPackage{svgnames}{xcolor}
\documentclass[11pt]{ltxdoc}

\makeatletter
%=======================================================================
% \MyReplicate{<amount>}{<tokens>}
% After triggering two expansion-steps <tokens> are appended to the
% token stream <amount> times.
% E.g., \MyReplicate{10}{X} yields XXXXXXXXXX
%-----------------------------------------------------------------------
% Define a TeX-number-quantity of non-positive value
\@ifdefinable\MyStopromannumeral{\chardef\MyStopromannumeral=`\^^00}%
%-----------------------------------------------------------------------
% Define Paraphernalia:
\newcommand\Myfot[2]{#1}%
\newcommand\Mysot[2]{#2}%
\newcommand\Myexchg[2]{#2#1}%
%-----------------------------------------------------------------------
% Define the loop:
\newcommand\MyReplicate[2]{%
% #1 amount of replications
% #2 tokens to replicate
\romannumeral\expandafter\Myexchg
\expandafter{\romannumeral\number\number#1 000\relax}%
{\MyReplicateloop{#2}{}}%
}%
\newcommand\MyReplicateloop[3]{%
% #1 tokens to replicate
% #2 replications gathered so far
% #3 lowercase letter m or \relax
\ifx#3\relax\expandafter\Mysot\else\expandafter\Myfot\fi
{\MyReplicateloop{#1}{#2#1}}%
{\MyStopromannumeral#2}%
}%
%=======================================================================
% \NeutralizeOneUnstarredEndMacrocode replaces the delimiter
% % \end{macrocode} by the same but with m of catcode 11 replaced
% by m of catcode 12.
%-----------------------------------------------------------------------
% \NeutralizeOneStarredEndMacrocode replaces the delimiter
% % \end{macrocode*} by the same but with m of catcode 11 replaced
% by m of catcode 12.
%-----------------------------------------------------------------------
\begingroup
\catcode`\|=0
\catcode`\[=1
\catcode`\]=2
\catcode`\{=12
\catcode`\}=12
\catcode`\%=12
\catcode`\Y=14
\catcode`\\=\active
|def|NeutralizerDefiner#1#2#3#4[Y
|gdef#1##1%#2#2#2#2\end{macrocode#4}[##1%#2#2#2#2\end{#3acrocode#4}]Y
]Y
|catcode`|m =12|relaxY
|catcode`| =|activeY
|@ifdefinable|NeutralizeOneUnstarredEndMacrocode[Y
|NeutralizerDefiner[|NeutralizeOneUnstarredEndMacrocode][ ][m][]Y
]Y
|catcode`| =12|relaxY
|@ifdefinable|NeutralizeOneStarredEndMacrocode[Y
|NeutralizerDefiner[|NeutralizeOneStarredEndMacrocode][ ][m][*]Y
]Y
|endgroup
%=======================================================================
% \NeutralizeInstancesOfUnstarredEndMacrocode{<amount>} replaces
% <amount> instances of the delimiter % \end{macrocode} by the same
% but with m of catcode 11 replaced by m of catcode 12.
%-----------------------------------------------------------------------
% \NeutralizeInstancesOfStarredEndMacrocode{<amount>} replaces
% <amount> instances of the delimiter % \end{macrocode*} by the same
% but with m of catcode 11 replaced by m of catcode 12.
%-----------------------------------------------------------------------
\newcommand\NeutralizeInstancesOfUnstarredEndMacrocode[1]{%
\MyReplicate{#1}{\NeutralizeOneUnstarredEndMacrocode}%
}%
\newcommand\NeutralizeInstancesOfStarredEndMacrocode[1]{%
\MyReplicate{#1}{\NeutralizeOneStarredEndMacrocode}%
}%
%=======================================================================
% Patch the environments macrocode and macrocode* of the package doc
% so that by redefining the macro \SkipMacrocodeEndings accordingly
% you can have these environments ignore as many instances of the
% ending phrase of the environment in question as denoted by
% \SkipMacrocodeEndings while scanning for the end of that environment.
\def\SkipMacrocodeEndings{0}%
\@namedef{macrocode*}{%
\macro@code
\NeutralizeInstancesOfStarredEndMacrocode\SkipMacrocodeEndings
\sxmacro@code
}%
\def\macrocode{%
\macro@code
\frenchspacing\@vobeyspaces
\NeutralizeInstancesOfUnstarredEndMacrocode\SkipMacrocodeEndings
\xmacro@code
}%
\makeatother

\usepackage{dox}%
\usepackage{fontspec}%
\usepackage{xcolor}%
\usepackage{hypdoc}%
\hypersetup{linkcolor=DarkGreen,citecolor=DarkRed,
urlcolor=Blue,colorlinks=true}
\usepackage{hyperref}%
\hypersetup{linkcolor=DarkGreen,citecolor=DarkRed,
urlcolor=Blue,colorlinks=true}
\hypersetup{pdfauthor={Peter Flynn},
pdftitle={The test LaTeX2e document package},
pdfsubject={Testing123},
pdfkeywords={latex,typesetting},
pdfproducer={XeLateX with hyperref},
pdfcreator={Emacs with psgml, ClassPack with Saxon, LaTeX from TeX Live}}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}\raggedright
\DocInput{test.dtx}
\end{document}
%</driver>
% \fi
% % \CheckSum{8}
% % \CharacterTable
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
% Digits \0\1\2\3\4\5\6\7\8\9
% Exclamation \! Double quote \" Hash (number) \#
% Dollar \$ Percent \% Ampersand \&
% Acute accent \' Left paren \( Right paren \)
% Asterisk \* Plus \+ Comma \,
% Minus \- Point \. Solidus \/
% Colon \: Semicolon \; Less than \<
% Equals \= Greater than \> Question mark \?
% Commercial at \@ Left bracket \[ Backslash \\
% Right bracket \] Circumflex \^ Underscore \_
% Grave accent \` Left brace \{ Vertical bar \|
% Right brace \} Tilde \~}
% % \GetFileInfo{test.dtx}
% \def\fileversion{1.26}
% \def\filedate{2023/12/30}
% \title{The \textsf{test} \LaTeXe\ package\thanks{%
% This document corresponds to \textsf{test}
% \textit{v.}\ \fileversion , dated \filedate.}
% \\[1em]\Large
% Testing dox/doc
% \\[1ex]\large
% on XSLT generating DTX}
% \author{Peter Flynn}
% \maketitle
% \renewcommand{\abstractname}{Summary}\thispagestyle{empty}
% \begin{abstract}
% Test
% \end{abstract}
% \clearpage
% \tableofcontents
% \clearpage
% \section{Test}
% Test
% \clearpage
% \StopEventually{\label{endcode}%
% \clearpage
% \addcontentsline{toc}{section}{Change History}%
% \label{changehistory}%
% \PrintChanges
% \clearpage
% \label{codeindex}%
% \addcontentsline{toc}{section}{Index}%
% \PrintIndex}
% \iffalse
%<*package>
% \fi
% \clearpage
% \section{The \textsf{test} macros}
% \iffalse
%</package>
% \fi
% \iffalse
%<*testscript>
% \fi
% \clearpage
% \section{The \emph{test.xsl} script}
% \setcounter{CodelineNo}{0}
% Now look: this normal usage works fine
% Identify the file origin, date, time, etc.\par
% \begin{macrocode}
<!-- The test.xsl script 24-02-04T21:01:06 -->
% \end{macrocode}
% Here we show the XSLT to handle a DocBook <sect1>
% IMPORTANT: it is supposed to generate the DTX code as-is
% between <xsl:text> and </xsl:text>
% \begingroup ^^A-----------------------------------------------
% \def\SkipMacrocodeEndings{1}%
% \begin{macrocode}
<xsl:template match="db:sect1">
<!-- process sect1 content -->
<xsl:apply-templates/>
<xsl:if test="@xml:id='options'">
<xsl:text>% Now invoke the options.\par
% \iffalse
%% Now invoke the options.
% \fi
% \begin{macrocode}
\ExecuteOptions{</xsl:text>
<xsl:value-of
select="descendant::db:annotation/@xreflabel"/>
<xsl:text>}
\ProcessOptions\relax
% \end{macrocode}&#xa;</xsl:text>
</xsl:if>
<xsl:call-template name="checkpackages">
<xsl:with-param name="pos" select="'after'"/>
<xsl:with-param name="loc" select="."/>
</xsl:call-template>
</xsl:if>
</xsl:template>
% \end{macrocode}
% \endgroup ^^A-------------------------------------------------
% That's all, folks!
% \iffalse
%</db2dtxscript>
% \fi
% \Finale

Re: Recognising \end{macrocode}

<l38p2pFg1e3U1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=8154&group=comp.text.tex#8154

  copy link   Newsgroups: comp.text.tex
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: peter@silmaril.ie (Peter Flynn)
Newsgroups: comp.text.tex
Subject: Re: Recognising \end{macrocode}
Date: Fri, 16 Feb 2024 09:43:53 +0000
Lines: 24
Message-ID: <l38p2pFg1e3U1@mid.individual.net>
References: <l2amvdF3d5aU1@mid.individual.net> <upr7cr$1cpmm$1@solani.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net qI460c7mPx1zds/PvghsjQHYDCKt16pabHtQmnO/uA59SoEciK
Cancel-Lock: sha1:ww2XB8ZCXUzGvuYM67fgv/h4hlM= sha256:fKhPpJDSzepgAuBdDhI1gwynvNrOJO0eutWkbCX72nA=
User-Agent: Mozilla Thunderbird
Content-Language: en-GB
In-Reply-To: <upr7cr$1cpmm$1@solani.org>
 by: Peter Flynn - Fri, 16 Feb 2024 09:43 UTC

On 05/02/2024 17:55, Ulrich D i e z wrote:
> Peter Flynn wrote:
[...]
>> Is there a way to configure doc/dox to recognise the end of the environment only when the '%    \end{macrocode}' occurs at the beginning of a line?
>
> I don't know dox.
>
> As far as I know, the package doc does not provide facilities for
> configuring such behavior.
>
> How about patching the environments macrocode and macrocode* of the
> package doc so that you can specify the amount of ending-phrases of
> these environments that should be ignored when scanning for the end
> of an instance of such an environment.

Thank you for the code, very useful and interesting. In fact there is
another solution, and that's to change the XSLT code so that it outputs
percent and four spaces in one xsl:text, and '{macrocode}' in another.
The result is the same, but it means there is no chance of the code
being misinterpreted.

Peter
"When in doubt, change the data"

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor