Debian Codegraph @

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

raw
1 %\iffalse
2 % hideproofs.dtx generated using makedtx version 1.2 (c) Nicola Talbot
3 % Command line args:
4 % -src "hideproofs\.sty=>hideproofs.sty"
5 % -doc "hideproofs-doc.tex"
6 % hideproofs
7 % Created on 2025/6/15 0:20
8 %\fi
9 %\iffalse
10 %<*package>
11 %% \CharacterTable
12 %% {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
13 %% 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
14 %% Digits \0\1\2\3\4\5\6\7\8\9
15 %% Exclamation \! Double quote \" Hash (number) \#
16 %% Dollar \$ Percent \% Ampersand \&
17 %% Acute accent \' Left paren \( Right paren \)
18 %% Asterisk \* Plus \+ Comma \,
19 %% Minus \- Point \. Solidus \/
20 %% Colon \: Semicolon \; Less than \<
21 %% Equals \= Greater than \> Question mark \?
22 %% Commercial at \@ Left bracket \[ Backslash \\
23 %% Right bracket \] Circumflex \^ Underscore \_
24 %% Grave accent \` Left brace \{ Vertical bar \|
25 %% Right brace \} Tilde \~}
26 %</package>
27 %\fi
28 % \iffalse
29 % Doc-Source file to use with LaTeX2e
30 % Copyright (C) 2025 pwintz, all rights reserved.
31 % \fi
32 % \iffalse
33 %<*driver>
34 \documentclass{article}
35 \usepackage[a4paper, margin=1in]{geometry}
36 \usepackage{hideproofs}
37 \usepackage{lmodern}
38 \usepackage{xcolor}
39 \usepackage[final, % Include links even if document is in 'draft' mode.
40 hidelinks, % Prevent boxes from being drawn around links in some viewers.
41 breaklinks=true, % Allow line breaks in the middle of links
42 colorlinks=true,
43 linkcolor=black, % TOC, links to labeled equations and environments
44 filecolor=magenta,
45 urlcolor=black!30!blue, % URLS including links in references
46 citecolor=black!30!blue, % In-line citations
47 ]{hyperref}
48 \usepackage{listings}
49 \lstdefinestyle{mystyle}{
50 backgroundcolor=\color{gray!10}, % light gray background
51 commentstyle=\color{green!50!black}\itshape,
52 keywordstyle=\color{blue!70!black}\bfseries,
53 numberstyle=\tiny\color{gray},
54 stringstyle=\color{orange!80!black},
55 basicstyle=\ttfamily\small,
56 % breakatwhitespace=false,
57 % breaklines=true,
58 % captionpos=b,
59 keepspaces=true,
60 numbers=left,
61 numbersep=5pt,
62 showspaces=false,
63 % showstringspaces=false,
64 % showtabs=false,
65 frame=single,
66 rulecolor=\color{black},
67 tabsize=2,
68 xleftmargin=10pt,
69 xrightmargin=5pt,
70 aboveskip=10pt,
71 belowskip=0pt
72 }
73 \lstset{style=mystyle}
74
75 \setlength{\parindent}{0pt} % No indentation
76 \setlength{\parskip}{1em} % Add vertical space between paragraphs
77
78 \title{Hide Proofs \LaTeX{} Package \\
79 \large Define a \texttt{proof*} environment to hides proofs based on document mode}
80 \author{Paul Wintz}
81 \date{June 14, 2025}
82
83 \begin{document}
84 \DocInput{hideproofs.dtx}
85 \end{document}
86 %</driver>
87 %\fi
88 %\maketitle
89 %
90 %\begin{abstract}
91 %The \texttt{hideproofs} package provides a convenient way to conditionally hide or display proof contents in LaTeX documents based on the document mode (\texttt{draft}, \texttt{final}, or neither). It defines a starred proof environment \verb|proof*| that behaves like the standard \verb|proof| environment from \texttt{amsthm}, but optionally hides its body and replaces it with a customizable message.
92 %The motivation for this package is to reduce the clutter in large files by omitting long proofs, allowing authors to focus their attention on results or proofs that are currently works in-progress.
93 %\end{abstract}
94 %
95 %
96 %%===================================
97 %%===================================
98 %\section{Requirements}
99 %\label{sec:Requirements}
100 %This package requires \LaTeX3 support (\texttt{expl3}, \texttt{l3keys2e}).
101 %
102 %% \section{Installation}
103 %%
104 %% Eventually, \texttt{hideproofs} may be bundled with \LaTeX{} installations.
105 %% Until then, you must install it manually.
106 %% The
107 %% % TODO: Update this.
108 %% Put \texttt{hideproofs.sty} in your project's directory or somewhere in your \TeX\ path.
109 %
110 %%===================================
111 %%===================================
112 %\section{Usage}
113 %\label{sec:Usage}
114 %To use the \texttt{hideproofs} package, load it in your document preamble:
115 %\begin{lstlisting}[language=TeX]
116 %\usepackage{hideproofs}
117 %\end{lstlisting}
118 %Then, replace any \texttt{proof} environments you want to hide with a \texttt{proof*} environment:
119 %\begin{lstlisting}[language=TeX]
120 %\begin{proof*}
121 % This is the proof that will be hidden based on the mode.
122 %\end{proof*}
123 %\end{lstlisting}
124 %
125 %By default, proofs are hidden in \texttt{draft} and default (non-\texttt{draft}, non-\texttt{final}) document modes, and shown only in \texttt{final} mode.
126 %To compile your document \texttt{draft} mode, pass \texttt{draft} as a class option:
127 %\begin{lstlisting}[language=TeX]
128 %\documentclass[draft]{article}
129 %\end{lstlisting}
130 %Similarly for \texttt{final}:
131 %\begin{lstlisting}[language=TeX]
132 %\documentclass[draft]{article}
133 %\end{lstlisting}
134 %The default mode has neither \texttt{draft} nor \texttt{final} in the class options:
135 %\begin{lstlisting}[language=TeX]
136 %\documentclass{article}
137 %\end{lstlisting}
138 %
139 %\section{Package Options}
140 %
141 %Several package options allow you to customize the hiding behavior and the appearance of the message that replaces hidden proofs.
142 %
143 %\subsection*{Hiding options}
144 %
145 %The following options control when proofs are hidden or shown, based on the document class options:
146 %\begin{description}
147 % \item[\texttt{hideInDraft}] Hide proofs in \texttt{draft} mode. Default: \texttt{true}.
148 % \item[\texttt{hideInDefault}] Hide proofs in the default mode (neither \texttt{draft} nor \texttt{final}). Default: \texttt{true}.
149 % % \item[\texttt{showInFinal}] Show proofs in \texttt{final} mode.
150 % \item[\texttt{hideInFinal}] Hide proofs in \texttt{final} mode. Default: \texttt{false}.
151 % % (Negation of \texttt{showInFinal}. Default behavior) .
152 % \item[\texttt{show}] Show all proofs, regardless of mode-specific settings.
153 % \item[\texttt{hide}] Hide all proofs in \texttt{proof*} environments, regardless of mode-specific settings.
154 %\end{description}
155 %
156 %% The follow options are also available, but they match the default behavior:
157 %% \begin{description}
158 %% \item[\texttt{showInDraft}] Show proofs in \texttt{draft} mode. (Negation of \texttt{hideInDraft}. Default behavior)
159 %% \item[\texttt{showInDefault}] Show proofs in the default mode. (Negation of \texttt{hideInDraft}. Default behavior)
160 %% \end{description}
161 %
162 %\subsection*{Message options}
163 %
164 %The following options modify how the
165 %\begin{description}
166 % \item[\texttt{message=\emph{string}}] Sets the message shown when proofs are hidden. \\
167 % Default: \verb|Proof hidden.|
168 % \item[\texttt{color=\emph{name}}] Sets the color of the message if the \texttt{color} package is loaded.
169 % This option has no effect if the `color` package is not loaded. \\
170 % Default: \verb|blue|.
171 %\end{description}
172 %
173 %\subsection{Optional Environment Argument}
174 %
175 %The \verb|proof*| environment supports an optional title, just like \verb|proof| to change the rendered text from ``Proof.'':
176 %\begin{lstlisting}[language=TeX]
177 %\begin{proof*}[Sketch of proof]
178 %This sketch will be hidden in draft mode.
179 %\end{proof*}
180 %\end{lstlisting}
181 %
182 %\subsection*{Example}
183 %
184 %Consider the following example:
185 %
186 %\begin{lstlisting}[language=TeX]
187 %\documentclass{article}
188 %\usepackage{hideproofs}
189 %\usepackage{color}
190 %
191 %\begin{document}
192 %
193 % \begin{proof}
194 % This is a non-starred proof environment.
195 % \end{proof}
196 %
197 % \begin{proof*}
198 % This is a starred proof environment.
199 % \end{proof*}
200 %
201 % \begin{proof*}[Proof sketch]
202 % This is a starred proof environment with an optional argument.
203 % \end{proof*}
204 %
205 %
206 %\end{lstlisting}
207 %% \makeatletter
208 % % \hideproofs@setDefaults{}%
209 % % \hideproofs@newSetup{
210 % % hideInFinal=true,
211 % % message={Proof omitted.},
212 % % color=red
213 % % }%
214 %% \makeatother
215 %The output is \\[10pt]
216 %\fbox{%
217 % \begin{minipage}{0.8\linewidth}
218 % \begin{proof}
219 % This is a non-starred proof environment.
220 % \end{proof}
221 % \begin{proof*}
222 % This is a starred proof environment.
223 % \end{proof*}
224 % \begin{proof*}[Proof sketch]
225 % This is a starred proof environment with an optional argument.
226 % \end{proof*}
227 % \end{minipage}
228 %} \\[10pt]
229 %(If the \texttt{color} package is not loaded, then the message text is black.)
230 %
231 %\makeatletter
232 % \hideproofs@newSetup{show}
233 %\makeatother
234 %Changing the document class options to
235 %\begin{lstlisting}[language=TeX]
236 %\documentclass[final]{article}
237 %\end{lstlisting}
238 %produces \\[10pt]
239 %\fbox{%
240 % \begin{minipage}{0.8\linewidth}
241 % \begin{proof}
242 % This is a non-starred proof environment.
243 % \end{proof}
244 % \begin{proof*}
245 % This is a starred proof environment.
246 % \end{proof*}
247 % \begin{proof*}[Proof sketch]
248 % This is a starred proof environment with an optional argument.
249 % \end{proof*}
250 % \end{minipage}
251 %}
252 %
253 %% \subsection*{Example: Custom Message}
254 %\makeatletter
255 % \hideproofs@setDefaults{}
256 % \hideproofs@newSetup{
257 % message={Proof omitted.},
258 % color=red
259 % }
260 %\makeatother
261 %The appearance of the ``proof hidden" text can be changed by setting the \texttt{message} and \texttt{color} options:
262 %\begin{lstlisting}[language=TeX]
263 %\usepackage[
264 % message={Proof omitted.},
265 % color=red
266 %]{hideproofs}
267 %\end{lstlisting}
268 %Note that the \texttt{message} string must be wrapped in brackets if it contains spaces.
269 %The result is \\[10pt]
270 %\fbox{%
271 % \begin{minipage}{0.8\linewidth}
272 % \begin{proof}
273 % This is a non-starred proof environment.
274 % \end{proof}
275 % \begin{proof*}
276 % This is a starred proof environment.
277 % \end{proof*}
278 % \begin{proof*}[Proof sketch]
279 % This is a starred proof environment with an optional argument.
280 % \end{proof*}
281 % \end{minipage}
282 %}
283 %
284 %% \subsection*{Example: Changing when proofs are hidden}
285 %
286 %
287 %% \begin{lstlisting}[language=TeX]
288 %% \usepackage[
289 %% hideInFinal=true,
290 %% message={Proof omitted.},
291 %% color=gray
292 %% ]{hideproofs}
293 %% \begin{lstlisting}[language=TeX]
294 %% \usepackage[
295 %% hideInFinal=true,
296 %% message={Proof omitted.},
297 %% color=gray
298 %% ]{hideproofs}
299 %% \end{lstlisting}
300 %
301 %% The ouput
302 %%
303 %% \makeatletter
304 %% \hideproofs@newSetup{
305 %% hideInFinal=true,
306 %% message={Proof omitted.},
307 %% color=red
308 %% }
309 %% \makeatother
310 %% \begin{proof*}
311 %% This is a proof
312 %% \end{proof*}
313 %
314 %
315 %\section{License}
316 %
317 %This package is released under the \LaTeX\ Project Public License, which is distributed from CTAN archives in the directory macros/latex/base/lppl.txt.
318 %
319 %\section{Author}
320 %
321 %Paul Wintz (\href{https://paulwintz.com/}{paulwintz.com}) \\
322 %PhD Student, UC Santa Cruz, Department of Applied Mathematics \\
323 %\\
324 %
325 %
326 %
327 %
328 %\StopEventually{}
329 %\section{The Code}
330 %\iffalse
331 % \begin{macrocode}
332 %<*hideproofs.sty>
333 % \end{macrocode}
334 %\fi
335 % hideproofs - Define a starred proof environment "proof*" that hides contents when document is not "final".
336 %
337 % (c) 2025 - Paul Wintz
338 %
339 %% This program can be redistributed and/or modified under the terms
340 %% of the LaTeX Project Public License Distributed from CTAN archives
341 %% in directory macros/latex/base/lppl.txt.
342 %
343 % Disable LTeX for this file (https://valentjn.github.io/ltex/advanced-usage.html#magic-comments)
344 % LTeX: enabled=false
345 \NeedsTeXFormat{LaTeX2e}
346 \ProvidesPackage{hideproofs}
347 [2025/06/15 v1.0 Define a starred proof environment "proof*" that hides contents when document is not "final".]
348
349 \RequirePackage{amsthm}
350 \RequirePackage{ifdraft} % Provides ifoptionfinal.
351 \RequirePackage{environ} % Provides \NewEnviron.
352 \RequirePackage{ifthen} % Provides conditionals.
353
354 % Create a boolean that we set to true if proofs should be hidden.
355 \newboolean{hideproofs@hideProofs}
356 \setboolean{hideproofs@hideProofs}{false}
357
358 \RequirePackage{expl3}
359 \RequirePackage{l3keys2e}% To use \keys_define in LaTeX2e
360 \ExplSyntaxOn % Enable LaTeX3 Programming layer
361
362 % Create booleans loaded from options
363 \bool_new:N \l__hideproofs_hide_in_default_mode_bool
364 \bool_new:N \l__hideproofs_hide_in_draft_mode_bool
365 \bool_new:N \l__hideproofs_hide_in_final_mode_bool
366 \bool_new:N \l__hideproofs_force_show_bool
367 \bool_new:N \l__hideproofs_force_hide_bool
368
369 % Set defaults
370
371 \newcommand{\hideproofs@setDefaults}{%
372 \cs_set:Npn \hideproofs@message {Proof~hidden.}
373 \cs_set:Npn \hideproofs@color {blue}
374 \bool_set:Nn \l__hideproofs_hide_in_draft_mode_bool { \c_true_bool }
375 \bool_set:Nn \l__hideproofs_hide_in_default_mode_bool { \c_true_bool }
376 \bool_set:Nn \l__hideproofs_hide_in_final_mode_bool { \c_false_bool }
377 \bool_set:Nn \l__hideproofs_force_show_bool { \c_false_bool }
378 \bool_set:Nn \l__hideproofs_force_hide_bool { \c_false_bool }
379 }
380 \hideproofs@setDefaults{}
381
382 \newcommand{\hideproofs@newSetup}[1]{
383 \hideproofs@setDefaults{}
384 \keys_set:nn { hideproofs }
385 {
386 #1
387 }
388 % After changing the setup, we need to update \hideproofs@hideProofs.
389 \hideproofs@updateHideProofs{}
390 }
391
392 \newcommand{\hideproofs@updateHideProofs}{
393 % ╭─────────────────────────────────────────────────────────────────────────────────────────────────────╮
394 % │ Enable hidden proofs if any of the current mode is marked for hiding proofs │
395 % ╰─────────────────────────────────────────────────────────────────────────────────────────────────────╯
396
397 % Reset hideproofs@hideProofs to false, in case it was previously set to true.
398 \setboolean{hideproofs@hideProofs}{false}
399
400 \bool_if:nT {\l__hideproofs_hide_in_draft_mode_bool && \l__mode_draft_bool}{
401 \setboolean{hideproofs@hideProofs}{true}
402 }
403 \bool_if:nT {\l__hideproofs_hide_in_final_mode_bool && \l__mode_final_bool}{
404 \setboolean{hideproofs@hideProofs}{true}
405 }
406 \bool_if:nT {\l__hideproofs_hide_in_default_mode_bool && (!\l__mode_draft_bool && !\l__mode_final_bool)} {
407 \setboolean{hideproofs@hideProofs}{true}
408 }
409 \bool_if:nT {\l__hideproofs_force_show_bool} {
410 \setboolean{hideproofs@hideProofs}{false}
411 }
412 \bool_if:nT {\l__hideproofs_force_hide_bool} {
413 \setboolean{hideproofs@hideProofs}{true}
414 }
415
416 }
417
418 % Declare boolean calculated from the package options and document options
419 \bool_new:N \l__hide_proofs
420
421 % ╭───────────────────────────────────────────────────────────────────╮
422 % │ Define key-value options for the package. │
423 % ╰───────────────────────────────────────────────────────────────────╯
424 \keys_define:nn { hideproofs }{% Key-value list
425
426 % ───── Define Boolean Key-Value Option: "show" ─────
427 % Description: Override any automatic hiding or showing that is based on the document mode.
428 % Instead, always show the proofs.
429 show .bool_set:N = {\l__hideproofs_force_show_bool},
430
431 % ───── Define Boolean Key-Value Option: "hide" ─────
432 % Description: Override any automatic hiding or showing that is based on the document mode.
433 % Instead, always hide the proofs.
434 hide .bool_set:N = {\l__hideproofs_force_hide_bool},
435
436 % ───── Define String Key-Value Option: "message" ─────
437 % Description: Set the message that is shown when a proof is hidden.
438 message .str_set:N = {\hideproofs@message},
439
440 % ───── Define String Key-Value Option: "color" ─────
441 % Description: Set the color of the message when a proof is hidden.
442 color .str_set:N = {\hideproofs@color},
443
444 % ───── Define Boolean Key-Value Option: "hideInDefault" ─────
445 % Description: Hide proofs if the document mode is default (neither draft nor final)
446 hideInDefault .bool_set:N = {\l__hideproofs_hide_in_default_mode_bool},
447
448 % % ───── Define Negated Boolean Key-Value Option: "showInDefault" ─────
449 % % Description: Show proofs if the document mode is default (neither draft nor final)
450 % showInDefault .bool_set_inverse:N = {\l__hideproofs_hide_in_default_mode_bool},
451
452 % ───── Define Boolean Key-Value Option: "hideInDraft" ─────
453 % Description: Hide proofs if the document mode is draft
454 hideInDraft .bool_set:N = {\l__hideproofs_hide_in_draft_mode_bool},
455
456 % % ───── Define Negated Boolean Key-Value Option: "showInDraft" ─────
457 % % Description: Show proofs if the document mode is draft
458 % showInDraft .bool_set_inverse:N = {\l__hideproofs_hide_in_draft_mode_bool},
459
460 % ───── Define Boolean Key-Value Option: "hideInFinal" ─────
461 % Description: Hide proofs if the document mode is final
462 hideInFinal .bool_set:N = {\l__hideproofs_hide_in_final_mode_bool},
463
464 % % ───── Define Negated Boolean Key-Value Option: "showInFinal" ─────
465 % % Description: Show proofs if the document mode is final
466 % showInFinal .bool_set_inverse:N = {\l__hideproofs_hide_in_final_mode_bool}
467 }
468 \ProcessKeysOptions { hideproofs }
469
470 % ╭───────────────────────────────────────────────────────────────────────────────╮
471 % │ Create LaTeX3 booleans for draft mode and final mode. │
472 % ╰───────────────────────────────────────────────────────────────────────────────╯
473 \bool_new:N \l__mode_draft_bool
474 \bool_new:N \l__mode_final_bool
475 % Set the booleans based on the whether in draft mode or final mode.
476 \ifoptiondraft{
477 \bool_set_true:N \l__mode_draft_bool
478 }{
479 \bool_set_false:N \l__mode_draft_bool
480 }%
481 \ifoptionfinal{
482 \bool_set_true:N \l__mode_final_bool
483 }{
484 \bool_set_false:N \l__mode_final_bool
485 }
486
487 % Update \hideproofs@hideProofs based on the options and document mode.
488 \hideproofs@updateHideProofs{}
489
490 \ExplSyntaxOff% Disable LaTeX3 Programming layer
491
492
493 % ╭─────────────────────────────────────────────────╮
494 % │ Hide Proof Environment │
495 % ╰─────────────────────────────────────────────────╯
496 \NewEnviron{proof*}[1][]{%
497 % ⋘────────── Open Proof ──────────⋙
498 % If optional argument is not given, then don't give proof an optional argument (o/w it would result in an empty string instead of "proof")
499 \ifthenelse{ \equal{#1}{} }{% If optional argument is not given...
500 % ...then open the proof without optional argument.
501 \begin{proof}%
502 }{% If an optional argumnet is given...
503 % ...then open the proof with the optional argument.
504 \begin{proof}[#1]%
505 }%
506 %
507 % ⋘────────── Proof body ──────────⋙
508 \ifthenelse{\boolean{hideproofs@hideProofs}}{% If hideproofs@hideProofs is true...
509 {% Start color block
510 \@ifpackageloaded{color}{% If color package...
511 \color{\hideproofs@color}% Set color
512 }{}%
513 % Insert the message for the hidden proof.
514 \hideproofs@message
515 }% End color block
516 }{% If hideproofs@hideProofs is false
517 % Insert the actual proof.
518 \BODY%
519 }%
520 %
521 % ⋘────────── Close proof ──────────⋙
522 \end{proof}%
523 }
524
525 \endinput% Stop input here when this file is loaded.
526 %%
527 %% End of file `hideproofs.sty'.%\iffalse
528 % \begin{macrocode}
529 %</hideproofs.sty>
530 % \end{macrocode}
531 %\fi
532 %\Finale
533 \endinput