Debian Codegraph @

texmf-dist/source/latex/nag/nag.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2005-10 by Ulrich M. Schwarz
4 %
5 % This file may be distributed and/or modified under the conditions of
6 % the LaTeX Project Public License, either version 1.3a or, at your
7 % option, any later version. The latest version of this license is in
8 %
9 % http://www.latex-project.org/lppl.txt
10 %
11 % \fi
12 %
13 %\iffalse
14 %<*driver>
15 \documentclass{ltxdoc}
16 \usepackage[l2tabu]{nag}
17 \GetFileInfo{nag.sty}
18 \typeout{\fileversion}
19 \usepackage[T1]{fontenc}
20 \usepackage{lmodern}
21 \usepackage[scaled]{luximono}
22 \EnableCrossrefs
23 \CodelineIndex
24 \RecordChanges
25 \begin{document}
26 \DocInput{nag.dtx}
27 \end{document}
28 %</driver>
29 %<*nagdemo>
30 %% Test document: finding and complaining about obsolete macros.
31 %%
32 \RequirePackage[l2tabu, orthodox, experimental]{nag}[2007/12/21]
33 \documentclass{article}
34 %% some usual culprits
35 \usepackage{times, a4wide, epsfig, palatino}
36 %% some fancy packages
37 \usepackage{subfig, topcapt, caption, hyperref}
38 \begin{document}
39 \typeout{Next: no complaint because frontmatter is not defined}
40 \ifx\frontmatter\undefined
41 \else
42 \typeout{FAILURE! I shouldn't know frontmatter!}
43 \fi
44 \typeout{Next: no complaing about label outside float not preceded by caption}
45 \section{Tests}\label{sec:tests}
46 \typeout{Next: it and bf complaints}
47 {\it italics {\bf not bold italics}}
48
49 \typeout{Next: not-an-env complaints}
50 \begin{Large}
51 \begin{sffamily}
52 Large and sans.
53 \end{sffamily}
54 \end{Large}
55
56 \typeout{Next: center in float complaint}
57 \begin{figure}
58 \begin{center}
59 Center in float.
60 \end{center}
61 \caption{\label{fig}Figs and dates.}
62 \end{figure}
63
64 \typeout{Next: no complaints: manually fake caption}
65 \begin{figure}
66 I have a caption, you just can't see it.
67 \makeatletter\nag@hascaptiontrue\makeatother
68 \label{date}
69 \end{figure}
70
71 \typeout{Next: no complaing about label outside float not preceded by caption}
72 \section{More Tests}\label{sec:tests2}
73
74 \typeout{Next: put-label-after-caption complaint}
75 \begin{figure}
76 \label{coconut}\caption{Preceded, not followed, by label.}
77 \end{figure}
78
79 \typeout{Next: no-caption complaint}
80 \begin{figure}
81 No caption, even a fake one.
82 But too big, this should get bottom-of-page warning.
83 \rule{1pt}{0.4\textheight}
84 \end{figure}
85
86 \typeout{Next: no complaint about subfloat and topcapt}
87 \typeout{also: complaint about it in caption.}
88 \begin{figure}
89 \subfloat{\label{sf:1}Subfig number~\ref{sf:1} with label.}
90 \subfloat[\label{sf:17}Strange subfig]{Subfig~\ref{sf:17} with label elsewhere.}
91 \caption{Figure: \it's a sin!}
92 \end{figure}
93
94 \begin{figure}
95 \topcaption{A topcaption.}
96 \subfloat{\label{sf:2}Subfig~\ref{sf:2} with label, but no caption.}
97 \end{figure}
98
99 \typeout{Next: no robustness issues}
100 \begin{minipage}{5cm}
101 foo\footnote{bar}
102 \end{minipage}
103
104 \typeout{Shouldn't cause trouble to have dollars in headings.}
105 \section{Maths tests, like if $1+1=2$}
106
107 \typeout{Next: three complaints in total concerning $$ and eqnarray}
108
109 A \TeX-style displayed equation:
110 $$ 1+1=2 $$
111
112 Not an equation at all:
113 $ $ 1+1=2 $ $
114
115 An in line equation:
116 $1+1=2$
117
118 Two inline equations, double dollar is dollar dollar in resticted
119 horizontal mode (onlyamsmath gets this wrong):
120 $a+b=c$$1+1=2$
121
122 An eqnarray:
123 \begin{eqnarray}
124 1+1 &=& 2
125 \end{eqnarray}
126
127 A bracket-style equation:
128 \[1+1=2\]
129
130 A starred eqnarray:
131 \begin{eqnarray*}
132 1+1 &=& 2
133 \end{eqnarray*}
134
135 A double-dollar in a hbox:
136 \hbox{$$}
137
138 \typeout{Next: appendix complaints}
139 \begin{appendix}
140 \begin{center}
141 It's a center environment.
142 \end{center}
143 \typeout{Next: no over complaint, centerline complaint, no frac complaint}
144 Over etc. warning removed for compatibility with \LaTeX\ without amsmath.
145
146 \centerline{Furthermore, $4\over 2=2$.}
147 $\frac 42$
148 \end{appendix}
149 \typeout{Next: unmatched endflushright}
150 This is not flushright, in spite of a endflushright coming up.
151 \endflushright
152 \typeout{Next: unclosed center}
153 {\center Smack in the middle, but center used as a switch\par}
154 \typeout{Next: mismatched endflushright}
155
156 Another endflushright, this is brace-mismatched and otherwise totally
157 unsuited for closing the center command above.
158 \endflushright
159
160 \typeout{Next: a warning that is not uppercased.}
161 \MakeUppercase{\it's a sin!}
162
163 \typeout{Next: another warning about it in a caption, in the LoF this time.}
164 \listoffigures
165 \AtEndDocument{\typeout{You should get 25 warnings and one info in the log.}}
166 \end{document}
167 %</nagdemo>
168 %
169 %\fi
170 %
171 % \CharacterTable
172 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
173 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
174 % Digits \0\1\2\3\4\5\6\7\8\9
175 % Exclamation \! Double quote \" Hash (number) \#
176 % Dollar \$ Percent \% Ampersand \&
177 % Acute accent \' Left paren \( Right paren \)
178 % Asterisk \* Plus \+ Comma \,
179 % Minus \- Point \. Solidus \/
180 % Colon \: Semicolon \; Less than \<
181 % Equals \= Greater than \> Question mark \?
182 % Commercial at \@ Left bracket \[ Backslash \\
183 % Right bracket \] Circumflex \^ Underscore \_
184 % Grave accent \` Left brace \{ Vertical bar \|
185 % Right brace \} Tilde \~}
186 %\CheckSum{624}
187 %
188 %\DoNotIndex{\if,\else,\fi,\PackageWarning,\PackageWarningNoLine,\typeout}
189 %\DoNotIndex{\@for,\addtocounter,\arabic,\centering,\csname,\CurrentOption}
190 %\DoNotIndex{\DeclareOption,\def,\do,\endcsname,\expandafter,\ifnum,\ifx}
191 %\DoNotIndex{\InputIfFileExists,\let,\lq,\rq,\MessageBreak,\protect}
192 %\DoNotIndex{\space,\stepcounter,\the,\value,\relax,\ProcessOptions}
193 %\DoNotIndex{\ifcsname,\@ifundefined,\flo,\begingroup,\endgroup}
194 %\DoNotIndex{\or,\vbox,\vskip,\z@,\wd,\vtop,\tmp@a,\tmp@b,\tw@}
195 %\DoNotIndex{\@nil,\@nx,\@ne,\@tempcnta,\@tempcntb,\@tempdima,\@tempskipb}
196 %\DoNotIndex{\foo,\endfoo,\ht,\dp,\wd,\hrule,\ifcase,\ifdim}
197 %
198 %\changes{0.1}{2005/03/29}{First official version.}
199 %\changes{0.2}{2005/05/08}{Rephrased umlaut.sty warning, suggested by
200 %Patrick Happel.}
201 %\changes{0.2}{2005/05/08}{Added abort.nag, suggested by Michael Zedler}
202 %\changes{0.3}{2005/07/07}{New ifdefined that won't relax the commands}
203 %\changes{0.4}{2006/04/19}{Handling command vs. environment; bugfixes}
204 % \changes{0.5}{2006/07/08}{Handle the case that somebody else relaxes
205 % the ver@-commands. Stack-based NotASwitch.}
206 %\changes{0.55}{2007/03/31}{Some spaces crept in in 0.5}
207 %\changes{0.60alpha}{2007/04/03}{ changes the way label/caption is handled,
208 % this eliminates the current limit of some thousand floats you can have in
209 % your document. (I wonder why nobody noticed). }
210 %\changes{0.60alpha2}{2007/04/08}{ is more careful around commands that
211 % aren't there. }
212 %\changes{0.60alpha4}{2007/04/23}{ handles eqnarray itself and has code in
213 % nag-experimental.cfg to handle double-dollar in a more robust way that
214 % onlyamsmath.}
215 %\changes{0.60alpha4}{2007/04/23}{ tarballs now unpack into a subdirectory
216 % like proper citizens should.}
217 %\changes{0.60alpha5}{2007/05/10}{ improves compatibility with subfig.}
218 %\changes{0.60}{2007/05/10}{ fixes double-dollar in conjunction with
219 % hyperref; documents incompatiblity with rotating.}
220 %\changes{0.61alpha1}{2007/11/10}{ fixes warnings in toc/lof/lot and
221 % unsightly uppercasing. }
222 %\changes{0.61alpha2}{2007/11/26}{ fixes the warnings, without generating
223 % too many duplicates.}
224 %\changes{0.61alpha3}{2007/12/21}{ warns about inputs that fail (in
225 % particular includes that fail) and notes if a float has position t/b but is
226 % too large to ever go into such a position (log only). }
227 %\changes{0.61alpha4}{2008/01/04}{ exempts the complaints counter from
228 % include trickery. (Previously, nag would get confused if you includeonly
229 % only some chapters.) }
230 %\changes{0.61alpha5}{2008/01/27}{ introduces compatibility hacks with
231 % version control packages which rely on dollar having constant catcode.
232 % (Workaround for svninfo and rcs, all other packages now disable
233 % double-dollar
234 % checking.) }
235 %\changes{0.61}{2008/02/10}{ is 0.61alpha5 with some typos in the docs
236 % fixed.}
237 %\changes{0.62}{2007/07/30}{ fixes a bug in the float placement code and
238 % adds more compatibility with the caption package.}
239 %\changes{0.621}{2010/04/05}{Bugfix concerning unknown command in math mode}
240 %\changes{0.622}{2010/05/17}{Bugfix: math in captions catcode issue}
241 %\changes{0.623}{2010/08/15}{Tracing code in experimental: nofiles}
242 %\changes{0.623}{2010/08/15}{Tracing code in experimental: changing labels}
243 %\changes{0.623}{2010/08/15}{New error message: no room for a ... and eTeX}
244 %\changes{0.7}{2011/11/25}{IncompatiblePackages,RecommendPackage,BadFileLoadOrder}
245 %
246 %\GetFileInfo{nag.sty}
247 %\newcommand\pkg[1]{\textsf{#1}}
248 %\title{The \pkg{nag} package\ignorespaces%
249 % \thanks{This document corresponds to \pkg{nag}~\fileversion,
250 % dated~\filedate. Other versions can be found at http://absatzen.de/}}
251 % \author{Dr. Ulrich Michael Schwarz\ignorespaces%
252 % \thanks{\texttt{[email protected]}}}
253 %
254 % \maketitle
255 %
256 % \begin{abstract}
257 % Old habits die hard. All the same, there are commands, classes and
258 % packages which are outdated and superseded. \pkg{nag} provides
259 % routines to warn the user about the use of those. As an example, we
260 % provide an extension that detects many of the ``sins'' described in
261 % \pkg{l2tabu}.
262 % \end{abstract}
263 %
264 % \tableofcontents
265 %
266 % \section{User-side considerations.}
267 %
268 % \subsection{Installation.}
269 %
270 % Process \texttt{nag.ins} with \LaTeX\ to obtain some files:
271 % \texttt{nag.sty} and \texttt{nag-l2tabu.cfg} et al. must go to a place where
272 % \LaTeX\ will find them, like the local TEXMF tree. (If all else fails and
273 % you need it to work \emph{right now}, having them in the same
274 % directory as the \LaTeX\ file you want to use them on may work under
275 % many circumstances.) You can, as usual, run \LaTeX\ on
276 % \texttt{nag.dtx} to obtain this documentation, including the
277 % implemenation docs. (This is recommended if you plan to extend
278 % \pkg{nag} to handle your own packages.) \texttt{nagdemo.tex} is
279 % a horrible document that will show you many of the warnings that
280 % \pkg{nag} can generate.
281 %
282 % \subsection{Usage.}
283 %
284 % Add the following to the beginning your main document (Comments and
285 % |\listfiles| can be safely left before it, though):
286 % \begin{verbatim}
287 % \RequirePackage[l2tabu, orthodox]{nag}\end{verbatim}
288 % This will check for many common mistakes, and give some hints on what
289 % to use instead. However, you should always refer to l2tabu for a more
290 % detailed explanation of the whats and whys: it gives more information
291 % than can be possibly pressed into two lines of error message.
292 % Orthodox checks for pitfalls that are not technically incorrect. If
293 % you know what you're doing, omit orthodox.
294 %
295 % \subsection{Known bugs}
296 % currently none.
297 %
298 % \subsection{\texttt{nag-l2tabu.cfg}}
299 %
300 % In a nutshell, \texttt{nag-l2tabu.cfg} detects the following:
301 % \begin{itemize}
302 % \item Usage of the 2.09-style font commands |\it|, |\bf|, |\rm|,
303 % |\sc|, |\sl|, |\tt| and |\cal|.
304 % \item Usage of |\centerline|.
305 % \item Usage of the outdated packages \pkg{epsfig}, \pkg{psfig},
306 % \pkg{epsf}, \pkg{doublespace}, \pkg{fancyheadings}, \pkg{scrpage},
307 % \pkg{umlaut}, \pkg{isolatin}, \pkg{isolatin1}, \pkg{t1enc},
308 % \pkg{caption2}, \pkg{psfonts}, \pkg{mathptm}, \pkg{times},
309 % \pkg{palatino}, \pkg{mathpple}, \pkg{euler} and \pkg{utopia}, and of
310 % the outdated class \pkg{scrlttr}.
311 % \item Figures and tables without caption (this is not technically
312 % in l2tabu, but the people who have floats without captions tend
313 % to ask ``Why is \LaTeX\ moving my pictures away from where I
314 % put them?''), labels within floats
315 % that do not reference the caption, and usage of the center
316 % environment within floats.
317 %\end{itemize}
318 %
319 % It is beyond the possibilities of this package to detect things like
320 % use of \TeX\ assignment syntax, or direct change of paper
321 % parameters, or reliable detection of user-issued |\sloppy|.
322 % eqnarray is handled as of 0.60alpha4, and there is code for \$\$ in
323 % experimental since 0.60alpha4, which has been moved to l2tabu in 0.60.
324 %
325 % {\bfseries\label{disclaimer} Be warned, that this package will possibly balk at
326 % legitimate use, and not find illegitimate use in all cases. It is a
327 % tool, not a replacement for study of \pkg{l2tabu}.}
328 %
329 % \iffalse
330 %<*l2tabunag>
331 % \fi
332 % \begin{macrocode}
333 \ProvidesFile{nag-l2tabu.cfg}
334 [2010/05/17 v2.11 l2tabu rules for nag.sty (ulmi)]
335 %%
336 %% The sins.
337 %%
338 %% Section numbers refer to l2tabuen 1.7 revised/enlarged dated 2004OCT24
339 %% \S 1.1
340 \ObsoletePackage{a4wide}{the \lq a4paper\rq\space class option}
341 \ObsoletePackage{a4}{the \lq a4paper\rq\space class option}
342 %% \S 1.2--1.5 cannot reasonably be checked programmatically
343 %% \S 1.6
344 % \end{macrocode}
345 % Hacking galore ahead! We will make the dollar active. Since unlike
346 % \pkg{onlyamsmath}, we do not change the user's command to \LaTeX\ or
347 % \pkg{amsmath} commands, we need to store the old double dollar
348 % sequence as well as the single dollar.
349 % \begin{macrocode}
350 \def\nag@doubledollar{$$}%$$
351 \def\nag@singledollar{$}%$
352 % \end{macrocode}
353 % This is used to hide our redefinition in unprotected expanding
354 % context. This should not happen: you are expected to \emph{always}
355 % use protected means of expansion in \LaTeX, but fecal matter
356 % happens. See below for a good trick to distinguish expansion from
357 % executing context.
358 % \begin{macrocode}
359 \def\nag@expanding@voodoo#1#2#3{\relax\relax\nag@singledollar}
360
361 \def\nag@maybedispmath{%
362 \texorpdfstring{%
363 %% in TeX context, do tricky stuff.
364 \ifinner\expandafter\@firstoftwo
365 \else\expandafter\@secondoftwo\fi
366 {%% in inner mode, $$ is an empty formula, so no testing wanted.
367 \nag@singledollar}%
368 {%%
369 \ifx\protect\@typeset@protect\expandafter\@firstoftwo
370 \else\expandafter\@secondoftwo\fi
371 {%% normal case: looks like typesetting
372 %% protect against strictly expanding context
373 %% like TeX' \message: the first expanding voodoo will expand,
374 %% removing the rest, inserting \relax\relax$ instead. This is
375 %% not totally transparent, but \let\relax\relax is as close
376 %% to a no-op as we can get.
377 \let\nag@expanding@voodoo\nag@expanding@voodoo
378 \protect\nag@maybe@dispmath}%
379 {%% some other case, hide ourselves
380 \nag@singledollar}%
381 }%
382 }{%
383 %% in pdf context, just be a math shift. This creates the "math
384 %% shift not allowed" warnings we all love.
385 \nag@singledollar
386 }%
387 }
388 % \end{macrocode}
389 % If the user doesn't load \pkg{hyperref}, we have to fake its
390 % \cmd{\texorpdfstring} command. Note that this will break any package that
391 % is foolish enough to detect \pkg{hyperref} by testing for
392 % definedness of \cmd{\texorpdfstring}.
393 % \begin{macrocode}
394 \AtBeginDocument{\providecommand\texorpdfstring{\@firstoftwo}}
395 \AtBeginDocument{\catcode`$\active}%$
396 \AtEndDocument{\catcode`$=3\relax}
397 % \end{macrocode}
398 % Now, the proper testing. (Yes, the above is just the
399 % technicalities.) We use the kernel's \cmd{\@ifnextchar} to look for
400 % a possible second dollar. Note however, this would allow skipping of
401 % spaces between them, and \$\_\$ is not a displayed equation start in
402 % \TeX. We work around this by re\cmd{\let}ting \cmd{\@sptoken} to
403 % something that cannot legally appear in the source.
404 % \begin{macrocode}
405 \def\nag@quark{\nag@quark}
406 \bgroup
407 \catcode`$\active%$
408 \gdef\nag@maybe@dispmath{%
409 \bgroup
410 \let\@sptoken\nag@quark% prevent skipping of spaces
411 \@ifnextchar${%$%
412 \ifmmode
413 % we already warned upon entering.
414 \else
415 \nag@warn{%
416 \nag@doubledollar...\nag@doubledollar\space is obsolete.\MessageBreak
417 Use \string\[...\string\] et al. instead}%
418 \fi
419 \egroup\expandafter\nag@doubledollar\@gobble
420 }{%
421 \egroup\nag@singledollar
422 }%
423 }
424 % we do the assignment here, which means any package that redefines
425 % \$ as well will silently disable us. This is a feature.
426 \global\let$\nag@maybedispmath%$
427 \egroup
428 % \end{macrocode}
429 % \changes{0.61alpha6}{2008/01/27}{Compatibility w/ VCS packages, pgf}
430 %% new in 2.1alpha1: more compat testing. Version control keywords are dollar-delimited.
431 %% all five implementations get it wrong.
432 % \begin{macrocode}
433 \AtBeginDocument{%
434 \@ifpackageloaded{rcs}{%
435 % this redefinition is functionally equivalent,
436 % but does not share actual code.
437 \renewcommand\RCS{\bgroup%
438 \catcode`\_ =\active
439 \catcode`\$=3 % this line added for compatibility.
440 \csname RCS_get_argument\endcsname
441 }
442 \PackageInfo{nag}{rcs.sty hack applied}%
443 }{}%
444 \@ifpackageloaded{svninfo}{%
445 \g@addto@macro\@svnBeginRead{\catcode`\$ 3 }%
446 \PackageInfo{nag}{svninfo.sty hack applied}%
447 }{}%
448 \@ifpackageloaded{svn}{%
449 \PackageInfo{nag}{svn.sty is broken: disabling dollar check}%
450 \catcode`\$ 3
451 }{}%
452 \@ifpackageloaded{rcsinfo}{%
453 \PackageInfo{nag}{rcsinfo.sty is broken: disabling dollar check}%
454 \catcode`\$ 3
455 }{}%
456 \@ifpackageloaded{pgf}{%
457 \PackageInfo{nag}{pgf.sty is broken: disabling dollar check}%
458 \catcode`\$ 3
459 }{}%
460 }
461
462
463 %% \S 1.7 cannot reasonably be checked programmatically
464 %% \S 1.8 \sloppy is called by parbox, among others, and would
465 %% give many spurious warnings.
466 %% \S 2.1.1
467 \ObsoleteCS[an old LaTeX 2.09 command]{bf}
468 {\protect\bfseries\space or \protect\textbf}
469 \ObsoleteCS[an old LaTeX 2.09 command]{it}
470 {\protect\itshape\space or \protect\textit}
471 \ObsoleteCS[an old LaTeX 2.09 command]{rm}
472 {\protect\rmfamily\space or \protect\textrm}
473 \ObsoleteCS[an old LaTeX 2.09 command]{sc}
474 {\protect\scshape\space or \protect\textsc}
475 \ObsoleteCS[an old LaTeX 2.09 command]{sf}
476 {\protect\sffamily\space or \protect\textsf}
477 \ObsoleteCS[an old LaTeX 2.09 command]{sl}
478 {\protect\slshape\space or \protect\textsl}
479 \ObsoleteCS[an old LaTeX 2.09 command]{tt}
480 {\protect\ttfamily\space or \protect\texttt}
481 \ObsoleteCS[an old LaTeX 2.09 command]{cal}
482 {\protect\mathcal}% Hmm, this is not in l2tabu?
483 %% \S 2.1.2
484 %% Gone with 1.8 because this never worked for the kernel \frac anyway.
485 %% \ObsoleteCS[TeX]{over}{\protect\frac}
486 %% \ObsoleteCS[TeX]{choose}{\protect\frac\space or amsmath's \protect\binom}
487 %% \S 2.1.3
488 \ObsoleteCS[TeX]{centerline}{\protect\centering\space or center environment}
489 %% \S 2.2.1
490 \ObsoleteClass{scrlettr}{the scrlttr2 package}
491 %% \S 2.2.2
492 \ObsoletePackage{epsf}{the graphicx package}
493 \ObsoletePackage{psfig}{the graphicx package}
494 \ObsoletePackage[deprecated]{epsfig}{the graphicx package directly}
495 %% \S 2.2.3
496 \ObsoletePackage{doublespace}{the setspace package}
497 %% \S 2.2.4
498 \ObsoletePackage{fancyheadings}{the fancyhdr or scrpage2 packages}
499 \ObsoletePackage{scrpage}{the scrpage2 package}
500 %% \S 2.2.5
501 \ObsoletePackage{isolatin}{the inputenc package with option latin1}
502 \ObsoletePackage{umlaut}{the inputenc package with suitable option
503 (latin1, utf8 ...)}
504 \ObsoletePackage{isolatin1}{the inputenc package with option latin1}
505 %% \S 2.2.6
506 \ObsoletePackage{t1enc}{the fontenc package with option T1}
507 %% \S 2.2.7 we don't check for bst yet.
508 %% (This is in l2tabu 1.8)
509 \ObsoletePackage{caption2}{the caption package v3.0 or later}
510 %% \S 2.3.1-3
511 \ObsoletePackage{times}
512 {the mathptmx, helvet (option scaled=.9), courier packages}
513 \ObsoletePackage{pslatex}
514 {the mathptmx, helvet (option scaled=.9), courier packages}
515 \ObsoletePackage{mathptm}
516 {the mathptmx package}
517 %% \S 2.3.4-5
518 \ObsoletePackage{palatino}
519 {the mathpazo, helvet (option scaled=.95), courier packages}
520 \ObsoletePackage{mathpple}{the mathpazo package}
521 %% \S 2.3.6 can't be checked
522 %% \S 2.3.7
523 \ObsoletePackage{euler}{the eulervm package}
524 \ObsoletePackage{utopia}{the fourier package}
525 %% \S 3.1
526 \NagDeclareFloat{figure}\NagDeclareFloat{table}%
527 \g@addto@macro\nag@labels{,label,caption@xlabel}%
528 % \changes{0.60}{2007/03/31}{alternate center-in-float check, doesn't
529 % take up as many macro names}
530 \nag@prepend{endcenter}{%
531 \ifx\@captype\@undefined\else
532 \nag@warn{\lq center\rq\space environment in \@captype.\MessageBreak
533 Maybe you want \protect\centering\space instead}%
534 \fi
535 }%
536 %% The latter two are used by KOMA-Script, the last by hypcap.
537 % \changes{0.53}{2007/03/21}{hypcap support. (H.G.Krauth\"auser)}
538 % \changes{0.53}{2007/03/21}{topcapt support.}
539 \g@addto@macro\nag@captions{,caption,captionabove,captionbelow,hc@caption,topcaption}%
540
541 %% \S 3.2
542 \NotAnEnvironment{appendix}%
543 %% In the same vein:
544 \@for\sectioning:=frontmatter,mainmatter,backmatter\do{%
545 \expandafter\NotAnEnvironment\expandafter{\sectioning}%
546 }
547 %% \S 3.3
548 %% It's more trouble than it's worth to have another warning for
549 %% align*, since it passes through align.
550 \ObsoleteEnv{eqnarray}{amsmath's align}
551 %% \S 3.4 -- nothing to be done --
552 % \end{macrocode}
553 % \iffalse
554 %</l2tabunag>
555 % \fi
556 %
557 % \subsection{\texttt{nag-orthodox.cfg}}
558 % \texttt{nag-orthodox.cfg} warns about usage that is not technically
559 % incorrect, but will mostly do things an unwary user may not expect.
560 % This includes in particular the usage of font size and style switches
561 % as environments (line spacing will be off if the environment does not
562 % contain a trailing \string\par, spurious spaces might occur since the
563 % switches don't \string\ignorespaces), and, conversely, the usage of
564 % center etc. environments as unclosed switches. (Detection of the
565 % latter might still be somewhat brittle.)
566 % \iffalse
567 %<*orthodoxnag>
568 % \fi
569 % \begin{macrocode}
570 \ProvidesFile{nag-orthodox.cfg}
571 [2006/04/19 v1.8 strict rules for nag.sty (ulmi)]
572 \@for\fontcmd:=tiny,small,footnotesize,normalsize,large,Large,%
573 LARGE,huge,Huge\do{%
574 \expandafter\NotAnEnvironment\expandafter{\fontcmd}%
575 }%
576 \@for\fontcmd:=sffamily,rmfamily,ttfamily,%
577 bfseries,mdseries,scshape,%
578 itshape,upshape\do{%
579 \expandafter\NotAnEnvironment\expandafter{\fontcmd}%
580 }%
581 \@for\justsw:=centering,raggedleft,raggedright,%
582 RaggedLeft,RaggedRight\do{%
583 \expandafter\NotAnEnvironment\expandafter{\justsw}%
584 }
585 \@for\justenv:=center,flushleft,flushright\do{%
586 \expandafter\NotASwitch\expandafter{\justenv}%
587 }
588 % \end{macrocode}
589 %\iffalse
590 %</orthodoxnag>
591 %\fi
592 %
593 % \subsection{\texttt{nag-abort.cfg}}
594 % Requesting this nag file will turn all complaints into errors.
595 %
596 % \iffalse
597 %<*abortnag>
598 %\fi
599 % \begin{macrocode}
600 \ProvidesFile{nag-abort.cfg}
601 [2007/11/10 v0.2 treat complaints as errors (ulmi)]
602 \DeclareRobustCommand\nag@warn[1]{%
603 \addtocounter{nag@sins}{1}%
604 \PackageError{nag}{#1}{#1}%
605 }
606 \DeclareRobustCommand\nag@warnNoLine[1]{%
607 \addtocounter{nag@sins}{1}%
608 \PackageError{nag}{#1}{#1}%
609 }
610 % \end{macrocode}
611 %\iffalse
612 %</abortnag>
613 %<*experimentalnag>
614 %\fi
615 %\subsection{\texttt{nag-experimental.cfg}}
616 % Functionality that needs more testing.
617 % \begin{macrocode}
618 \ProvidesFile{nag-experimental.cfg}
619 [2009/07/04 v0.62alpha2 experimental additions to nag (ulmi)]
620 % \end{macrocode}
621 %
622 % Patch handling of nofiles: suppressed lines give an
623 % Info-level message in the logfile now. The message
624 % doesn't quite give the original line, but a sanitized
625 % version. Reason: otherwise, we might need to execute
626 % the setup code \#2.
627 %
628 % \begin{macrocode}
629 \long\def\nag@protected@dontwrite#1#2#3%
630 {\write\m@ne{}%
631 \def\nag@line{#3}%
632 \@onelevel@sanitize\nag@line
633 \PackageInfo{nag}{%
634 \string\nofiles\space in effect.
635 Did not write line \MessageBreak
636 `\nag@line'
637 }%
638 \if@nobreak\ifvmode\nobreak\fi\fi}%
639
640 \if@filesw
641 \def\nofiles{%
642 \@fileswfalse
643 \typeout{No auxiliary output files.^^J}%
644 \global\let\protected@write=\nag@protected@dontwrite
645 \let\makeindex\relax
646 \let\makeglossary\relax}
647 \else
648 % already \nofiles.
649 \global\let\protected@write=\nag@protected@dontwrite
650 \fi
651 % \end{macrocode}
652 %
653 % Amend ``no space for a new foo'' message to point out
654 % e\TeX\ alleviates some problems in that area.
655 % \begin{macrocode}
656 \gdef\ch@ck#1#2#3{%
657 \ifnum\count1#1<#2\else
658 \errhelp{%
659 eTeX has more counters, dimens, etc., maybe
660 that will help.
661 }
662 \errmessage{No room for a new #3}%
663 \fi}
664 % \end{macrocode}
665 %
666 % \begin{macrocode}
667 \def\@testdef #1#2#3{%
668 \def\reserved@a{#3}%
669 \expandafter \ifx \csname #1@#2\endcsname\reserved@a
670 \else
671 \@tempswatrue
672 \begingroup
673 \@onelevel@sanitize\reserved@a
674 \expandafter\let\expandafter\nag@tmpb\csname #1@#2\endcsname
675 \ifx\nag@tmpb\relax
676 \let\nag@tmpb\@empty
677 \else
678 \@onelevel@sanitize\nag@tmpb
679 \fi
680 \PackageInfo{nag}{%
681 Label `#2' appears to have changed from\MessageBreak
682 `\nag@tmpb'\MessageBreak
683 to `\reserved@a'
684 }%
685 \endgroup
686 \fi}
687 % \end{macrocode}
688 %
689 %
690 % Check if a float that may be positioned b is actually small
691 % enough for bottomfraction etc.
692 % \changes{0.62alpha1}{2008/03/19}{Bigger warning if all float positions fail}
693 % \changes{0.62alpha2}{2009/07/04}{Fix for marginpar etc which don't have fps}
694 % \begin{macrocode}
695 \let\@xa\expandafter
696 \newif\ifnag@dofloatsizecheck
697 \newif\ifnag@allfloatpositionsfailed
698 \newcommand\nag@allfloatsizechecks{}%
699 \newcommand\nag@onefloatsizecheck[2]{%
700 % #1 is size fraction of textheight,
701 % #2 is position to say in warning.
702 \ifdim \ht\@currbox>#1\textheight
703 \@tempdima -#1\textheight
704 \advance \@tempdima \ht\@currbox
705 \PackageInfo{nag}{Float too large for #2 by \the\@tempdima}%
706 % note we do not truncate.
707 % also, it's too late to add "p" now.
708 \else
709 \nag@allfloatpositionsfailedfalse
710 \fi
711 }
712 % \@currbox is current float box,
713 % \@fps is the current list of float specifiers.
714 \renewcommand\@largefloatcheck{%
715 \ifdim \ht\@currbox>\textheight
716 \@tempdima -\textheight
717 \advance \@tempdima \ht\@currbox
718 \@latex@warning {Float too large for page by \the\@tempdima}%
719 \ht\@currbox \textheight
720 \fi
721 %% the preceding is the original check.
722 \nag@dofloatsizechecktrue
723 \nag@allfloatpositionsfailedtrue
724 \def\nag@allfloatsizechecks{}%
725 \@xa\@xa\@xa\@tfor\@xa\@xa\@xa\nag@fltsz@tmp\@xa\@xa\@xa:\@xa\@xa\@xa=\csname @fps\endcsname\do{%
726 \ifx\nag@fltsz@tmp\relax
727 \nag@dofloatsizecheckfalse
728 \fi
729 \if\nag@fltsz@tmp !
730 \nag@dofloatsizecheckfalse
731 \else
732 \if\nag@fltsz@tmp t
733 \g@addto@macro\nag@allfloatsizechecks
734 {\nag@onefloatsizecheck{\topfraction}{top of page}}%
735 \else
736 \if\nag@fltsz@tmp b
737 \g@addto@macro\nag@allfloatsizechecks
738 {\nag@onefloatsizecheck{\bottomfraction}{bottom of page}}%
739 \else
740 \if\nag@fltsz@tmp p
741 \nag@allfloatpositionsfailedfalse
742 \fi
743 \fi
744 \fi
745 \fi
746 }%
747 \ifnag@dofloatsizecheck
748 \nag@allfloatsizechecks
749 \ifnag@allfloatpositionsfailed
750 \nag@warn{All float specifiers `\@fps' won't work}%
751 \fi
752 \fi
753 }%
754 % \end{macrocode}
755 % More experimental code: warning about files that were
756 % requested but not there. The really important one would
757 % be a check for include (this is just a typeout in the kernel?!).
758 % But as it is, we get warnings that point out missing ToC, LoF etc.
759 % \begin{macrocode}
760 \def\@input#1{%
761 \IfFileExists{#1}{\@@input\@filef@und}{%
762 \typeout{No file #1.}
763 \@latex@warning{File `#1' not found}
764 %{The file `#1' was requested but not found }
765 \protected@edef\nag@nofile{File `#1' requested, but not found}%
766 \@xa\AtEndDocument\@xa{%
767 \@xa\@latex@info@no@line\@xa{%
768 \nag@nofile
769 }%
770 }%
771 }}%
772 %
773 \def\@input@#1{\InputIfFileExists{#1}{}{%
774 \typeout{No file #1.}
775 \@latex@warning{File `#1' not found}
776 {The file `#1' was requested but not found }
777 \edef\nag@nofile{File `#1' requested, but not found}%
778 \@xa\AtEndDocument\@xa{%
779 \@xa\@latex@info@no@line\@xa{%
780 \nag@nofile
781 }%
782 }%
783 }}%
784 %
785 % \end{macrocode}
786 %\iffalse
787 %</experimentalnag>
788 %
789 %<*nag>
790 %\fi
791 % \section{Author-side considerations and implementation.}
792 % If you are a package or class author and want to extend the range
793 % of \pkg{nag} (or prevent \pkg{nag} from criticizing
794 % your macros), please see the description below, in
795 % sections~\ref{sec:obsol-cmds} and following. It is
796 % probably wise to group new rules in a seperate nag file:
797 % users can request nag files by passing their name as a package
798 % parameter, as shown above for the example of l2tabu.
799 %
800 % \subsection{Low-level tools.}
801 % Identify ourselves.
802 % \begin{macrocode}
803 \NeedsTeXFormat{LaTeX2e}
804 \ProvidesPackage{nag}[2011/11/25 0.7 warning about old commands (ulmi)]
805 \let\@xa\expandafter
806 \let\@nx\noexpand
807 % \end{macrocode}
808 % First of all, two counters we need. The first is used to
809 % generate running numbers for replacement macros, the latter is
810 % stepped for each complaint we have, so that the user gets a
811 % frighteningly high number, showing how sinful he or she is.
812 % \changes{0.61alpha1}{2007/11/10}{roman counter (external file issue)}
813 % \changes{0.61alpha4}{2008/01/01}{sin counter should not be saved by include}
814 % \begin{macrocode}
815 \newcounter{nag@c}
816 \renewcommand\thenag@c{\roman{nag@c}}%
817 \setcounter{nag@c}{1}%
818 \begingroup
819 \let\@addtoreset\@gobbletwo
820 \newcounter{nag@sins}%
821 \endgroup
822 % \end{macrocode}
823 %
824 % \begin{macro}{\nag@prepend}
825 % |\nag@prepend|\marg{cs}\marg{something}:
826 % Prepend \meta{something} to the macro definition of |\|\meta{cs}.
827 %
828 % In reality, we do call indirection: save old macro away,
829 % redefine macro to do the something, call old macro.
830 % (With thanks to Juergen Goebel, Heiko Oberdiek and Rolf Niepraschk
831 % (\pkg{savesym}))
832 %
833 % From $0.60\alpha_2$ on, nag is more robust about not defining
834 % commands that are not there. Now, they're not even relaxed.
835 % \begin{macrocode}
836 \newcommand\nag@ifundefined[1]{%
837 \begingroup
838 \@ifundefined{#1}{\endgroup\@firstoftwo}{\endgroup\@secondoftwo}%
839 }
840 % \end{macrocode}
841 % \changes{0.51}{2006/10/21}{bugfix}
842 % Don't define the macro if it's not there. This confuses caption,
843 % which loads ragged2e AtBeginDocument, at which point, RaggedLeft
844 % et al. were already defined by us.
845 % \changes{0.52}{2007/02/25}{info}
846 % \changes{0.60alpha2}{2007/04/08}{don't even relax unknown
847 % commands (J.Sommer)}
848 % \dots but \emph{do} log a message.
849 % \changes{0.61alpha1}{2007/11/10}{Extra indirection of warnings
850 % for robustness (uppercasing/LoF issues)}
851 % \changes{0.61alpha2}{2007/11/26}{Creep under existing robust cover}
852 % \begin{macrocode}
853 \newcommand\nag@prepend[2]{%
854 \nag@ifundefined{#1}{%
855 % if it doesn't exist, don't do anything.
856 \PackageInfo{nag}{%
857 Command \@backslashchar#1\space not defined, skipping amendment%
858 }%
859 }{%
860 \nag@ifundefined{#1 }{%
861 \let\nag@maybespace\@empty
862 }{%
863 \let\nag@maybespace\space
864 %\PackageInfo{nag}{%
865 % Command \@backslashchar#1\space appears robust\MessageBreak
866 % Modifying `\@backslashchar#1\space' instead.
867 %}%
868 }%
869 \@xa\let
870 \csname nag@@#1@\thenag@c\@xa\endcsname
871 \csname #1\nag@maybespace\endcsname
872 \@xa\DeclareRobustCommand\csname nag@@warning@\thenag@c\@xa\endcsname{%
873 #2%
874 }%
875 \@xa\nag@pr@p@nd\csname #1\nag@maybespace\@xa\endcsname
876 \csname nag@@#1@\thenag@c\@xa\endcsname
877 \csname nag@@warning@\thenag@c\@xa\endcsname
878 % \end{macrocode}
879 % Fun with scoping: one might think we can get away with a (non-local)
880 % |\advance\c@nag@c 1\relax| here. This would lead to less hashtable
881 % usage. Problem: if a nag@@foo@17 macro ever escapes its scope, it
882 % might be bound to something else entirely. This might occur with
883 % some of the fancier table packages which use external files?
884 % \begin{macrocode}
885 \stepcounter{nag@c}%
886 }%
887 }
888 \newcommand\nag@pr@p@nd[3]{%
889 \def#1{#3#2}%
890 }
891 % \end{macrocode}
892 % \end{macro}
893 % \begin{macro}{\nag@warn}
894 % All complaints to the user run through one of these two macros,
895 % with or without source line.
896 % \changes{0.61alpha1}{2007/11/10}{Made robust.}
897 % \begin{macrocode}
898 \DeclareRobustCommand\nag@warn{%
899 \addtocounter{nag@sins}{1}%
900 \PackageWarning{nag}%
901 }
902 \DeclareRobustCommand\nag@warnNoLine{%
903 \addtocounter{nag@sins}{1}%
904 \PackageWarningNoLine{nag}%
905 }
906 \providecommand\PackageInfoNoLine[2]{%
907 \PackageInfo{#1}{#2\@gobble}%
908 }
909 \DeclareRobustCommand\nag@suggestNoLine[1]{%
910 \PackageInfoNoLine{nag}{#1}%
911 }
912 % \end{macrocode}
913 % \end{macro}
914 %
915 % \subsection{Obsoletifying commands.}\label{sec:obsol-cmds}
916 %
917 % (No, I do not think that is a proper word either.)
918 %
919 % \begin{macro}{\ObsoleteCS}
920 % Usage: |\ObsoleteCS|\oarg{reason}\marg{CS}\marg{suggestions}
921 % Mark |\|\meta{CS} as obsolete. \meta{reason} defaults to
922 % obsolete. When the macro is used anyway, the following
923 % warning is logged:
924 %
925 % \noindent|Command \|\meta{CS}| is |\meta{reason}|. Use |\meta{suggestions}| instead.|
926 % \begin{macrocode}
927 \newcommand\ObsoleteCS[3][obsolete]{%
928 \AtBeginDocument{%
929 \nag@prepend{#2}{%
930 \nag@warn{%
931 Command \@backslashchar#2 is #1.
932 \MessageBreak
933 Use #3 instead}%
934 }%
935 }%
936 }
937 % \end{macrocode}
938 % \end{macro}
939 %
940 % \begin{macro}{\ObsoleteEnv}
941 % \changes{0.60alpha4}{2007/04/23}{There was no ObsoleteEnv?!}
942 % \begin{macrocode}
943 \newcommand\ObsoleteEnv[3][obsolete]{%
944 \AtBeginDocument{%
945 \nag@prepend{#2}{%
946 \nag@warn{%
947 Environment #2 is #1.
948 \MessageBreak
949 Use #3 instead}%
950 }%
951 }%
952 }
953 % \end{macrocode}
954 % \end{macro}
955 %
956 % \subsection{Obsoletifying packages and classes.}
957 %
958 % Checking for packages and classes is done by looking for
959 % |[email protected]|, which holds the version information that is also
960 % displayed by |\listfiles|. This means that we're out of luck if
961 % fontenc ever becomes obsolete, because that won't be detected.
962 %
963 % First, define a macro to check if a control sequence is defined.
964 % Unlike |\@ifundefined|, this will not define the control sequence
965 % to |\relax|, but the arguments will be executed in a group. For
966 % our purposes, this doesn't matter, because we only give a warning
967 % (and |\addtocounter| already is |\global|).
968 % \begin{macrocode}
969 \newcommand\nag@ifcsname[3]{%
970 \begingroup\@ifundefined{#1}{#3}{#2}\endgroup
971 }
972 % \end{macrocode}
973 % Just because we can, use $\epsilon$\TeX' |\ifcsname| if we can. This
974 % bootstrapping gives me a big grin\dots Note we add an extra group
975 % for compatibility with the non-$\epsilon$ case.
976 % \changes{0.52}{2007/02/25}{made eTeX-ifcsname more robust}
977 % \begin{macrocode}
978 \nag@ifcsname{ifcsname}{%
979 \renewcommand*\nag@ifcsname[3]{%
980 \begingroup
981 % assume it won't be there.
982 \let\tmp@a\@secondoftwo
983 \ifcsname #1\endcsname
984 % It still might be relax from some other test. Thanks to J\"org
985 % Sommer for finding this bug.
986 \expandafter\ifx\csname #1\endcsname\relax
987 \else
988 % it's there after all
989 \let\tmp@a\@firstoftwo
990 \fi
991 \fi
992 \tmp@a{#2}{#3}%
993 \endgroup
994 }%
995 % \end{macrocode}
996 % This way of escaping the grouping gives me an even
997 % bigger grin.
998 % \begin{macrocode}
999 \global\let\nag@ifcsname\nag@ifcsname
1000 }{}
1001 % \end{macrocode}
1002 %
1003 % \begin{macro}{\ObsoletePackage}
1004 % Usage: |\ObsoletePackage|\oarg{reason}\marg{package}\marg{%
1005 % alternative}. Mark \meta{package} as obsolete. \meta{reason} defaults
1006 % to obsolete. If the \meta{package} is used anyway, at the end of
1007 % the compilation, the following warning will be displayed:
1008 %
1009 % \noindent|Package |\meta{package}| is |\meta{reason}|. Use |
1010 % \meta{alternative}| instead.|
1011 % \begin{macrocode}
1012 \newcommand\ObsoletePackage[3][obsolete]{%
1013 \AtEndDocument{%
1014 % |\@clsextension| is onlypreamble, for some reason.
1015 \nag@ifcsname{ver@#2.sty}{%
1016 \nag@warnNoLine{%
1017 Package #2 is #1.\MessageBreak
1018 Use #3 instead}%
1019 }{}%
1020 }%
1021 }
1022 % \end{macrocode}
1023 % \end{macro}
1024 % \begin{macro}{\SuggestedPackage}
1025 % Usage: |\SuggestedPackage|\oarg{reason}\marg{package}
1026 % \begin{macrocode}
1027 \newcommand\SuggestedPackage[2][might be useful to you]{%
1028 \AtEndDocument{%
1029 \nag@ifcsname{ver@#2.sty}{%
1030 % Attaboy!
1031 }{%
1032 \nag@suggestNoLine{%
1033 Not loaded: Package #2 #1}%
1034 }%
1035 }%
1036 }%
1037 % \end{macrocode}
1038 % \end{macro}
1039 % \begin{macro}{\IncompatiblePackages}
1040 % Usage: |\IncompatiblePackages|\oarg{reason}\marg{package}\marg{package}\marg{hint}
1041 % \begin{macrocode}
1042 \newcommand\IncompatiblePackages[4][are incompatible]{%
1043 \AtEndDocument{%
1044 \nag@ifcsname{ver@#2.sty}{%
1045 \nag@ifcsname{ver@#3.sty}{%
1046 \nag@warnNoLine{%
1047 Packages #2 and #3 #1.\MessageBreak
1048 #4}%
1049 }{}%
1050 }{}
1051 }%
1052 }%
1053 % \end{macrocode}
1054 % \end{macro}
1055 %
1056 % \begin{macro}{\ObsoleteClass}
1057 % Usage: |\ObsoleteClass|\oarg{reason}\marg{class}\marg{%
1058 % alternative}. Mark \meta{class} as obsolete. \meta{reason} defaults
1059 % to obsolete. If the \meta{class} is used anyway, at the end of
1060 % the compilation, the following warning will be displayed:
1061 %
1062 % \noindent|Class |\meta{class}| is |\meta{reason}|. Use |
1063 % \meta{alternative}| instead.|
1064 % \begin{macrocode}
1065 \newcommand\ObsoleteClass[3][obsolete]{%
1066 \AtEndDocument{%
1067 % |\@clsextension| is onlypreamble, for some reason.
1068 \nag@ifcsname{ver@#2.cls}{%
1069 \nag@warnNoLine{%
1070 Class #2 is #1.\MessageBreak
1071 Use #3 instead}%
1072 }{}%
1073 }%
1074 }
1075 % \end{macrocode}
1076 % \end{macro}
1077 %
1078 % \begin{macro}{\BadFileLoadOrder}
1079 % \begin{macrocode}
1080 \def\nag@quark{\nag@quark}
1081 \ifx\@listfiles\@undefined
1082 % emulate a silent listfiles
1083 \def\@listfiles#1\@@{}%
1084 \fi
1085 \newcommand\BadFileLoadOrder[3][This might cause problems]{%
1086 \AtEndDocument{%
1087 \nag@ifLoadOrder{#2}{#3}{%
1088 \nag@warnNoLine{%
1089 `#3' loaded after `#2'.\MessageBreak
1090 #1}%
1091 }%
1092 }%
1093 }
1094 \def\nag@ifLoadOrder#1#2{%
1095 \def\nag@tmporder@a ##1#1##2\relax{%
1096 \ifx\nag@quark##2\nag@quark
1097 \noexpand\@gobble
1098 \else
1099 \nag@tmporder@b ##2,#2\relax
1100 \fi
1101 }%
1102 \def\nag@tmporder@b ##1#2##2\relax{%
1103 \ifx\nag@quark##2\nag@quark
1104 \noexpand\@gobble
1105 \else
1106 \noexpand\@firstofone
1107 \fi
1108 }%
1109 \@xa\protected@edef\@xa\nag@tmporder\@xa{\@xa\nag@tmporder@a\@filelist,,#1\relax}%
1110 \nag@tmporder
1111 }
1112 % \end{macrocode}
1113 % \end{macro}
1114 %
1115 % \subsection{Common float errors and no-nos.}
1116 %
1117 % We do the following:
1118 % \begin{itemize}
1119 % \item check for presence of a caption
1120 % \item check for absence of the center environment
1121 % \item check that a label comes only after a caption
1122 % \end{itemize}
1123 %
1124 % First of all, we define two ifs to memorize whether we have a
1125 % label and/or a caption in the float already. Package writers may
1126 % want to set these manually behind \pkg{nag}'s back. In this
1127 % way, they can suppress possible warnings if they know what
1128 % they're doing -- we only check at the end of the float
1129 % environment, which gives them plenty of time to call
1130 % |\csname nag@haslabeltrue\endcsname| et al.
1131 % (Thanks to Markus Kohm for pointing out this need.)
1132 % We initialize |\nag@hascaption| to be true because since 0.60,
1133 % |\label| always checks if it's after a caption, even outside of
1134 % floats.
1135 % \begin{macrocode}
1136 \newif\ifnag@haslabel
1137 \newif\ifnag@hascaption\nag@hascaptiontrue
1138 % \end{macrocode}
1139 % Now, to the work proper: as of 0.60, it is sufficient to set the
1140 % label and caption flags to false. |\endcenter| now always checks
1141 % if it is inside a float (looking at |\@captype|). The label and
1142 % caption commands are amended only once. This should be
1143 % sufficient: captions are not handled by letting |\caption| to the
1144 % proper command upon float entry, so we assume nobody redefines
1145 % |\caption| at runtime, or they provide more entries to
1146 % |\nag@captions|. Similar for |\label|, and we do not care about
1147 % the flag setting outside of floats.
1148 % \begin{macrocode}
1149 \newcommand\nag@hackfloat[1]{%
1150 \nag@prepend{#1}{%
1151 \global\nag@haslabelfalse\global\nag@hascaptionfalse
1152 }%
1153 \nag@prepend{end#1}{%
1154 \ifnag@hascaption\relax\else
1155 \nag@warn%
1156 {#1 with no \protect\caption}%
1157 \fi
1158 % labels outside floats shouldn't complain:
1159 \global\nag@hascaptiontrue
1160 % (we do this always because it needs to be global)
1161 }%
1162 }
1163 % \end{macrocode}
1164 % Add checks to all macros named by |\nag@labels|
1165 % and |\nag@captions|, respectively.
1166 % \changes{0.3}{2005/07/07}{Fixed missing globals}
1167 % Scoping of presence-of-caption information:
1168 % \changes{0.4}{2006/04/19}{bugfix}
1169 % Well, maybe I should do it the way the kernel does, which means
1170 % a label is just as local as |\refstepcounter|'s |\@currentlabel|
1171 % information as of v0.4. I think we can leave captions global.
1172 % \changes{0.60}{2007/03/31}{Captions/Labels now done only once, and not every time
1173 % we enter a float}
1174 % \changes{0.60}{2007/03/31}{@preamblecmds}
1175 % Big old hack: we do this at |\@preamblecmds|-time, which is after
1176 % |\AtBeginDocument|, since hyperref loads nameref ABD, and nameref
1177 % steps all over label. \emph{Note:} We cannot use |\nag@prepend|
1178 % for this, since it would break the pkgindoc package, which nobody
1179 % has ever heard of, but it's in the kernel and relies on certain
1180 % tokens being present in the expansion of |\@preamblecmds|. Now,
1181 % you pretty much cannot get any later than this.
1182 %
1183 % \emph{Note:} we cannot exchange the order of the for loops here:
1184 % if a cs generates both a label and a caption, it shouldn't get
1185 % complained about.
1186 % \begin{macrocode}
1187 \AtBeginDocument{%
1188 \g@addto@macro{\@preamblecmds}{%
1189 \@for\labelprovider:=\nag@labels\do{%
1190 \ifx\labelprovider\@empty\else
1191 \nag@prepend{\labelprovider}%
1192 {\nag@captioncheck\nag@haslabeltrue}%
1193 \fi
1194 }%
1195 \@for\captionprovider:=\nag@captions\do{%
1196 \ifx\captionprovider\@empty\else
1197 \nag@prepend{\captionprovider}{\global\nag@hascaptiontrue}%
1198 \fi
1199 }%
1200 }%
1201 }
1202 \newcommand\nag@captioncheck{%
1203 \ifnag@hascaption\else
1204 \nag@warn{\protect\label\space in float, but not after
1205 \protect\caption}%
1206 \fi
1207 }
1208 % \end{macrocode}
1209 % Define the lists of commands that are floats, generate labels,
1210 % and generate captions, respectively. We don't start with defined
1211 % floats (that is for nag-l2tabu.cfg to set up). Since v0.52, we handle
1212 % an empty name, so the lists may be empty. Also, no labels and
1213 % captions are provided by default since v0.52. This has been moved
1214 % to nag-l2tabu.cfg.
1215 % See also
1216 % |\NagDeclareFloat|, which is the user-level wrapper for new
1217 % floats. Since there are no packages to define new
1218 % caption or label commands on an user level, there is no wrapper
1219 % for those.
1220 % \begin{macrocode}
1221 \def\nag@floats{}
1222 \def\nag@labels{}
1223 \def\nag@captions{}
1224 % \end{macrocode}
1225 %
1226 % We call the above for each float environment named via
1227 % |\nag@floats|:
1228 % \begin{macrocode}
1229 \newcommand\nag@floatsetup{%
1230 \@for\flo:=\nag@floats\do{%
1231 \ifx\flo\@empty\else
1232 \@xa\nag@hackfloat\@xa{\flo}%
1233 \fi
1234 }%
1235 }
1236 % \end{macrocode}
1237 % but only after all other packages get their chance to add to the
1238 % list:
1239 % \begin{macrocode}
1240 \AtBeginDocument{%
1241 \nag@floatsetup
1242 }
1243 % \end{macrocode}
1244 %
1245 % At the very end, we will display a running total of complaints.
1246 % \begin{macrocode}
1247 \AtBeginDocument{%
1248 \AtEndDocument{%
1249 \ifnum\value{nag@sins}>0%
1250 \PackageWarningNoLine{nag}{\arabic{nag@sins} complaints
1251 in total}%
1252 \else
1253 \typeout{No complaints by nag.}%
1254 \fi
1255 }%
1256 }
1257 % \end{macrocode}
1258 %
1259 % \section{Switch vs. Environment}
1260 %
1261 % People often use switches as environments and vice versa. This is
1262 % dangerous in because it tends to \emph{almost} work.
1263 % (Consider font size commands in particular, but also |\centering|
1264 % vs. |center| environment.) As usual, ``it's not an error if you
1265 % know what you're doing''. In particular, it is perfectly valid
1266 % code to use the |\foo|\dots|\endfoo| syntax. So, |\NotASwitch|
1267 % needs to trace the calls to |\foo| and see if they match with
1268 % corresponding |\endfoo|s with its own stack. This might still be
1269 % brittle. Fortunately, it is currently only needed for
1270 % nag-orthodox, where it checks for the justification environments.
1271 %
1272 % First of all, a helper macro we hinge upon:
1273 % \changes{0.53}{2007/03/20}{bugfix: more Robustness. (J\"org Sommer)}
1274 % \begin{macrocode}
1275 \DeclareRobustCommand\nag@ifCurrentEnvironment[3]{%
1276 \bgroup
1277 \def\tmp@a{#1}%
1278 \ifx\@currenvir\tmp@a
1279 #2%
1280 \else
1281 #3%
1282 \fi
1283 \egroup
1284 }
1285 % \end{macrocode}
1286 % And now, the two variations there are:
1287 % \begin{macro}{\NotAnEnvironment}
1288 % Usage:|\NotAnEnvironment|\marg{command}
1289 % Issue an error if the user calls |\begin{command}| and not
1290 % |\command| directly.
1291 % \begin{macrocode}
1292 \newcommand\NotAnEnvironment[1]{%
1293 \AtBeginDocument{%
1294 \nag@prepend{#1}{%
1295 \nag@ifCurrentEnvironment{#1}{%
1296 \nag@warn{%
1297 There is no environment ``#1''.\MessageBreak
1298 Maybe you want a grouped \@backslashchar#1
1299 }%
1300 }{% OK case.
1301 }%
1302 }%
1303 }%
1304 }
1305 % \end{macrocode}
1306 % \end{macro}
1307 % |\NotASwitch| is a bit more involved:
1308 % \begin{macro}{\NotASwitch}
1309 % Usage:|\NotASwitch|\marg{command}
1310 % Issue an error if the user calls |\command| and not
1311 % |\begin{command}| and mis-nests calls or doesn't call
1312 % |\endcommand| at all.
1313 % \changes{0.54}{2007/03/27}{bugfix: can't get around the token register. (J\"org Sommer)}
1314 % \begin{macrocode}
1315 % we need to maintain a stack of environments that are used in the
1316 % \foo...\endfoo way.
1317 \newcommand\nag@envstack{\relax}
1318
1319 \DeclareRobustCommand\nag@beginenv[1]{%
1320 % push a begin-entry onto the stack. Form is
1321 % |{\foo{lineno}}| for environment foo.
1322 \bgroup
1323 \@xa\toks@\@xa{\nag@envstack}%
1324 \xdef\nag@envstack{%
1325 \@nx{%
1326 \@xa\@nx\csname #1\endcsname
1327 \@nx{\the\inputlineno\@nx}%
1328 \@nx}%
1329 \the\toks@
1330 }%
1331 \egroup
1332 }
1333 \DeclareRobustCommand\nag@endenv[1]{%
1334 % extract the first entry.
1335 \@xa\nag@end@nv\nag@envstack\@nil #1\@nil
1336 }
1337
1338 \def\nag@end@nv#1#2\@nil #3\@nil{%
1339 \def\tmp@a{#1}%
1340 \def\tmp@b{\relax}%
1341 \ifx\tmp@a\tmp@b
1342 % This was the end-of-stack flag.
1343 \nag@warn{``\@backslashchar end#3'' without matching
1344 ``\@backslashchar #3''}
1345 \else
1346 % We may assume this is a proper entry. See if the begin-token on
1347 % the stack matches what |\nag@endenv| was passed.
1348 \@xa\ifx\csname #3\@xa\endcsname\@firstoftwo #1%
1349 %OK case, just pop the entry.
1350 \gdef\nag@envstack{#2}%
1351 \else
1352 % error case
1353 \nag@warn{%
1354 You cannot close ``\@xa\string\@firstoftwo #1'' on line
1355 \@secondoftwo #1 with ``\@backslashchar end#3''%
1356 }%
1357 % leave it on the stack. Some case of misnesting will always cause
1358 % horrible amounts of follow-up errors. Also, scare them!
1359 \fi
1360 \fi
1361 }
1362 % \end{macrocode}
1363 % At the end, we complain about all the entries that are still on
1364 % the stack.
1365 % \begin{macrocode}
1366 \AtEndDocument{%
1367 \@xa\@tfor\@xa\looseends\@xa:\@xa=\nag@envstack\do{%
1368 \@xa\ifx\looseends\relax\else
1369 \nag@warnNoLine{Unmatched
1370 ``\@xa\@xa\@xa\string\@xa\@firstoftwo\looseends''
1371 command on line
1372 \@xa\@xa\@xa\string\@xa\@secondoftwo\looseends%
1373 }%
1374 \fi
1375 }%
1376 }
1377 % \end{macrocode}
1378 % \end{macro}
1379 % Now, the user-side command is easy.
1380 % \begin{macrocode}
1381 \newcommand\NotASwitch[1]{%
1382 \AtBeginDocument{%
1383 \nag@prepend{#1}{%
1384 \nag@beginenv{#1}%
1385 }%
1386 \nag@prepend{end#1}{%
1387 \nag@endenv{#1}%
1388 }%
1389 }%
1390 }
1391 % \end{macrocode}
1392 %
1393 % \section{Compatibility issues}
1394 % \subsection{The \pkg{caption} package}
1395 % Axel Sommerfeldt's \pkg{caption} package loads the \pkg{ragged2e}
1396 % package AtBeginDocument (regardless of whether it is needed).
1397 % This is too late for us to amend the |\RaggedFoo| commands with
1398 % |\NotAnEnvironment|. Since v0.51 of \pkg{nag}, they will then be
1399 % skipped (with information in the log). Earlier versions would
1400 % fail because by time \pkg{ragged2e} was loaded, the commands were
1401 % already defined by the amendment process. To make sure the
1402 % commands \emph{are} amended, load \pkg{ragged2e} explicitly
1403 % yourself.
1404 %
1405 % \subsection{The \pkg{subfig} package}
1406 % Starting with v0.52 of \pkg{nag}, we recognize the fact that the
1407 % |\subfloat| command from Steven D. Cochran's \pkg{subfig} package
1408 % is a caption-provider for its fourth argument. Earlier versions
1409 % would flag use of |\label| as inappropriate. The current
1410 % implementation works with versions close enough to v1.3 of
1411 % \pkg{subfig}. Since the change is a one-liner, I hope it will be
1412 % integrated into future versions of \pkg{subfig}.
1413 % \changes{0.52}{2007/02/25}{twiddle subfig's bowels}
1414 % \begin{macrocode}
1415 \AtBeginDocument{%
1416 \nag@ifcsname{[email protected]}{%
1417 \PackageInfo{nag}{Attempting subfig hack\@gobble}%
1418 \nag@maybehacksubfig
1419 }{%
1420 }%
1421 }
1422 \def\nag@maybehacksubfig{%
1423 %
1424 % of course, i need to touch the single longest definition in
1425 % subfig.sty, to amend one single command...
1426 %
1427 % The definition is taken from subfig.sty 1.3 dated 2005/07/05 by
1428 % S.D. Chochran, where it is called sf@@@subfloat, and appears here
1429 % under the conditions of section 6 of the LPPL 1.3. The subfig
1430 % package is available on a CTAN mirror near you.
1431 %
1432 \long\def\nag@@original@@sf@@@subfloat##1[##2][##3]##4{%
1433 \@ifundefined{FBsc@max}{%
1434 }{%
1435 \FB@readaux{\let\FBsuboheight\relax}%
1436 }%
1437 \@tempcnta=\@ne
1438 \if@minipage
1439 \@tempcnta=\z@
1440 \else\ifdim \lastskip=\z@ \else
1441 \@tempcnta=\tw@
1442 \fi\fi
1443 \ifmaincaptiontop
1444 \sf@top=\sf@nearskip
1445 \sf@bottom=\sf@farskip
1446 \else
1447 \sf@top=\sf@farskip
1448 \sf@bottom=\sf@nearskip
1449 \fi
1450 \leavevmode
1451 \setbox\@tempboxa \hbox{%
1452 ##4}%
1453 \@tempdima=\wd\@tempboxa
1454 \@ifundefined{FBsc@max}{%
1455 }{%
1456 \global\advance\Xhsize-\wd\@tempboxa
1457 \dimen@=\ht\@tempboxa
1458 \advance\dimen@\dp\@tempboxa
1459 \ifdim\dimen@>\FBso@max
1460 \global\FBso@max\dimen@
1461 \fi
1462 }%
1463 \vtop\bgroup
1464 \vbox\bgroup
1465 \ifcase\@tempcnta
1466 \@minipagefalse
1467 \or
1468 \vskip\sf@top
1469 \or
1470 \ifdim \lastskip=\z@ \else
1471 \@tempskipb\sf@top\relax\@xaddvskip
1472 \fi
1473 \fi
1474 \sf@ifpositiontop{%
1475 \ifx \@empty##3\relax \else
1476 \sf@subcaption{##1}{##2}{##3}%
1477 \vskip\sf@capskip
1478 \vskip\sf@captopadj
1479 \fi\egroup
1480 \hrule width0pt height0pt depth0pt
1481 \box\@tempboxa
1482 }{%
1483 \@ifundefined{FBsc@max}{%
1484 \box\@tempboxa
1485 }{%
1486 \ifx\FBsuboheight\relax
1487 \box\@tempboxa
1488 \else
1489 \vbox to \FBsuboheight{\FBafil\box\@tempboxa\FBbfil}%
1490 \fi}%
1491 \egroup
1492 \ifx \@empty##3\relax \else
1493 \vskip\sf@capskip
1494 \hrule width0pt height0pt depth0pt
1495 \sf@subcaption{##1}{##2}{##3}%
1496 \fi
1497 }%
1498 \vskip\sf@bottom
1499 \egroup
1500 \@ifundefined{FBsc@max}{%
1501 }{%
1502 \addtocounter{FRobj}{-1}%
1503 \ifnum\c@FRobj=0\else
1504 \subfloatrowsep
1505 \fi
1506 }%
1507 \ifmaincaptiontop\else
1508 \global\advance\@nameuse{c@\@captype}\m@ne
1509 \fi
1510 \endgroup\ignorespaces}%
1511 %
1512 \expandafter\ifx\csname sf@@@subfloat\endcsname\nag@@original@@sf@@@subfloat
1513 % yup, that's it.
1514 \PackageInfo{nag}{OK, equivalent to subfig 1.3, redefining
1515 \@backslashchar sf@@@subfloat\@gobble}%
1516 \global\long\def\sf@@@subfloat##1[##2][##3]##4{%
1517 \@ifundefined{FBsc@max}{%
1518 }{%
1519 \FB@readaux{\let\FBsuboheight\relax}%
1520 }%
1521 \@tempcnta=\@ne
1522 \if@minipage
1523 \@tempcnta=\z@
1524 \else\ifdim \lastskip=\z@ \else
1525 \@tempcnta=\tw@
1526 \fi\fi
1527 \ifmaincaptiontop
1528 \sf@top=\sf@nearskip
1529 \sf@bottom=\sf@farskip
1530 \else
1531 \sf@top=\sf@farskip
1532 \sf@bottom=\sf@nearskip
1533 \fi
1534 \leavevmode
1535 \setbox\@tempboxa \hbox{%
1536 %% ulmi: new 2007/02/25: #4 may contain label command
1537 \csname nag@hascaptiontrue\endcsname
1538 %% and that was it.
1539 ##4}%
1540 \@tempdima=\wd\@tempboxa
1541 \@ifundefined{FBsc@max}{%
1542 }{%
1543 \global\advance\Xhsize-\wd\@tempboxa
1544 \dimen@=\ht\@tempboxa
1545 \advance\dimen@\dp\@tempboxa
1546 \ifdim\dimen@>\FBso@max
1547 \global\FBso@max\dimen@
1548 \fi
1549 }%
1550 \vtop\bgroup
1551 %% ulmi: new 2007/05/10: #2, #3 may contain label command
1552 \csname nag@hascaptiontrue\endcsname
1553 %% and that was it.
1554 \vbox\bgroup
1555 \ifcase\@tempcnta
1556 \@minipagefalse
1557 \or
1558 \vskip\sf@top
1559 \or
1560 \ifdim \lastskip=\z@ \else
1561 \@tempskipb\sf@top\relax\@xaddvskip
1562 \fi
1563 \fi
1564 \sf@ifpositiontop{%
1565 \ifx \@empty##3\relax \else
1566 \sf@subcaption{##1}{##2}{##3}%
1567 \vskip\sf@capskip
1568 \vskip\sf@captopadj
1569 \fi\egroup
1570 \hrule width0pt height0pt depth0pt
1571 \box\@tempboxa
1572 }{%
1573 \@ifundefined{FBsc@max}{%
1574 \box\@tempboxa
1575 }{%
1576 \ifx\FBsuboheight\relax
1577 \box\@tempboxa
1578 \else
1579 \vbox to \FBsuboheight{\FBafil\box\@tempboxa\FBbfil}%
1580 \fi}%
1581 \egroup
1582 \ifx \@empty##3\relax \else
1583 \vskip\sf@capskip
1584 \hrule width0pt height0pt depth0pt
1585 \sf@subcaption{##1}{##2}{##3}%
1586 \fi
1587 }%
1588 \vskip\sf@bottom
1589 \egroup
1590 \@ifundefined{FBsc@max}{%
1591 }{%
1592 \addtocounter{FRobj}{-1}%
1593 \ifnum\c@FRobj=0\else
1594 \subfloatrowsep
1595 \fi
1596 }%
1597 \ifmaincaptiontop\else
1598 \global\advance\@nameuse{c@\@captype}\m@ne
1599 \fi
1600 \endgroup\ignorespaces}%
1601 \else
1602 \PackageInfo{nag}{Not redefining sf@@@subfloat, it looks odd\@gobble}
1603 \fi
1604 }
1605 % \end{macrocode}
1606 %
1607 % \subsection{The \pkg{float} package}
1608 % Sorry, there is no way for \pkg{nag} to automatically add new
1609 % float types to check them for captions. However, since v0.52,
1610 % there is an user-level command |\NagDeclareFloat| that will do
1611 % the bookkeeping for you, i.e. after your call to |\newfloat|, you
1612 % call |\NagDeclareFloat| with the first argument to |\newfloat|.
1613 % \changes{0.52}{2007/02/25}{Command NagDeclareFloat added}
1614 % \begin{macrocode}
1615 \newcommand*\NagDeclareFloat[1]{\g@addto@macro\nag@floats{,#1}}
1616 % \end{macrocode}
1617 %
1618 % \subsection{The \pkg{topcapt} package and the \pkg{subfig} package}
1619 % nagdemo exhibits an error when topcapt and subfig are used
1620 % together, i.e. \pkg{subfig} thinks the caption has not been
1621 % stepped already. This is not a bug in \pkg{nag}.
1622 %
1623 % \subsection{The \pkg{rotating} package}
1624 % \pkg{rotating} uses \cmd{\centerline} to place rotated floats. As
1625 % far as I can see, the usage is legitimate there, and using
1626 % \cmd{\centering} instead would change behaviour when the float's
1627 % dimension are larger than the text body. (Currently, the height
1628 % of the figure may exceed \cmd{\textwidth} without warning.) If this
1629 % bothers you, go read the warning on p.~\pageref{disclaimer} again.
1630 %
1631 % \subsection{Version control packages}
1632 % Common version control systems like rcs, cvs, svn insert their keywords
1633 % between dollar signs. Packages that parse these keywords define their
1634 % commands and usually assume catcode 3, which is not true if either
1635 % \pkg{onlyamsmath} or \pkg{nag} is loaded. Special handling is
1636 % introduced for \pkg{rcs} and \pkg{svninfo}. In case of \pkg{rcsinfo},
1637 % \pkg{svn} and \pkg{pgf} (yes, it's got internal VC handling that fails
1638 % when \cmd{\pgfuselibrary} is used outside the preamble -- thanks to
1639 % Ralf Th\"ole for spotting this one), dollar checking is disabled.
1640 %
1641 % \section{Loading extensions}
1642 % Finally, we deal with package options.
1643 % This is simple: just try to input appropriate nag files.
1644 % \changes{0.4}{2006/04/19}{config file names changed to free extension}
1645 % \begin{macrocode}
1646 \DeclareOption*{%
1647 \InputIfFileExists{nag-\CurrentOption.cfg}{%
1648 \PackageInfo{nag}{%
1649 Loaded nag-\CurrentOption.cfg
1650 }
1651 }{%
1652 \InputIfFileExists{\CurrentOption.nag}{%
1653 \PackageWarningNoLine{nag}{%
1654 Loaded old-style config file \CurrentOption.nag.\MessageBreak
1655 Consider renaming the file to nag-\CurrentOption.cfg
1656 }%
1657 }{%
1658 \PackageWarningNoLine{nag}{Required ruleset
1659 \CurrentOption, and it wasn't there}
1660 }%
1661 }
1662 }
1663 \ProcessOptions*
1664 % \end{macrocode}
1665 %\iffalse
1666 %</nag>
1667 %\fi
1668 % \PrintChanges
1669 %\PrintIndex
1670 %\Finale
1671 %\iffalse
1672 %%X Local Variables:
1673 %%X mode: latex
1674 %%X End:
1675 %\fi