1

Need help in customising class ltxdoc. I would like to colour code macrocode environments so as to facilitate the visual distinction between package's macro code and it associated documentation.

I tried to create a new environment:

\newenvironment{sourcecode}%
{\color{blue}\begin{macrocode}}%
{\end{macrocode}}

That failed with a capacity size exceeded (set for the occasion to 100000).

I had a look at ltxdoc.dtx to see if I could simply import the macrocode environment. But its implementation is too cryptic for me.

Thanks for any insight here :-)

2

You can use the environment hooks from the package etoolbox in the first part of the .dtx.

MWE:

% \iffalse
%<*driver>
\documentclass{ltxdoc}
\usepackage{xcolor}
\usepackage{etoolbox}
\AtBeginEnvironment{macrocode}{\color{blue}}
\begin{document}
\DocInput{dtxcolor.dtx}
\end{document}
%</driver>
% \fi
% \StopEventually{}
%
%This is a description of the code below.
%    \begin{macrocode}
  \mathchardef\implies="3221 \mathchardef\impliedby="3220 \mathchardef\Implies=%
"3229 \mathchardef\Impliedby="3228 \mathchardef\implic="2221 \mathchardef
\implicby="2220 \mathchardef\Implic="2229 \mathchardef\Implicby="2228 \let
\imp\to%%
%    \end{macrocode}
% \Finale
\endinput

Result (with latex dtxcolor.dtx):

enter image description here

  • When the macrocode environment is immediately preceded by with a \DescribeMacro{mymacro}, the mymacro in the margin gets coloured too. Adding some documentation text between \DescribeMacro{mymacro} and \begin{macrocode} resolves the colour issue. – JM. Marcastel Dec 6 '17 at 13:48
  • @JM.Marcastel you might be able to patch DescribeMacro as well (with pretocmd etc.), for example put \color{black} in front and \color{blue} at the end. – Marijn Dec 6 '17 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.