[also posted recently to tex.s.e]
tl;dr
I am having trouble getting redefined macros from dox.sty to be obeyed.
They are redefined in my Preamble, but they fail to override the ones
from dox.sty and I'm not clear why. MWE below.
Peter
Full post
---------
After successful tests getting protruding (outdented) escape characters
to work, see
https://tex.stackexchange.com/questions/742244/index-entries-with-outdented-escape-characters
(thank you, contributors). The technique I chose was to define a macro
which gobbled the markup escape character and `\llap`'d it, eg
\newcommand{\myescape}{\leavevmode\expandafter\llap\string}
so I can write `\verb+@begin+\index{begin={\ttfamily\myescape @begin}}`
which does the job.
I now need to apply this to the automated index entries generated by the
`dox` package, which extends `doc` by providing user-defined object
names and groups for use in DocTeX (`ltxdoc`) package documentation.
If I define a new group for a specific set of my own commands (which use
TeX syntax), I can write
\doxitem[idxtype=command,macrolike]{Command}{mycommand}{commands}
This creates a `mycommand` environment and a custom `\DescribeCommand`
macro where I can document each command I create:
\begin{mycommand}{foo}
This is the
\DescribeCommand{\foo}\verb+\foo+
command from the \textsf{foobar} package.
\end{mycommand}
The `\DescribeCommand` macro prints the name in the margin for
reference, and automatically makes a pair of index entries like this
(one for the entry itself, and one for all the entries in that group):
\indexentry{foo=\verb!*+\foo+ (command)|usage}{1} \indexentry{commands:>foo=\verb!*+\foo+|usage}{1}
I want to have these appear in the index with the backslash protruding
out of the left-hand edge of the index column (in the style of the
TeXbook) so that the first letter of the indexed entry is aligned with
all the other index entries.
I have located the code source of the index entries at the macros `\@doxcreatespecialmainmacrolikeindex` and
`@doxcreatespecialmacrolikeindex` in dox.sty so in theory I should be
able to copy these and modify them in my own code but when I do this
(below) I get no error, but after processing, the `.idx` file contains
exactly the same as the previous (`dox.sty`'s own ) definition: in other
words, my redefinition is ignored. A `\typeout` command in my
redefinitions confirms that the redefined macros are not actually being executed.
I've clearly misunderstood something about how dox.sty does its
business, but I cannot find any other file on disk containing a
definition of `\@doxcreatespecialmainmacrolikeindex`, so I am unable to
see why a new definition is not replacing the old one. (I did try
placing my redefinition inside `\AtBeginDocument` but that had no effect).
MWE test.tex (requires `makeindex -s gind.ist -o test.ind test.idx`) ---------------------------------8<--------------------------------- \documentclass[11pt,doc2]{ltxdoc}
\usepackage{doc,dox,makeidx}
\usepackage[columns=1]{idxlayout}
\makeindex
% Create a new "command" object, behaving like a TeX macro \doxitem[idxtype=command,macrolike]{Command}{mycommand}{commands}
% Create a macro to gobble an escape character and reproduce it
% so that it will hang into the LH margin \newcommand{\myescape}{\leavevmode\expandafter\llap\string}
% Redefine the macros from dox.sty which generate the index
% entries for the 'macrolike' object groups
\makeatletter
\def\@doxcreatespecialmainmacrolikeindex#1#2#3{%
\typeout{defining my special main #1 index}%
\expandafter\def\csname SpecialMain#1Index\endcsname##1{% \@SpecialIndexHelper@##1\@nil
\@bsphack% \special@index{\@gtempa\actualchar{\ttfamily\myescape\bslash\@gtempa}% \space(#2)\encapchar main}% \special@index{#3:\levelchar\@gtempa\actualchar{\ttfamily\myescape\bslash\@gtempa}%
\encapchar main}%
\@esphack}}%
\def\@doxcreatespecialmacrolikeindex#1#2#3{%
\typeout{defining my special #1 index}%
\expandafter\def\csname Special#1Index\endcsname##1{% \@SpecialIndexHelper@##1\@nil
\@bsphack%
\index{\@gtempa\actualchar{\ttfamily\myescape\bslash\@gtempa}% \space(#2)\encapchar usage}% \index{#3:\levelchar\@gtempa\actualchar{\ttfamily\myescape\bslash\@gtempa}% \encapchar usage}%
\@esphack}}%
\makeatother
\begin{document}
\begin{mycommand}{foo}
This is the
\DescribeCommand{\foo}\verb+\foo+
command from the \textsf{foobar} package.
\end{mycommand}
Normal index entries for alignment test:
flynn\index{flynn} and funnel\index{funnel}
and one with the outdented escape character done manually \verb+@fred+\index{fred={\ttfamily\myescape @fred}}.
\printindex
\end{document} ---------------------------------8<---------------------------------
Can anyone suggest where I have gone wrong?
Peter
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)