lvjr / codehigh

Highlight codes and demos with l3regex and lpeg
https://ctan.org/pkg/codehigh
11 stars 6 forks source link

How to use codehigh in .dtx file? #10

Closed note286 closed 1 year ago

note286 commented 1 year ago

This is test.dtx file.

% \iffalse
%<*driver>
\ProvidesFile{test.dtx}
%</driver>
%<class>\NeedsTeXFormat{LaTeX2e}
%<class>\ProvidesClass{test}[2022/11/22 v1.0.0 Test]
%<*driver>
\documentclass{l3doc}
\usepackage{codehigh}
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
% This is document.
% \begin{codehigh}
% \documentclass{test}
% \begin{document}
% Test
% \end{document}
% \end{codehigh}
% This is document.
% \section{Implementation}
%    \begin{macrocode}
%<*class>
\LoadClass{ctexart}
%</class>
%    \end{macrocode}
% \Finale
\endinput

This is test.ins file.

\input docstrip
\askforoverwritefalse
\preamble
\endpreamble
\postamble
\endpostamble
\keepsilent
\generate{\file{\jobname.cls}{\from{\jobname.dtx}{class}}}
\nopreamble
\nopostamble
\endbatchfile

With pdflatex test.dtx and pdflatex test.ins, we get test.cls as below:

%%
%% This is file `test.cls',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% test.dtx  (with options: `class')
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{test}[2022/11/22 v1.0.0 Test]
\LoadClass{ctexart}
%% 
%%
%% End of file `test.cls'.

and test.pdf as below: image

I don't know why codehigh recognizes the %. According to my understanding, \DocInput swallows the %. So what is the cause of this situation?

lvjr commented 1 year ago

It seems % characters are still there when codehigh environment is executed. But I know little about docstrip, so I am not sure it is a bug of docstrip or codehigh. Hope @FrankMittelbach has a little time to see this issue?

note286 commented 1 year ago

I tested listings package, and I found the same problem, but listings package has a parameter gobble that can be set, namely \lstset{gobble=2}.

% \iffalse
%<*driver>
\ProvidesFile{test.dtx}
%</driver>
%<class>\NeedsTeXFormat{LaTeX2e}
%<class>\ProvidesClass{test}[2022/11/22 v1.0.0 Test]
%<*driver>
\documentclass{l3doc}
\usepackage{ninecolors}
\usepackage{listings}
\lstset{
gobble          = 2,
language        = [LaTeX]TeX,
basicstyle      = \small\ttfamily,
backgroundcolor = \color{azure9!25},
keywordstyle    = \color{red6}
}
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
% This is document.
% \begin{lstlisting}
% \documentclass{test}
% \begin{document}
% Test
% \end{document}
% \end{lstlisting}
% This is document.
% \section{Implementation}
%    \begin{macrocode}
%<*class>
\LoadClass{ctexart}
%</class>
%    \end{macrocode}
% \Finale
\endinput

image

If don't set \lstset{gobble=2}, it will be image

Can codehigh package provide interface like gobble? The default configuration provided by codehigh package is really beautiful, and I like it very much. It would be appreciated if the author could add this interface.

FrankMittelbach commented 1 year ago

@lvjr time? not really :-) .. see https://tex.stackexchange.com/a/612586/10109 (there are still the odds and ends, sigh). But in general here is the issue:

lvjr commented 1 year ago

@FrankMittelbach Thank you very much for the explanation!

@note286 It is a good idea to add gobble option in codehigh package. I have no time to update this package recently. But if you would like to help you could make a pull request, then I will upload a new release to CTAN.

note286 commented 1 year ago

I'll give it a try, but my level is limited, and there is a high probability that I can't realize this gobble in codehigh. Finally, thank you again for your answers.

FrankMittelbach commented 1 year ago

beside that you may want (perhaps) something like \AddToHook{package/doc/after}{ arrange for "gobble=2" as default } in the package