package doc v3: interaction with package hypdoc
Brief outline of the bug
Using \RenewDocElement{Macro}{macro} and/or \RenewDocElement{Env}{environment} together with package hypdoc creates unexpected behavior due to the conflict resolution applied by package doc. In particular, when using \RenewDocElement some backup macro definitions are not updated and so after loading package hypdoc via hook begindocument/before are restored to an outdated state afterwards.
This bug mainly concerns package doc but with https://github.com/latex3/latex2e/blob/842eb92c8fd7015c9b8396cd00455ebd3a52a3fe/base/ltxdoc.dtx#L645
class ltxdoc is blamable as well.
Edit:
The file was named test.tex, index creation would be: makeindex -s gind.ist -t test.ilg -o test.ind test.idx
Edit2:
\SpecialShortIndex is flawed too as within \str_case_e:nnF the assignments to \reserved@a would have to be csnames like space, bgroup, egroup or really string sequences escaped with \quotechar as this is used as sort key for the index command. Not sure how to deal \verbatimchar and the default case. Let me know, if I should open a separate issue.
Minimal example showing the bug
\listfiles
\RequirePackage{latexbug}
\begin{filecontents*}{doc-bugreport.dtx}
% Package \pkg{doc} tries to revert some changes applied by \pkg{hypdoc} if
% loaded. As far as I can see, this is currently flawed. I will try to give a
% brief summary from what I found.
%
% \subsubsection*{Descriptions}
% \DescribeMacro{\foo}
% The expected output is {\MacroFont|\foo|\textnormal{\space(somefoo)}}
%
% \medskip\noindent
% \DescribeEnv{bar}
% The expected output is {\MacroFont|bar|\textnormal{\space(\textit{somebar})}}
%
% Actually, |\PrintDescribeEnv| and |\PrintEnvName| are not changed
% by \pkg{hypdoc}.
%
% \bigskip\noindent
% \begin{macro}{\foo}
% The expected output is {\MacroFont|\foo|\textnormal{\space(somefoo)}}.
% \begin{macrocode}
\newcommand*\foo{def}
\begin{bar}
\end{bar}
% \end{macrocode}
% Changes to |\PrintMacroName| are not reflected in any case as it is redefined
% by \cls{ltxdoc} to
% \begin{verbatim}
% \renewcommand\PrintMacroName[1]{\MacroFont\detokenize{#1}}
% \end{verbatim}
% and does not use a scope for the font. Using |\PrintMacroName{\foo}|
% results in: {\PrintMacroName{\foo}--Look at me, I am out of scope!}
%
% Is there any reason for the re-definition? Could package \pkg{doc} take care
% of it, if necessary? Reverting back to the original definition of \pkg{doc}
% \begin{verbatim}
% \expandafter\let\expandafter\PrintMacroName\csname @@PrintMacroName\endcsname
% \end{verbatim}
% \expandafter\let\expandafter\PrintMacroName\csname @@PrintMacroName\endcsname
% {\PrintMacroName{\foo}--Look at me, still buggy} as |\@@PrintMacroName| does
% not hold the correct definition.
% \end{macro}
% \begin{environment}{bar}
% The expected output is {\MacroFont|bar|\textnormal{\space(\textit{somebar})}}
% \begin{macrocode}
\newenvironment{bar}{}{}
\foo
% \end{macrocode}
% \end{environment}
%
% \subsubsection*{Index}
% |\SortIndex| is reset and therefore |\SortIndex{!XXX}{XXX}| creates an index
% entry without a page link.\SortIndex{@XXX}{XXX}
%
% I am assuming, using |\SpecialMacroIndex| respectively |\SpecialUsageIndex|
% and |\SpecialEnvIndex| should create always an index entry refering a page
% and not a code line despite |\CodelineIndex| was used.
%
% Concerning macros, as |\SpecialMacroIndex| is not changed by \pkg{hypdoc} and
% |\SpecialUsageIndex| is reset, this part looks good. |\SpecialMainIndex| and
% |\SpecialMainMacroIndex| are not affected, so nothing to change for those.^^A
% \SpecialMainMacroIndex{\specialfoo}\SpecialMacroIndex{\specialfoo}
%
% Regarding environmenst, |\@@SpecialEnvIndex| would have to be updated as
% well, when |\RenewDocElement{Env}{environment}| was invoked. On the contrary,
% |\SpecialMainEnvIndex| is not in question, nothing to do for the latter.^^A
% \SpecialMainEnvIndex{specialbar}\SpecialEnvIndex{specialbar}
%
% \subsubsection*{Proposal}
% \begin{itemize}
% \item Get rid of restoring via |\@@DescribeMacro| as well as |\@@DescribeEnv|,
% |\@@PrintDescribeEnv| and |\@@PrintEnvName| as all macros are not touched
% by \pkg{hypdoc}.
% \item |\@@SpecialUsageIndex| should remain, |\@@SortIndex| can be removed too.
% \item Handle special cases for |\PrintDescribeMacro|, |\PrintMacroName| and
% |\SpecialEnvIndex|
% \end{itemize}
% Alternativly to handling specific cases, a generic solution would be to store
% |@@PrintDescribe#2|, |@@Print#2Name| and |@@Special#2Index| at the end of
% |\@NewDocElement|
\end{filecontents*}
%\PassOptionsToPackage{hyperref=false}{doc}
\documentclass{ltxdoc}
\DoNotIndex{\begin,\end,\newcommand,\newenvironment}
\RenewDocElement[
macrolike = true ,
idxtype = foo,
idxgroup = foos,
printtype = somefoo
]{Macro}{macro}
\RenewDocElement[
macrolike = false ,
idxtype = bar ,
idxgroup = bars ,
printtype = \textit{somebar}
]{Env}{environment}
% proposed changes
\makeatletter
%\let\@@PrintDescribeMacro\PrintDescribeMacro
%\let\@@PrintMacroName\PrintMacroName
%\let\@@SpecialEnvIndex\SpecialEnvIndex
\makeatother
\CodelineIndex
\RecordChanges
\EnableCrossrefs
%\let\TempPrintMacroName\PrintMacroName
\begin{document}
%\let\PrintMacroName\TempPrintMacroName
\DocInclude{doc-bugreport}
\PrintIndex
\PrintChanges
\end{document}
Log file (required) and possibly PDF file
This issue has been automatically marked as stale because it has not had recent activity.
This issue has been automatically marked as stale because it has not had recent activity.
Likely the best plan is to merge hypdoc into doc v3: we will need to watch for explicit use of v2 and probably have a frozen version of hypdoc to support that.
This issue has been automatically marked as stale because it has not had recent activity.
This issue has been automatically marked as stale because it has not had recent activity.
This issue has been automatically marked as stale because it has not had recent activity.
This issue has been automatically marked as stale because it has not had recent activity.