-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsecretx.dtx
1369 lines (1352 loc) · 46.3 KB
/
secretx.dtx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% \iffalse meta-comment
%
% Copyright (c) 2019-2024 by Keith F. Prussing <[email protected]>
%
% This work may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, either version 1.3c of this license
% or (at your option) any later version. The latest version of this
% license is in
%
% http://www.latex-project.org/lppl.txt
%
% and version 1.3c or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Keith F. Prussing.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{\jobname.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}[2003/12/01]
%<package>\ProvidesPackage{secretx}
%<package>[2024/03/07 v0.10.9 Classification marking macros]
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{hypdoc}
\usepackage{secretx}
\fancyhead[L,C,R]{}
\fancyfoot[C]{}
\fancyfoot[R]{\thepage}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\usepackage{hologo}
\usepackage{listings}
\usepackage{mwe}
\newtcolorbox{notice}{colback=red!5!white,colframe=red!75!black,%
fonttitle=\bfseries,title={Notice}}
\setcounter{IndexColumns}{2}
\IndexPrologue{\section{Index}}
\GlossaryPrologue{\section{Change History}}
\usepackage[style=ieee]{biblatex}
\addbibresource{secretx.bib}
\usepackage{cleveref}
% Command for <barg>
\newcommand\barg[1]{{\ttfamily<}\meta{#1}{\ttfamily>}}
\tcbuselibrary{listings}
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{305}
%
% \CharacterTable
% {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
% 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
% Digits \0\1\2\3\4\5\6\7\8\9
% Exclamation \! Double quote \" Hash (number) \#
% Dollar \$ Percent \% Ampersand \&
% Acute accent \' Left paren \( Right paren \)
% Asterisk \* Plus \+ Comma \,
% Minus \- Point \. Solidus \/
% Colon \: Semicolon \; Less than \<
% Equals \= Greater than \> Question mark \?
% Commercial at \@ Left bracket \[ Backslash \\
% Right bracket \] Circumflex \^ Underscore \_
% Grave accent \` Left brace \{ Vertical bar \|
% Right brace \} Tilde \~}
%
% \changes{v0.5}{2019/04/24}{Initial version}
% \changes{v0.6}{2019/04/27}{Implementation reorganization}
% \changes{v0.7}{2019/04/27}{Correctly roll over marking level}
% \changes{v0.8}{2019/05/03}{Consolidate macros}
% \changes{v0.8.5}{2019/05/11}{Add explicit environments}
% \changes{v0.8.6}{2019/05/11}{Make all new commands robust}
% \changes{v0.9.0}{2020/09/16}{Provide manual heading override}
% \changes{v0.10}{2021/03/13}{Move development to trunk branch}
% \GetFileInfo{\jobname.sty}
%
%^^A Package macros
% \DoNotIndex{\begin, \end, \newenvironment, \newrobustcmd, \renewcommand}
% \DoNotIndex{\csdef, \csuse, \ifcsdef, \if, \else, \fi, \everypar}
% \DoNotIndex{\iftoggle, \ifnum, \toggletrue, \togglefalse, \thepage}
% \DoNotIndex{\newcounter, \newtoggle, \setcounter, \stepcounter}
% \DoNotIndex{\PackageError, \RequirePackage, \PackageWarning, \llap}
% \DoNotIndex{\box, \setbox}
% \DoNotIndex{\protect, \makebox, \parindent, \PushPostHook, \aftergroup}
% \DoNotIndex{\bgroup, \egroup, \@ifclassloaded, \centering, \kern}
% \DoNotIndex{\hfill, \null, \edef, \vspace, \setlist, \Large, \bfseries}
% \DoNotIndex{\space, \@ifpackageloaded, \fancyfoot, \fancyhead}
% \DoNotIndex{\fancypagestyle, \fbox, \ifcsempty, \ifdefstring}
% \DoNotIndex{\ifnumgreater, \IfValueTF, \lastbox, \leavevmode}
% \DoNotIndex{\leftmargin, \MessageBreak, \NewDocumentCommand}
% \DoNotIndex{\NewTColorBox, \PushPreHook, \tcbset, \tcbtitle}
% \DoNotIndex{\textwidth, \value, \usebeamerfont}
%^^A Other package macros
% \DoNotIndex{\AtBeginShipout}
% \DoNotIndex{\lhead, \chead, \rhead, \lfoot, \cfoot, \rfoot, \fancyhf}
% \DoNotIndex{\headerrulewidth, \pagestyle, \thispagestyle}
% \DoNotIndex{\zref, \zref@extract, \zlabel, \defbeamertemplate}
% \DoNotIndex{\BODY, \NewEnviron, \userbeamerfont, \setbeamerfont}
% \DoNotIndex{\ifdefempty, \DeclareStringOption, \ProcessKeyvalOptions}
% \DoNotIndex{\AtBeginEnvironment, \AtEndEnvironment}
%^^A Package specific to ignore
% \DoNotIndex{\thesecretx@doclevel, \thesecretx@pagelevel, \reset}
% \DoNotIndex{\thesecretx@markcount, \thesecretx@currentlevel, \curcnt}
%^^A Writing to the aux file macros
% \DoNotIndex{\@auxout, \immediate, \\, \AtEndDocument, \write, \string}
% \DoNotIndex{\space}
%
% \title{
% Classification Marking Macros for \LaTeX{} \thanks{This document
% corresponds to \textsf{\jobname}~\fileversion, % dated~\filedate.}
% }
%
% \author{Keith F. Prussing \\ \texttt{[email protected]}}
%
% \maketitle
% \tableofcontents
% \thispagestyle{secretx}
%
% \begin{abstract}
% This package provides a set of \LaTeX{} macros for marking paragraphs
% in a document with a leading string and modifying the header and the
% footer of each page. This is the spiritual successor to
% \textsf{secret.sty} but adds the feature of marking the header and the
% footer correctly.
% \end{abstract}
%
% \section{Introduction}
%
% A core component of reporting sensitive information is properly
% marking sections of a document with appropriate labels. This package
% aims to provide tools for helping mark a document correctly.
%
% \section{Usage}
% \changes{v0.7.1}{2019/04/28}{Expand usage documentation}
%
% To install the package, simply run the provided |secretx.ins| file
% through your preferred \LaTeX{} engine. Then, copy the resultant
% |.sty| file to a location where \LaTeX{} can find it. To generate
% the documentation, run this file (|secretx.dtx|) through \LaTeX{}
% twice. The second time is only to make sure the references and index
% are typeset correctly. If you have \hologo{LuaLaTeX}, you could also
% run |l3build install| to install into your local texmf tree and
% |l3build doc| to get a quick version of the documentation.
%
% \Cref{app:example} provides an example document and \textsf{beamer}
% presentation showing the usage of the package. The raw source is also
% provided in the \textsf{doc} directory with this reference. To see
% the typeset result, simply run the example files through \LaTeX{}.
%
% \subsection{Marking Management}
%
% The basic concept behind marking each page is setting a ``level'' for
% each paragraph. The highest level paragraph on any given page sets
% the overall level of the page in a standard document. Before use, the
% user must specify every desired marking level along with paragraph and
% header markings. The header and footer markings are set with a
% \textsf{fancyhdr} |\pagestyle| which is activated by default for
% non-\textsf{beamer} documents.
%
% To apply headers and footers to \textsf{beamer} slides, use
% \begin{lstlisting}[gobble=2, basicstyle=\ttfamily\small]
% \usebeamertemplate{headline}[secretx]
% \usebeamertemplate{footline}[secretx]
% \end{lstlisting}
% or simply use |\getheading| in your custom \textsf{headline} and
% \textsf{footline}. Additionally, the \textsf{headline} and
% \textsf{footline} themes accept an optional argument. If this matches
% the string ``title'', the overall document banner is typeset instead
% of the individual page banner.
%
% \DescribeMacro{\setmarking}
% \DescribeMacro{\setheading}
% To register a paragraph marking, use
% |\setmarking|\marg{level}\marg{marking}. Likewise, to register a
% heading use |\setheading|\marg{level}\marg{heading}. These marcos
% register a \marg{marking} or \marg{heading} at the specified
% \marg{level}. The user is responsible for making sure the marker and
% heading for given level are consistent. Providing a level more than
% once will simply overwrite the previous definition with no warning.
%
% \DescribeMacro{\addmarking}
% |\addmarking|\marg{level}\marg{marking}\marg{heading} will set the
% marking and heading at the given level. This is simply a convenience
% wrapper around |\setmarking| and |\setheading|.
%
% \DescribeMacro{\getmarking}
% \DescribeMacro{\getheading}
% \changes{v0.8.4}{2019/05/11}{Use current level as default marking}
% Once a level has been registered, retrieving the marking or heading is
% done with |\getmarking|\oarg{level} or |\getheading|\oarg{level}
% respectively. The argument defaults to the current paragraph or page
% level as appropriate. These macros check that the given \oarg{level}
% has a defined marking and heading. If not, these will raise an error.
% These return the expanded string given to |\setmarking| and
% |\setheading|.
%
% \DescribeMacro{\pagelevel}
% \DescribeMacro{\doclevel}
% These provide access to the current page and document levels. These
% are read only and are provided to reveal the current state for the
% user instead of having to work with the package internals.
%
% \DescribeMacro{\pagestyle\{secretx\}}
% \changes{v0.10}{2022/03/11}{Define fancyhdr page style}
% This pagestyle places the appropriate header and footer page marking
% in the center of the header and footer. It changes no other parts of
% the header or footer. This is loaded by default; however, it is
% ultimately the users responsibility to ensure this is loaded at the
% appropriate time or that other header/footer customizations do not
% overwrite the center portion of either the header or footer. If you
% need to have a highly customized header or footer, simply add
% |\getheading| to the appropriate portion of your header or footer.
%
% \subsection{Document Marking}
%
% \DescribeMacro{\marking}
% Marking a paragraph is done by specifying the numeric level with which
% to mark using |\marking|\marg{level}\{\ldots\}. This macro takes care
% of marking the paragraph with the appropriate marker and updating the
% page and document levels. The page and document levels are only
% updated if the given marking is higher than the current level.
%
% \DescribeEnv{marking block}
% Collecting large bodies of text into a macro is not ideal. Instead,
% we would like to use an environment. To this end, this package
% provides the |marking block| environment. The syntax is analogous to
% the |\marking| macro in that it takes a \marg{level}. For example:
% \begin{lstlisting}[gobble=2, basicstyle=\ttfamily\small]
% \begin{marking block}{1}
% \ldots
% \end{marking block}
% \end{lstlisting}
%
%
% \DescribeEnv{marking box}
% \changes{v0.11}{2024/02/28}{Add marking box environment}
% Graphical or tabular content can be wrapped in a |tcolorbox| to
% indicate the marking level of the entire content. The |marking box|
% environment will wrap the item in a colored box and place the heading
% in the upper left and lower right corners of the box in the same color
% as the box. The environment accepts the following options:
%
% \begin{enumerate}
% \item \marg{level}: The level of the marking
% \item \barg{top sep}: The additional separation above the content
% \item \barg{bottom sep}: The additional separation below the content
% \item \oarg{options}: Additional options passed to |tcolorbox|
% \end{enumerate}
%
% Under the hood, this is a |tcolorbox| customized with the |secretx|
% style.
%
% \iffalse
%<*driver>
% \fi
\begin{tcblisting}{listing outside text}
\setheading{1}{Marking}
\begin{marking box}{1}
\includegraphics%
[width=\textwidth]%
{example-image-a}
\end{marking box}
\end{tcblisting}
% \iffalse
%</driver>
% \fi
%
% For convenience, we provide definitions to set common levels. The
% styles and colors listed are used with |marking box| and may be
% customized as described in the documentation for |tcolorbox|. These
% are:
%
% \DescribeMacro{\unclassified}
% \DescribeEnv{unclassified block}
% \DescribeEnv{unclassified box}
% \DescribeMacro{unclassified style}
% \DescribeMacro{unclassified/color}
% Mark unclassified.
% \begin{itemize}
% \item Level: 1
% \item Marking: \getmarking[1]
% \item Heading: \getheading[1]
% \end{itemize}
%
% \DescribeMacro{\fouo}
% \DescribeEnv{fouo block}
% Mark for official use only.
% \begin{notice}
% The FOUO marking is deprecated. This will be removed in version 0.11.
% \end{notice}
% \begin{itemize}
% \item Level: 2
% \item Marking: \getmarking[2]
% \item Heading: \getheading[2]
% \end{itemize}
%
% \DescribeMacro{\confidential}
% \DescribeEnv{confidential block}
% \DescribeEnv{confidential box}
% \DescribeMacro{confidential style}
% \DescribeMacro{confidential/color}
% Mark confidential.
% \begin{itemize}
% \item Level: 5
% \item Marking: \getmarking[5]
% \item Heading: \getheading[5]
% \end{itemize}
%
% \DescribeMacro{\secret}
% \DescribeEnv{secret block}
% \DescribeEnv{secret box}
% \DescribeMacro{secret style}
% \DescribeMacro{secret/color}
% Mark secret.
% \begin{itemize}
% \item Level: 10
% \item Marking: \getmarking[10]
% \item Heading: \getheading[10]
% \end{itemize}
%
% \DescribeMacro{\secretnoforn}
% \DescribeEnv{secretnoforn block}
% \DescribeEnv{secretnoforn box}
% \DescribeMacro{secretnoforn style}
% \DescribeMacro{secretnoforn/color}
% Mark secret no foreign.
% \begin{itemize}
% \item Level: 15
% \item Marking: \getmarking[15]
% \item Heading: \getheading[15]
% \end{itemize}
%
% \DescribeMacro{\topsecret}
% \DescribeEnv{topsecret block}
% \DescribeEnv{topsecret box}
% \DescribeMacro{topsecret style}
% \DescribeMacro{topsecret/color}
% Mark top secret.
% \begin{itemize}
% \item Level: 25
% \item Marking: \getmarking[25]
% \item Heading: \getheading[25]
% \end{itemize}
%
% \subsection{Overriding the Default Page Marking}
%
% \begin{notice}
% Version 0.11 will change the meaning of this option as the internal
% logic is still buggy. After 0.11, |heading| will \emph{enable} the
% adaptive marking.
% \end{notice}
%
% \DescribeMacro{heading}
% \changes{v0.10}{2022/03/10}{Allow default behavior of header}
% Although this package attempts to automate away many of the underlying
% details of marking a document, it cannot always succeed. Since it is
% the final responsibility of the document author to ensure appropriate
% overall markings, the |heading| argument to the package provides
% a manual override to the package determined page marking per the
% alternate marking advice in \cite{noauthor_marking_2021}. This
% option can be given alone or assigned as a string |heading=<text>|.
% If a string is given, the text is typeset in the header and footer
% verbatim. If the text is not given, the highest header marking of the
% document will be used for the header and footer. The header and
% footers will be the same on all pages in the document.
%
% If possible, we would appreciate any representative examples of usages
% that fails to get marked correctly reported to the
% \href{https://github.com/kprussing/secretx/issues}{issue tracker}.
% However, due to the intended use of this package, we understand if
% this is not practical.
%
% \DescribeMacro{\setlevel}
% \changes{v0.10}{2021/08/17}{Add setlevel command}
% This macro explicitly sets the level of a page without marking a
% particular item. The focus of this is more for a class like
% \textsf{beamer} where the slide may be composed solely of images
% that are themselves marked but are unknown to \LaTeX{}, or floating
% environment such as |figure| or |table|. This lets the user
% explicitly state the classification of the proper page or scope.
%
% \subsection{Additional Statements}
%
% \DescribeMacro{\distribution}
% A distribution statement is a common need for documentation. Using
% |\distribution| \marg{level}\marg{reason}\marg{date of
% determination}\marg{controlling DoD office} will place the appropriate
% distribution statement following DoDI 5230.24\cite{dodi_5230.24}.
% Here \marg{level} is the letter version of the statement (A, B, C, D,
% etc.).
%
% \DescribeMacro{\exportcontrol}
% This macro places the export control warning in a framed box at the
% current location in accordance with DoDI 5230.24\cite{dodi_5230.24}.
% The default is to typeset the box at 90\% of the |\textwidth|. Using
% |\exportcontrol|\oarg{width} typesets the control statement in a box
% of the given \oarg{width}.
%
% \section{Tips and Tricks}
%
% A few items must be kept in mind while using this package.
% Specifically, this package makes use of \textsf{everyhook} to
% manipulate the |\everypar| hook. As noted
% online\footnote{\url{https://tex.stackexchange.com/q/263744/61112}},
% \LaTeX{} makes extensive use of |\everypar| in many unexpected places.
% From a practical point of view, the following sections point out best
% practices.
%
% \subsection{Do Not Span Sections}
%
% A marking environment should not span a sectioning command. If the
% document contains:
%
% \begin{lstlisting}[gobble=2, basicstyle=\ttfamily\small]
% \begin{unclassified block}
% \lipsum[1]
%
% \chapter{The Next Chapter}
%
% \lipsum[2]
% \end{unclassified block}
% \end{lstlisting}
%
% the marking will be placed in the margin next to the chapter and not
% associated with the chapter text. Instead, use
%
% \begin{lstlisting}[gobble=2, basicstyle=\ttfamily\small]
% \unclassified{\lipsum[1]}
%
% \chapter{\getmarking[1]\setlevel{1} The Next Chapter}
%
% \unclassified{\lipsum[2]}
% \end{lstlisting}
%
% This will set the level, correctly associate the marking with the
% chapter title, and place it in the table of contents. To silence the
% warning from \textsf{hyperref}, place the macros in the \TeX{} portion
% of |\texorpdfstring|.
%
% \subsection{Do Not Wrap Floats}
%
% Similar to sectioning commands, placing floating environments within a
% marking block has negative consequences. When the floating
% environment is placed, it will have the marking in the margin.
% Instead, explicitly set the level within the floating environment and
% get the marking for the caption.
%
% \begin{lstlisting}[gobble=2, basicstyle=\ttfamily\small]
% \end{unclassified block}
%
% \begin{figure}
% \begin{secret box}
% \includegraphics{example-image-16x10}
% \end{secret box}
% \caption{\getmarking[1] Different level caption.}
% \end{figure}
%
% \begin{unclassified block}
% \end{lstlisting}
%
% \subsection{Marking Front Matter Titles}
%
% Markings can be added to the table of contents, list of figures, and
% list of tables titles using |\preto| from \textsf{etoolbox} (which is
% loaded by this package).
%
% \begin{lstlisting}[gobble=2, basicstyle=\ttfamily\small]
% \AtBeginDocument{%
% \preto\contentsname{\setlevel{1}\getmarking[1] }
% \preto\listfigurename{\setlevel{1}\getmarking[1] }
% \preto\listtablename{\setlevel{1}\getmarking[1] }
% }
% \end{lstlisting}
%
% \subsection{Marking List of Acronyms from \textsf{Acro}}
%
% The list of acronyms can be placed in a marking environment by
% redefining the template according to example
% 8\footnote{acro.example.texsx-505891} from the \textsf{acro}
% documentation.
%
% \begin{lstlisting}[gobble=2, basicstyle=\ttfamily\small]
% \RenewAcroTemplate[list]{description}{%
% \acroheading
% \acropreamble
% \begin{unclassified block}
% \begin{description}
% \acronymsmapF{
% \item[%
% \acrowrite{short}
% ]
% \acrowrite{list}%
% }
% {\item \AcroRerun}
% \end{description}
% \end{unclassified block}
% }
%
% \prinacronyms[name={\getmarking[1] \acrotranslate{list-name}}]
% \end{lstlisting}
%
% \subsection{Adjusting Boxed Environments}
%
% As mentioned, the |marking box| environment relies on |tcolorbox| with
% the custom |secretx| style. You may change the defaults using
% |\tcbset|. The following sets all marked box titles to be bold and to
% use a dark green to mark unclassified boxed content.
%
% \begin{lstlisting}[gobble=2, basicstyle=\ttfamily\small]
% \tcbset{secretx/.append style={fonttitle=\bfseries},
% unclassified/color/.default=green!50!black,
% }
% \end{lstlisting}
%
% \StopEventually{
% \printbibliography[heading=bibnumbered]
% \PrintChanges{}
% \PrintIndex{}
% }
%
% \section{Implementation}
%
% \iffalse
%<*package>
% \fi
%
% The basic logic is to define markings with increasing levels of
% sensitivity. We track these along with paired line markings and page
% markings in internal arrays.
%
% \subsection{Required Packages}
%
% For this package, we will need to modify the shipout, work with
% counters, control sequences, complex labels, and we will, obviously,
% need to modify the headers and footers. We add all of the packages in
% one location to keep things organized.
%
% \begin{macrocode}
\RequirePackage{atbegshi}
\RequirePackage{etoolbox}
\RequirePackage[excludeor]{everyhook}
\RequirePackage{environ}
\@ifclassloaded{beamer}{}{%
\RequirePackage{fancyhdr}%
}
\RequirePackage{kvoptions}
\RequirePackage{zref-user}
\RequirePackage{zref-abspage}
\@ifpackageloaded{tcolorbox}{}{%
\RequirePackage{tcolorbox}
}
% \end{macrocode}
% |Tcolorbox| moved the |\NewTColorBox| macro from the |xparse| library
% in version 5.1.0. We need to include it for older versions.
% \changes{v0.11}{2024/06/04}{Conditionally load xparse |tcolorbox| library}
% \begin{macrocode}
\@ifpackagelater{tcolorbox}{2022/06/22}{}{\tcbuselibrary{xparse}}
% \end{macrocode}
%
% \subsection{Package Options}
%
% \begin{macro}{\secretx@heading}
% This optional key-value pair is used to induce a manual override of
% page-level headings. All pages will be marked with the indicated
% heading if this option is specified.
% \begin{macrocode}
\DeclareStringOption{heading}[default]
\ProcessKeyvalOptions*
% \end{macrocode}
% \end{macro}
%
% \subsection{Package Counters}
%
% Define the package counters and toggle.
%
% \begin{macro}{secretx@pagelevel}
% A counter to store the marking level of the highest current page.
% \begin{macrocode}
\newcounter{secretx@pagelevel}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{secretx@doclevel}
% A counter to store the highest marking level of the current document.
% We also write out the document marking level to the auxiliary file for
% use on the second pass when creating the cover page.
% \begin{macrocode}
\newcounter{secretx@doclevel}
\AtEndDocument{%
\immediate\write\@auxout{%
\string\setcounter{secretx@doclevel}{\thesecretx@doclevel}%
}
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{secretx@currentlevel}
% A counter to maintain the marking level of the current scope.
% \begin{macrocode}
\newcounter{secretx@currentlevel}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{secretx@markcount}
% A counter for the classification environment.
% \begin{macrocode}
\newcounter{secretx@markcount}
% \end{macrocode}
% \end{macro}
%
% \subsection{Marking and Heading Management}
%
% These are the user facing macros for establishing the markings and
% headings. These automate away the tasks of storing the information at
% increasing levels and validating the levels when getting a marking or
% heading from the internal storage. When setting the marking or
% heading, we simply overwrite any previous value. It is up to the user
% to ensure the markings and headings are set at consistent levels. For
% this, we also provide a utility macro for setting both simultaneously.
%
% \begin{macro}{\setmarking}
% Set a marking level by defining the level and a line marking (e.g. (U)
% for unclassified, (S) for secret, etc.). This will overwrite a
% previously defined marking at the same level.
% \begin{macrocode}
\newrobustcmd{\setmarking}[2]{\csdef{secretx@marking#1}{#2}}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\getmarking}
% Get a line marking from the marking storage.
% \begin{macrocode}
\newrobustcmd{\getmarking}[1][\thesecretx@currentlevel]{%
\ifcsdef{secretx@marking#1}{%
\csuse{secretx@marking#1}%
}{%
\PackageWarning{secretx}{%
Marking ##1 level was not previously defined. Is it a typo
or did you simply forget to define it?%
}
}
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\setheading}
% Set the heading level by defining the level and the heading (e.g.
% UNCLASSIFIED, SECRET, etc.). This will overwrite a previously defined
% marking at the given level.
% \begin{macrocode}
\newrobustcmd{\setheading}[2]{\csdef{secretx@heading#1}{#2}}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\getheading}
% \changes{v0.11}{2023/05/23}{Get specific heading when given level}
% Get the heading on the page. Use the current page level unless the
% |heading| option was specified. If it was, always use it.
% \begin{macrocode}
\NewDocumentCommand{\getheading}{ o }{%
\IfValueTF{#1}{%
\ifcsdef{secretx@heading#1}{%
\csuse{secretx@heading#1}%
}{%
\PackageError{secretx}{Undefined heading level}{%
Marking ##1 level was not previously defined. Is it a
typo or did you simply forget to define it?%
}%
}%
}{%
\ifdefempty{\secretx@heading}{%
\csuse{secretx@heading\thesecretx@pagelevel}%
}{%
\ifdefstring{\secretx@heading}{default}{%
% \end{macrocode}
%^^A This should not be possible because the level was checked when
%^^A getting the marking.
% \begin{macrocode}
\csuse{secretx@heading\doclevel}%
}{%
\csuse{secretx@heading}%
}%
}
}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\addmarking}
% A helper macro to set a marking's level, section marking, and header
% marking.
% \begin{macrocode}
\newrobustcmd{\addmarking}[3]{%
\setmarking{#1}{#2}%
\setheading{#1}{#3}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\pagelevel}
% \begin{macro}{\doclevel}
% User facing macros to get the current page and document marking level.
% \begin{macrocode}
\newrobustcmd{\pagelevel}[0]{\thesecretx@pagelevel}
\newrobustcmd{\doclevel}[0]{\thesecretx@doclevel}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsection{Low Level Macros}
%
% Some low level macros for managing the marking level state.
%
% \begin{macro}{\secretx@updatelevel}
% A macro to update the page and document levels. We only update if the
% given level is higher than the current level. We do this for both the
% page and the document.
% \begin{macrocode}
\newrobustcmd{\secretx@updatelevel}[1]{%
\ifnum#1 > \thesecretx@pagelevel%
\setcounter{secretx@pagelevel}{#1}%
\fi%
\ifnum#1 > \thesecretx@doclevel%
\setcounter{secretx@doclevel}{#1}%
\fi%
}
% \end{macrocode}
% \end{macro}
%
% \subsection{Marking Utilities}
%
% We provide a macro for marking the document. These will handle the
% lower level details of getting the line markings and adjusting the
% details to set the headings. Each one starts by incrementing the
% marking count to track the count of the current environment, creates a
% label, sets the marking for each paragraph, and inserts the content.
% At the end, it sets an ending label.
%
% \begin{macro}{\marking}
% \changes{v0.8.1}{2019/05/10}{Remove nested marking restriction}
% \changes{v0.8.2}{2019/05/10}{Resolve multiply defined labels}
%
% The workhorse macro to actually set the headings and paragraph
% markings. We begin by incrementing the current marking count and
% storing it for later use.
% \begin{macrocode}
\newrobustcmd{\marking}[2]{%
\stepcounter{secretx@markcount}%
\edef\curcnt{\thesecretx@markcount}%
% \end{macrocode}
% Next, in order to correctly reset the level in the case of a nested
% marking, we need to wrap everything up in a group and use
% |\aftergroup|. But, it appears like we need to wrap the counter
% setting in a macro.
% \begin{macrocode}
\edef\reset{%
\setcounter{secretx@currentlevel}{\thesecretx@currentlevel}%
}%
\bgroup%
\aftergroup\reset%
% \end{macrocode}
% Now step the environment counter to track the current environment.
% \begin{macrocode}
\zlabel{secretx@mark-begin-\curcnt}%
\secretx@updatelevel{#1}%
\setcounter{secretx@currentlevel}{#1}%
#2%
% \end{macrocode}
% We finish by marking the ending and releasing the lock.
% \begin{macrocode}
\egroup%
\zlabel{secretx@mark-end-\curcnt}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{environment}{marking block}
% We also provide an environment for marking large bodies of text with a
% common marking.
% \begin{macrocode}
\NewEnviron{marking block}[1]{\marking{#1}{\BODY}}
% \end{macrocode}
% \end{environment}
%
% \subsection{Boxed Environment Marking}
%
% Define a style for creating a color box with level markings in the
% upper left end lower right.
% \begin{macrocode}
\tcbset{%
secretx/.style n args={3}{%
% Basic shape
sharp corners,%
boxrule=1pt,%
boxsep=1pt,%
% The heading
title={\getheading[#1]},%
% Place the heading in the upper left and lower right
detach title,
before upper={\tcbtitle\hfill\null\\[#2]},%
after upper={\leavevmode\\[#3]\null\hfill\tcbtitle},%
% Make the background transparent
standard jigsaw,%
opacityback=0.0,%
% Set the default color of the heading and the frame
secretx/color,
},
secretx/.prefix code={\setlevel{#1}},
% Set the default color of the heading and the frame
secretx/color/.default=black,
secretx/color/.style={/tcb/colframe=#1,,
/tcb/coltitle=#1},
}
% \end{macrocode}
%
% \begin{macro}{marking box}
% Define a new color box that passes the appropriate options to
% |secretx| style.
% \begin{macrocode}
\NewTColorBox{marking box}{m D<>{0pt} D<>{0pt} !O{} }{%
secretx={#1}{#2}{#3},%
% Additional options
#4%
}
% \end{macrocode}
% \end{macro}
%
% \subsection{Specific Markings}
%
% Now we define specific markings for the known classification levels.
% For each, we define an environment and a macro.
%
% An empty default marking.
% \begin{macrocode}
\addmarking{0}{}{}
% \end{macrocode}
%
% \begin{macro}{\unclassified}
% \begin{environment}{unclassified block}
% Unclassified markings.
% \begin{macrocode}
\addmarking{1}{(U)}{Unclassified}
\newrobustcmd{\unclassified}[1]{\marking{1}{#1}}
\NewEnviron{unclassified block}{\unclassified{\BODY}}
\tcbset{unclassified/.style 2 args={secretx={1}{#1}{#2},
unclassified/color},
unclassified/color/.forward to=/tcb/secretx/color}
\NewTColorBox{unclassified box}{D<>{0pt} D<>{0pt} !O{}
}{unclassified={#1}{#2}, #3}
% \end{macrocode}
% \end{environment}
% \end{macro}
%
% \begin{macro}{\fouo}
% \begin{environment}{fouo block}
% \changes{v0.9.1}{2019/09/19}{Fix capitalization}
% For official use only markings.
% \begin{macrocode}
\addmarking{2}{(U//FOUO)}{Unclassified//For Official Use Only}
\newrobustcmd{\fouo}[1]{%
\PackageWarning{secretx}{%
Deprecation warning: Marking FOUO is not correct.\MessageBreak%
Define and use a CUI level instead.\MessageBreak%
This level will be removed in v0.11.\MessageBreak%
}%
\marking{2}{#1}%
}
\NewEnviron{fouo block}{\fouo{\BODY}}
% \end{macrocode}
% \end{environment}
% \end{macro}
%
% \begin{macro}{\confidential}
% \begin{environment}{confidential block}
% Confidential markings.
% \begin{macrocode}
\addmarking{5}{(C)}{Confidential}
\newrobustcmd{\confidential}[1]{\marking{5}{#1}}
\NewEnviron{confidential block}{\confidential{\BODY}}
\tcbset{confidential/.style 2 args={secretx={5}{#1}{#2},
confidential/color},
confidential/color/.forward to=/tcb/secretx/color}
\NewTColorBox{confidential box}{D<>{0pt} D<>{0pt} !O{}
}{confidential={#1}{#2}, #3}
% \end{macrocode}
% \end{environment}
% \end{macro}
%
% \begin{macro}{\secret}
% \begin{environment}{secret block}
% Secret markings.
% \begin{macrocode}
\addmarking{10}{(S)}{Secret}
\newrobustcmd{\secret}[1]{\marking{10}{#1}}
\NewEnviron{secret block}{\secret{\BODY}}
\tcbset{secret/.style 2 args={secretx={10}{#1}{#2},
confidential/color},
secret/color/.forward to=/tcb/secretx/color}
\NewTColorBox{secret box}{D<>{0pt} D<>{0pt} !O{}
}{secret={#1}{#2}, #3}
% \end{macrocode}
% \end{environment}
% \end{macro}
%
% \begin{macro}{\secretnoforn}
% \begin{environment}{secretnoforn block}
% Secret no forn markings.
% \begin{macrocode}
\addmarking{15}{(S//NF)}{Secret//No Forn}
\newrobustcmd{\secretnoforn}[1]{\marking{15}{#1}}
\NewEnviron{secretnoforn block}{\secretnoforn{\BODY}}
\tcbset{secretnoforn/.style 2 args={secretx={15}{#1}{#2},
secretnoforn/color},
secretnoforn/color/.forward to=/tcb/secretx/color}
\NewTColorBox{secretnoforn box}{D<>{0pt} D<>{0pt} !O{}
}{secretnoforn={#1}{#2}, #3}
% \end{macrocode}
% \end{environment}
% \end{macro}
%
% \begin{macro}{\topsecret}
% \begin{environment}{topsecret block}
% Top secret markings.
% \begin{macrocode}
\addmarking{25}{(TS)}{Top Secret}
\newrobustcmd{\topsecret}[1]{\marking{25}{#1}}
\NewEnviron{topsecret block}{\topsecret{\BODY}}
\tcbset{topsecret/.style 2 args={secretx={25}{#1}{#2},
topsecret/color},
topsecret/color/.forward to=/tcb/secretx/color}
\NewTColorBox{topsecret box}{D<>{0pt} D<>{0pt} !O{}
}{topsecret={#1}{#2}, #3}
% \end{macrocode}
% \end{environment}
% \end{macro}
%
% \subsection{Overriding the Default Page Marking}
%
% \begin{macro}{\setlevel}
% This macro provides a user interface to explicitly set the page level.
% It is targeted as \textsf{beamer} frames that are predominantly
% explicitly marked.
% \begin{macrocode}
\newrobustcmd{\setlevel}[1]{%
\secretx@updatelevel{#1}%
}
% \end{macrocode}
% \end{macro}
%
% \subsection{Deprecated Macros}
%
% \begin{notice}
% These macros will be removed in v0.11.
% \end{notice}
% These macros are deprecated and are preserved for temporary backwards
% compatibility. They will be removed in the future.
%
% \begin{macrocode}
\newrobustcmd{\UCL}[1]{%
\PackageWarning{secretx}{Macro deprecated! Use
\protect\unclassified\space instead}%
\unclassified{#1}%
}
\newrobustcmd{\CNF}[1]{%
\PackageWarning{secretx}{Macro deprecated! Use
\\protect\confidential\space instead}%
\confidential{#1}%
}
\newrobustcmd{\SEC}[1]{%
\PackageWarning{secretx}{Macro deprecated! Use
\\protect\secret\space instead}%
\secret{#1}%
}
\newrobustcmd{\SNF}[1]{%
\PackageWarning{secretx}{Macro deprecated! Use
\\protect\secretnoforn\space instead}%
\secretnoforn{#1}%
}
\newrobustcmd{\TS}[1]{%
\PackageWarning{secretx}{Macro deprecated! Use
\\protect\topsecret\space instead}%
\topsecret{#1}%
}
% \end{macrocode}
%
% \subsection{Formatting Details}
%
% Now we move on to specific formatting details. The header and footer
% are determined by the marking level of the current page, but only for
% article style documents and not beamer slides. For beamer, we need to