Debian Codegraph @

texmf-dist/doc/latex/checklistings/checklistings.hva

raw
1 %% HeVeA support for checklistings.
2 %%
3 %% Limitations / caveats
4 %%
5 %% * checklistings.hva requires all the intermediate generated by latex and
6 %% checklistings.sh (*.<ext>, *.tex, *.msg, *.err).
7 %%
8 %% * The options 'codestyle', 'msgstyle', 'errstyle', 'codelst', 'msglst',
9 %% and 'errlst' cannot be set as in LaTeX, e.g.,
10 %% \checklistings{codelst={language=caml}}
11 %% Since HeVeA eliminates the grouping braces and passes 'language' to
12 %% the handler for 'codelst' (rather than 'language=caml').
13 %%
14 %% One workaround is to \usepackage{hevea} and use \ifhevea to select
15 %% the most appropriate of the two forms.
16 %%
17 %% * fancyvrb and the package options codestyle, msgstyle, and errstyle are
18 %% not supported.
19 %% Alternative 1: use the codelst, msglst, and errlst options.
20 %% Alternative 2: use css for formatting code, messages, and errors.
21 %%
22 %% * Non-empty labels in the arguments of \chklistingmsg and
23 %% \chklistingerr are not supported.
24 %%
25 \ProvidesPackage{checklistings}
26 \RequirePackage{keyval}
27 \RequirePackage{listings}
28
29 \newcounter{chklisting}
30 \setcounter{chklisting}{-1}
31
32 \newif\ifCHKL@fileexists
33 \newif\ifCHKL@showcode\CHKL@showcodetrue
34 \newif\ifCHKL@shouldfail\CHKL@shouldfailfalse
35 \newif\ifCHKL@withresult\CHKL@withresultfalse
36 \newif\ifCHKL@showerrors\CHKL@showerrorstrue
37 \newif\ifCHKL@loadhtml\CHKL@loadhtmlfalse
38 \def\CHKL@pkg@skipopts{}
39
40 % % % Declare Options % % %
41
42 \DeclareOption{withresult}{\CHKL@withresulttrue}
43 \DeclareOption{withoutresult}{\CHKL@withresultfalse}
44 \DeclareOption{skipone}{\def\CHKL@pkg@skipopts{firstline=2}}
45 \DeclareOption{skiptwo}{\def\CHKL@pkg@skipopts{firstline=3}}
46 \DeclareOption{showproblems}{\CHKL@showproblemstrue}
47 \DeclareOption{hideproblems}{\CHKL@showproblemsfalse}
48
49 \def\CHKL@codestyle{}
50 \def\CHKL@msgstyle{}
51 \def\CHKL@errstyle{}
52 \define@key{CHKL@pkgkeys}{codestyle}[]{\def\CHKL@codestyle{#1}}
53 \define@key{CHKL@pkgkeys}{msgstyle}[]{\def\CHKL@msgstyle{#1}}
54 \define@key{CHKL@pkgkeys}{errstyle}[]{\def\CHKL@errstyle{#1}}
55
56 \def\CHKL@codelst{}
57 \def\CHKL@msglst{}
58 \def\CHKL@errlst{}
59 \define@key{CHKL@pkgkeys}{codelst}[]{\def\CHKL@codelst{#1}}
60 \define@key{CHKL@pkgkeys}{msglst}[]{\def\CHKL@msglst{#1}}
61 \define@key{CHKL@pkgkeys}{errlst}[]{\def\CHKL@errlst{#1}}
62
63 \def\CHKL@subdir{.}
64 \def\CHKL@prefix{chklisting}
65 \def\CHKL@prompt{\#}
66 \def\CHKL@ext{.ml}
67 \define@key{CHKL@pkgkeys}{prompt}[]{\def\CHKL@prompt{#1}}
68 \define@key{CHKL@pkgkeys}{subdir}[]{\def\CHKL@subdir{#1}}
69 \define@key{CHKL@pkgkeys}{prefix}[]{\def\CHKL@prefix{#1}}
70 \define@key{CHKL@pkgkeys}{ext}[]{\def\CHKL@ext{#1}}
71 \define@key{CHKL@pkgkeys}{html}[]{\CHKL@loadhtmltrue}
72
73 % Unused options
74 \define@key{CHKL@pkgkeys}{compiler}[]{}
75 \define@key{CHKL@pkgkeys}{compilerflags}[]{}
76 \define@key{CHKL@pkgkeys}{lastflags}[]{}
77 \define@key{CHKL@pkgkeys}{includecmd}[]{}
78
79 % % % Process Options % % %
80
81 % Work around the lack of \DeclareOption* in package.hva
82 \renewcommand{\@process@option}[1]%
83 {\def\pkg@opt{{\@nostyle\@callprim{\@eatspaces}{#1,}}}%
84 \ifu\csname\@pkg@opt@name{\pkg@opt}\endcsname
85 \setkeys{CHKL@pkgkeys}{#1}
86 \else
87 \csname\@pkg@opt@name{\pkg@opt}\endcsname\fi}%
88
89 \ProcessOptions*
90 \newcommand{\checklistings}[1]{\ExecuteOptions{#1}}
91
92 % % % Macros used in files generated by checklistings.sh % % %
93
94 \newif\ifchklisting
95 \newcommand{\setchklistingcmd}[1]{%
96 \global\def\chklistingcmd{\emph{\CHKL@prompt{#1}}}}
97
98 \newenvironment{ChkListingMsg}{\verblatex}{\endverblatex}
99 \newenvironment{ChkListingErr}{\verblatex}{\endverblatex}
100
101 \newcommand{\chklistingfile}{\CHKL@prefix\CHKL@ext}
102
103 % % % Checklistings user macros % % %
104
105 \define@key{CHKL@envkeys}{continue}[]{}
106 \define@key{CHKL@envkeys}{include}[]{}
107 \define@key{CHKL@envkeys}{label}[]{}
108 \define@key{CHKL@envkeys}{showproblems}[]{\CHKL@showproblemstrue}
109 \define@key{CHKL@envkeys}{hideproblems}[]{\CHKL@showproblemsfalse}
110 \define@key{CHKL@envkeys}{skipnone}[]{\def\CHKL@pkg@skipopts{firstline=1}}
111 \define@key{CHKL@envkeys}{skipone}[]{\def\CHKL@pkg@skipopts{firstline=2}}
112 \define@key{CHKL@envkeys}{skiptwo}[]{\def\CHKL@pkg@skipopts{firstline=3}}
113 \define@key{CHKL@envkeys}{hide}[]{\CHKL@showcodefalse}
114 \define@key{CHKL@envkeys}{withresult}[]{\CHKL@withresulttrue}
115 \define@key{CHKL@envkeys}{withoutresult}[]{\CHKL@withresultfalse}
116 \define@key{CHKL@envkeys}{fail}[]{\CHKL@shouldfailtrue}
117
118 % Work around the lack of \edef and \expandafter
119 \def\CHKL@lstset#1{\lstset{#1}}
120 \def\elstset#1{\@callprim{\CHKL@lstset}{\{#1\}}}
121
122 \newcommand{\chklistingmsg}{\bgroup%
123 \setenvclass{lstlisting}{lstlisting chklistingmsg}%
124 \elstset{\CHKL@msgstyle}%
125 \elstset{\CHKL@msglst}%
126 \lstinputlisting{\CHKL@subdir/\CHKL@prefix\[email protected]}%
127 \egroup}%
128
129 \newcommand{\chklistingerr}{\bgroup%
130 \setenvclass{lstlisting}{lstlisting chklistingerr}%
131 \elstset{\CHKL@errstyle}%
132 \elstset{\CHKL@errlst}%
133 \lstinputlisting{\CHKL@subdir/\CHKL@prefix\[email protected]}%
134 \egroup}%
135
136 \newenvironment{chklisting}[1][]
137 {%
138 \setenvclass{lstlisting}{lstlisting chklisting}%
139 \stepcounter{chklisting}%
140 \def\@currentlabel{\thechklisting}%
141 \@setkeys{CHKL@envkeys}{#1}%
142 \global\def\CHKL@num{%
143 \ifthenelse{\value{chklisting}<1000}{0}{}%
144 \ifthenelse{\value{chklisting}<100}{0}{}%
145 \ifthenelse{\value{chklisting}<10}{0}{}%
146 \arabic{chklisting}}%
147 \global\def\CHKL@file{\CHKL@subdir/\CHKL@prefix\CHKL@num}%
148 \global\let\chklistingcmd\relax%
149 \ifCHKL@showcode%
150 \bgroup%
151 \ifCHKL@loadhtml%
152 \@open{div}{class="chklisting"}%
153 \rawinput{\CHKL@file{}.html}%
154 \@close{div}%
155 \else%
156 \elstset{\CHKL@pkg@skipopts}%
157 \elstset{\CHKL@codestyle}%
158 \elstset{\CHKL@codelst}%
159 \lstinputlisting{\CHKL@file\CHKL@ext}%
160 \fi%
161 \egroup%
162 \input{\[email protected]}%
163 \ifCHKL@shouldfail%
164 \ifchklisting%
165 \ifCHKL@showproblems%
166 \begin{divstyle}{checklistingserror}%
167 Unexpected success: \chklistingmsg{}
168 \end{divstyle}%
169 \fi%
170 \else%
171 \ifCHKL@withresult{\chklistingerr{}}\fi%
172 \fi%
173 \else
174 \ifchklisting%
175 \ifCHKL@withresult{\chklistingmsg{}}\fi%
176 \else%
177 \ifCHKL@showproblems%
178 \begin{divstyle}{checklistingserror}%
179 Unexpected failure: \chklistingerr{}
180 \end{divstyle}%
181 \fi%
182 \fi%
183 \fi
184 \fi%
185 \verblatex%
186 }
187 {\endverblatex}%
188 \endinput