summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/dbshow/dbshow-doc.tex
blob: ebfe69c5350e378a424dfb2ca3c06a1d6c586d40 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
\documentclass[full]{l3doc}
\usepackage[scheme=plain, fontset=ubuntu]{ctex}
\usepackage{multicol}
\usepackage{adjustbox}
\usepackage{zhlineskip}
\usepackage{enumitem}
\usepackage{indentfirst}
\usepackage{titling}
\usepackage{geometry}
\usepackage{tabularray}
\usepackage{xcolor}
\usepackage{tcolorbox}
\tcbuselibrary{listings, skins, raster, breakable}
\usepackage{tabularray}

\def\zhdate{2022年1月10日}
\def\endate{2022/01/10}
\def\version{v1.3}

\geometry{
  left=4.5cm,
  right=2cm,
  top=2cm,
  bottom=2cm,
}
\hypersetup {
  CJKbookmarks,
  bookmarksopen,
  bookmarksopenlevel=3,
  pdfstartview=FitH,
  pdfinfo = {
   Title = The package 'dbshow' ,
   Subject = A LaTeX package ,
   Author = Li Changkai
 }
}

\IndexPrologue {
  \part*{Index}
  \markboth{Index}{Index}
  \addcontentsline{toc}{part}{Index}
  The~italic~numbers~denote~the~pages~where~the~
  corresponding~entry~is~described,~
  numbers~underlined~point~to~the~definition,~
  all~others~indicate~the~places~where~it~is~used.
}

\GlossaryPrologue {
  \part*{Change~History}
  {\GlossaryParms\ttfamily\hyphenchar\font=`\-}
  \markboth{Change~History}{Change~History}
  \addcontentsline{toc}{part}{Change~History}
}

\let\subsubitem\subitem

\DoNotIndex{\begin, \end}
\setlength{\parskip}{\medskipamount}

\newcommand\tikzmark[1]{\tikz \coordinate[overlay, remember picture] (#1);}
\def\levelchar{?}
\def\orbar{\textup{\textbar}}
\def\defaultval#1{\textbf{\textup{#1}}}
\def\TF{true\orbar false}
\def\TTF{\defaultval{true}\orbar false}
\def\TFF{true\orbar\defaultval{false}}
\def\zhbefore{\textbf{前}}
\def\zhafter{\textbf{后}}
\def\enbefore{\textbf{before}~}
\def\enafter{\textbf{after}~}
\DeclareDocumentEnvironment { note } { +b } {
  \par\textbf{\textsf{NOTE:~}}#1\par
} {}

\AtEndDocument{
  \newgeometry{
    left=2cm,
    right=2cm,
    top=2cm,
    bottom=2cm
  }
  \PrintChanges
  \PrintIndex
}

\ExplSyntaxOn
\makeatletter
\cs_new_protected:Nn \dbshow_changes:nnnn {
  \@bsphack\group_begin:\@sanitize
  \catcode`\\\z@ \catcode`\ 10 \MakePercentIgnore
  \exp_args:Nx \glossary {
    \exp_not:N \textbf{#1}\levelchar
    \exp_not:N \textit{#2}\c_space_tl
    \exp_not:N \textbf{#3}\c_colon_str\c_space_tl
    \exp_not:n { #4 }
  }
  \group_end:\@esphack
}
\cs_generate_variant:Nn \dbshow_changes:nnnn { xnnn }

\cs_new_protected:Nn \dbshow_changes_what:nnnn {
  \regex_extract_once:nnNT { doc|macro|bug|option }
  { #3 } \l_tmpa_seq {
    \dbshow_changes:xnnn {
      \str_case_e:nn { \seq_item:Nn \l_tmpa_seq { 1 } } {
        { doc } { Documentation }
        { macro } { Macro }
        { bug } { Bug }
        { option } {  Option }
        { logic } {  Logic }
      }
    }
      {#2} {#3} {#4}
  }
}

\cs_new_protected:Nn \dbshow_changes_how:nnnn {
  \regex_extract_once:nnNT { Add|Update|Remove } { #3 } \l_tmpa_seq {
    \dbshow_changes:xnnn { \seq_item:Nn \l_tmpa_seq { 1 } }
      {#2} {#3} {#4}
  }
}

% #1 version #2 date #3 type #4 desc
\DeclareDocumentCommand \changes { m m m m } {
  \dbshow_changes:nnnn {#1} {#2} {#3} {#4}
  \dbshow_changes_what:nnnn {#1} {#2} {#3} {#4}
  \dbshow_changes_how:nnnn {#1} {#2} {#3} {#4}
}
\makeatother

\DeclareDocumentEnvironment { Description } { o +b } {
  \hbox_set:Nn \l_tmpa_box { #1 }
  \dim_set:Nn \l_tmpa_dim { \box_wd:N \l_tmpa_box }
  \begin{itemize}[labelwidth=\l_tmpa_dim, align=left]
    #2
  \end{itemize}
} {  }

\cs_new_protected:Nn \dbshowdoc_function_begin:N {
  \cs_set_eq:NN \__codedoc_tmp_cs:nN \__codedoc_typeset_function_block:nN
  \cs_set_protected:Npn \__codedoc_typeset_function_block:nN ##1##2 {
    \__codedoc_function_label:xN {##1} ##2
    \hbox_set:Nn \l_tmpa_box {##1}
    \int_compare:nTF { \str_count:n {##1} <= 22 }
      {##1} { \adjustbox{width=.7\marginparwidth, height=\box_ht:N \l_tmpa_box}{##1} }
    #1{##1}
    \__codedoc_typeset_expandability: \\
  }
}
\cs_new_protected:Nn \dbshowdoc_function_end: {
  \cs_set_eq:NN \__codedoc_typeset_function_block:nN \__codedoc_tmp_cs:nN
}
\DeclareDocumentEnvironment { option } { O{} +v }
  {
    \dbshowdoc_function_begin:N \SpecialOptionIndex
    \__codedoc_function:nnw {#1} {#2}
  }
  {
    \__codedoc_function_end:
    \dbshowdoc_function_end:
  }
\DeclareDocumentEnvironment { environment } { O{} +v }
  {
    \dbshowdoc_function_begin:N \SpecialEnvIndex
    \__codedoc_function:nnw {#1} {#2}
  }
  {
    \__codedoc_function_end:
    \dbshowdoc_function_end:
  }

\DeclareDocumentCommand \opt { O{} m }
  { \__codedoc_cmd:no {#1} { #2 } }

\NewDocumentCommand \linktarget { m m m } {%
  \hyperlink{#1}{#3}%
  \raisebox{1em}{\hypertarget{#2}{}}%
}
\ExplSyntaxOff


\begin{document}
\title{
  \pkg{dbshow} 宏包 \version%
  \protect\footnote{%
    代码仓库:\url{https://github.com/ZhiyuanLck/dbshow},
    QQ群:788706534}
  \rlap{\makebox[4cm][r]{
    \normalsize $\Longrightarrow$ \color{red}
    \linktarget{en}{zh}{English Version}
  }}
}
\author{\textit{李昌锴} \texttt{<lichangkai225@qq.com>}}
\date{\zhdate}
\maketitle

\tableofcontents

\begin{documentation}

\section{引言}
编写本宏包的动机来源于当前没有一个很好的错题本宏包,可以方便的根据各种条件对错
题进行筛选、排序,然后以自定义的样式展示出来。\pkg{dbshow} 宏包实现了四个核心
功能:数据存储和使用、数据筛选、数据排序、数据展示。

数据只需要存储一次,就可以通过预定义的筛选、排序条件和样式展示部分或全部的数据。
如上所述,本宏包其实实现了一个非常简单的数据库,复习错题的功能只是其中一个应用,
和其他数据库宏包比如 \pkg{datatool} 相比,\pkg{dbshow} 更专注于非图表类型的数
据展示。

\changes{1.2}{2022-01-09}{Add doc}{descripton for expansion}
\begin{itemize}
  \item 名字后带有 $\star$ 的命令是可以完全展开的(fully-expandable);
  \item 名字后带有 \ding{73} 的命令可以有限制地展开(restricted-expandable);
  \item 名字后不带有特殊字符的命令是不可展开的(non-expandable);
  \item 名字后带有 $\star$ 的选项不影响相关的代码的是否可展开;
  \item 名字后带有 \ding{73} 的选项是否影响相关代码的可展开性取决于选项的设置;
  \item 名字后不带有特殊字符的选项会使与之相关的代码变得不可展开。
\end{itemize}

\subsection{数据类型}

宏包基于 \pkg{expl3} 的基础类型构建了6种类型:
\begin{Description}[\texttt{clist}]
  \item[\texttt{date}]
    日期类型,以 |yyyy/mm/dd| 形式存储,支持大小比较,排序(转
    换成字符串)。默认值为 \cs{dbtoday}。
  \item[\texttt{str}]
    字符串类型,支持正则匹配,英文排序。默认值为空。
  \item[\texttt{tl}]
    \meta{token list}类型,支持正则匹配。默认值为空。
  \item[\texttt{int}]
    整数类型,支持大小比较,排序。默认值为0。
  \item[\texttt{fp}]
    浮点数类型,支持大小比较,排序。默认值为0。
  \item[\texttt{clist}]
    逗号分隔的列表类型。默认值为空列表。
\end{Description}

\changes{1.3}{2022-01-08}{Remove dependency}{\pkg{datatime2}}
除了日期类型,所有类型都是 \pkg{expl3} 的内置类型。\pkg{dbshow} 构建了一个简单
的 |date| 类型,支持转换成整数以及带样式的打印。

\subsection{与 \pkg{datatool} 的区别}

\changes{1.2}{2022-01-07}{Add doc}{add comparison to \pkg{datatool}}

从核心功能上看,\pkg{dbshow} 和 \pkg{datatool} 实现了相同的功能。区别在于
\pkg{dbshow} 基于 \pkg{expl3} 实现,支持字符串的正则匹配,还支持多级排序。使用
方式上更倾向于样式与内容分离,所有的样式都可以通过选项提前定义好并且可以复用。
\pkg{dbshow} 并没有实现从外部文件读取数据以及将数据持久化的功能,我认为这些应
该是更专业的外部程序的工作而不应该在 \LaTeX 中设计这些功能。因此,\pkg{dbshow}
只提供了一个运行时的临时数据库,足够轻便且满足大部分正常需求。如果你想删除或修
改数据库中某一条记录,请去对应的位置删除或修改掉对应的 \env{dbitem} 环境,而不
是让宏包提供一个输出某一行记录的命令。某种意义上记录数据库的 \TeX 源文件本身就
是数据的一种持久化。

\section{接口文档}

\subsection{创建、展示和清空数据库}
\begin{function}[added=2022-01-05]{\dbNewDatabase, \dbNewDatabase*}
  \begin{syntax}
    \cs{dbNewDatabase} \oarg{base database} \marg{database} \{ \\
    ~~\meta{attr1} = \meta{type spec1}, \\
    ~~\meta{attr2} = \meta{type spec2}, \\
    ~~\ldots{} \\
    \} \\
    \cs{dbNewDatabase}* \marg{database} \{ \\
    ~~\meta{attr1} = \meta{type spec1}, \\
    ~~\meta{attr2} = \meta{type spec2}, \\
    ~~\ldots{} \\
    \} \\
  \end{syntax}

\end{function}

  新建一个数据库,不带星号的版本可以指定一个数据库来继承其属性设置,该版本总是
  会舍弃掉之前的定义。

  带星号的版本不会舍弃之前已有的定义,而是将新的选项添加到后面。

  \meta{attr} 为属性名称,\meta{type spec} 负责声明属性类型和属性默认值:

  \noindent\begin{tblr}{
    colspec = {ll},
    column{1} = {font = \ttfamily}
  }
    \meta{attr} = \meta{type} &
    将 \meta{attr} 声明为 \meta{type} 类型 \\
    \meta{attr} = \meta{type}\orbar\meta{default} &
    将 \meta{attr} 声明为 \meta{type} 类型,并且将默认值设置为 \meta{default}。
    \\
  \end{tblr}

  \begin{note}
    每个数据库都有一个默认的属性 |id| 用来存储数据的索引。
  \end{note}

  下面是定义一个错题数据库的示例,|question| 和 |answer| 属性用来存储问题和答
  案,|date| 属性存储日期,|info| 属性存储额外信息,|labels| 存储题目标签。
\begin{verbatim}
  \dbNewDatabase{ques}{
    question = tl,
    answer = tl,
    date = date,
    info = tl,
    labels = clist
  }
\end{verbatim}

\begin{function}[added=2022-01-05]{\dbshow}
  \begin{syntax}
    \cs{dbshow} \marg{style} \marg{database}
  \end{syntax}

  使用 \meta{style} 样式来展示 \meta{database}。
\end{function}

\changes{1.2}{2022-01-07}{Add macro}{\cs{dbclear}}
\begin{function}[added=2022-01-07]{\dbclear}
  \begin{syntax}
    \cs{dbclear} \marg{database}
  \end{syntax}
  清空 \meta{database} 里的所有内容。
\end{function}

\subsection{\cs{dbNewStyle} 和样式选项}

\begin{function}[added=2022-01-05]{\dbNewStyle}
  \begin{syntax}
    \cs{dbNewStyle} \oarg{base styles} \marg{style} \marg{database} \marg{opts}
  \end{syntax}

  为 \meta{database} 定义一个新的样式 \meta{style},该样式可以基于已有的样式
  \meta{base styles},比如 |\dbNewStyle[base1, base2]{new-style}{ques}{}|。
\end{function}

\subsubsection{通用选项}

\begin{option}[added=2022-01-05]{filter}
  \begin{syntax}
    filter = <filter>
  \end{syntax}

  为当前样式设置由 \cs{dbCombineFilters} 所定义的过滤器
\end{option}

\begin{option}[added=2022-01-06]{raw-filter}
  \begin{syntax}
    raw-filter = <conditional expression>
  \end{syntax}

  使用条件表达式设置匿名过滤器,这里的条件指通过 \cs{dbNewConditional} 定义的
  条件。下面代码中两个示例的过滤器具有相同的功能。
\end{option}

\changes{1.1}{2022-01-06}{Add option}{\opt{raw-filter}}

\begin{verbatim}
  % method 1
  \begin{dbFilters}{db}
    \dbNewConditional{cond1}{int-attr}{\rval > 1}
    \dbNewConditional*{cond2}{str-attr}{\d+}
  \end{dbFilters}
  \dbNewStyle{style}{db}{raw-filter={cond1 && cond2}}
  % method 2
  \begin{dbFilters}{db}
    \dbNewConditional{cond1}{int-attr}{\rval > 1}
    \dbNewConditional*{cond2}{str-attr}{\d+}
    \dbCombineFilters{filter}{cond1 && cond2}
  \end{dbFilters}
  \dbNewStyle{style}{db}{filter=filter}
\end{verbatim}

\changes{1.2}{2022-01-08}{Fix bug}{string sorting bug}
\begin{option}[added=2022-01-05]{sort}
  \begin{syntax}
    sort = \{ <attr spec1>, <attr spec2>, \ldots{} \}
  \end{syntax}

  为当前样式设置排序规则。支持根据 |str|,|date|,|int|,|fp| 类型的数据进行排
  序,支持多级排序。\meta{attr} 表示增序,\meta{attr}* 表示降序。下面例子中,
  使用 |sort-style| 展示数据时的顺序为先按 |level| 降序,|level| 相同的再按出
  生日期 |birth| 增序,以此类推。
\end{option}

\begin{verbatim}
  \dbNewDatabase{sort-example}{
    name = str,
    birth = date,
    level = int,
    weight = fp,
  }
  \dbNewStyle{sort-style}{sort-example}{
    sort = { level*, birth, name, weight }
  }
\end{verbatim}

\begin{option}[added=2022-01-05, rEXP]{item-code}
  \begin{syntax}
    item-code = <code>
  \end{syntax}

  该选项用来设置展示数据库中每条记录的代码。你可以使用 \cs{dbuse} 来展示属性的
  值。
\end{option}

\changes{1.3}{2022-01-09}{Update option}{\opt{<attr>/sep}}
\begin{option}[added=2022-01-05, updated=2022-01-08, rEXP]{<attr>/sep}
  \begin{syntax}
    <attr>/sep = <separator> \\
    <attr>/sep = \{ \\
    ~~\meta{separator between two}, \\
    ~~\meta{separator between more than two}, \\
    ~~\meta{separator between final two} \\
    \} \\
    <attr>/sep = \{ \\
    ~~\meta{separator before year}, \\
    ~~\meta{separator between year and month}, \\
    ~~\meta{separator between month and day}, \\
    ~~\meta{separator after day} \\
    \} \\
  \end{syntax}

  该选项只适用于类型为 |clist| 或 |date| 的属性,用来设置列表间元素的间隔。参
  数为一个 \meta{separator} 时,所有元素间的分隔符被设置为 \meta{separator}。
  \meta{separator before year} 和 \meta{separator after day} 被设置为空。
\end{option}

  参数为3个元素的逗号分隔的列表时,此选项用来设置列表元素的分隔符,分别用来设
  置只有两个元素时的分隔符 \meta{separator between two},超过两个元素时的分隔
  符 \meta{separator between more than two},和最后两个元素之间的分隔符
  \meta{separator between final two}。对于类型为 |clist| 的属性,设置此选项时
  如果参数列表数量不是1或者3会触发报错。

\begin{verbatim}
  % clist-attr is an attribute of database db
  % suppose the val of clist-attr is { 1, 2, 3 }
  \dbNewStyle{clist-sep}{db}{
    clist-attr/sep = { ,~ },                % print 1, 2, 3
    clist-attr/sep = { {,~}, {,~}, {and~} } % print 1, 2 and 3
  }
\end{verbatim}

  参数为4个元素的逗号分隔的列表时,此选项用来设置日期的分隔符,分别用来设
  置 \meta{year} 之前的分隔符 \meta{separator before year} ,\meta{year} 和
  \meta{month} 之间的分隔符 \meta{separator between year and month} ,
  \meta{month} 和 \meta{day} 之间的分隔符,以及 \meta{day} 之后的分隔符。对于
  类型为 |date| 的属性,设置此选项时如果参数列表数量不是1或者4会触发报错。

\begin{verbatim}
  % date-attr is an attribute of database db
  % suppose the val of date-attr is 2022/01/01
  \dbNewStyle{date-sep}{db}{
    date-attr/sep = -,             % print 2022-01-01
    date-attr/sep = { |, -, -, | } % print |2022-01-01|
  }
\end{verbatim}

\changes{1.3}{2022-01-08}{Add option}{\opt{<attr>/zfill}}
\begin{option}[added=2022-01-08, EXP]{<attr>/zfill}
  \begin{syntax}
    <attr>/zfill = <\TTF>
  \end{syntax}

  该选项只适用于类型为 |date| 的属性。控制输出月份和天时是否补零。
\end{option}

\subsubsection{装饰器}

下面这些选项在不同层次上装饰原有的展示代码,有些其实不必通过选项的形式来装饰,
但这样做的好处是可以进一步使样式与内容分离。下面的例子中,\meta{style1} 和
\meta{style2} 是相同的样式,都用 * 将 \meta{attr1} 包裹住了,但是如果你还想定
义一个样式用 = 将 \meta{attr1} 包裹住,如果用 \meta{style1} 的方式,那就可能
需要重复大片代码,用 \meta{style2} 的方式则可以很轻松的继承 \meta{style1} 中的
代码。

\begin{verbatim}
  \dbNewStyle{style1}{db}{
    item-code = {%
      *\rvuse{attr1}*\rvuse{attr2}
      % more code
    }
  }
  \dbNewStyle{base-style}{db}{
    item-code = {%
      \rvuse{attr1}\rvuse{attr2}
      % more code
    }
  }
  \dbNewStyle[base-style]{style2}{db}{
    attr1/before-code = { * },
    attr1/after-code = { * },
  }
  \dbNewStyle[base-style]{style3}{db}{
    attr1/before-code = { = },
    attr1/after-code = { = },
  }
\end{verbatim}

\changes{1.3}{2022-01-08}{Add option}{\opt{<attr>/wrapper}}
\begin{option}[added=2022-01-08, rEXP]{<attr>/wrapper}
  \begin{syntax}
    <attr>/wrapper = <control sequence>
  \end{syntax}

  该选项只适用于类型为 |date| 的属性。\meta{control sequence} 只接收一个参数即
  日期,如果设置了此选项,则最后输出的日期为
  \meta{control sequence}\marg{date}。
\end{option}

\begin{option}[added=2022-01-05, rEXP]{before-code}
  \begin{syntax}
    before-code = <code>
  \end{syntax}

  该选项用来设置在展示整个数据库之\zhbefore 需要执行的代码。
\end{option}

\begin{option}[added=2022-01-05, rEXP]{after-code}
  \begin{syntax}
    after-code = <code>
  \end{syntax}

  该选项用来设置在展示整个数据库之\zhafter 需要执行的代码。
\end{option}

\changes{1.2}{2022-01-08}{Add options}{\opt{record-before-code},
\opt{record-after-code}}
\begin{option}[added=2022-01-05, rEXP]{record-before-code}
  \begin{syntax}
    record-before-code = <code>
  \end{syntax}

  该选项用来设置在展示当前记录之\zhbefore 需要执行的代码。
\end{option}

\begin{option}[added=2022-01-05, rEXP]{record-after-code}
  \begin{syntax}
    record-after-code = <code>
  \end{syntax}

  该选项用来设置在展示当前记录之\zhafter 需要执行的代码。
\end{option}

\begin{option}[added=2022-01-05, rEXP]{<attr>/before-code}
  \begin{syntax}
    <attr>/before-code = <code>
  \end{syntax}

  该选项用来设置展示数据库中属性 \meta{attr} 对应数据之\zhbefore 需要执行的代
  码。\cs{dbuse} 会在展示属性数据\zhbefore 执行此代码。
\end{option}

\begin{option}[added=2022-01-05, rEXP]{<attr>/after-code}
  \begin{syntax}
    <attr>/after-code = <code>
  \end{syntax}

  该选项用来设置展示数据库中属性 \meta{attr} 对应数据之\zhafter 需要执行的代码。
  \cs{dbuse} 会在展示属性数据\zhafter 执行此代码。
\end{option}

\begin{option}[added=2022-01-05, rEXP]{<attr>/item-before-code}
  \begin{syntax}
    <attr>/item-before-code = <code>
  \end{syntax}

  该选项只适用于类型为 |clist| 的属性,用来设置展示列表每个元素\zhbefore 需要
  执行的代码。
\end{option}

\begin{option}[added=2022-01-05, rEXP]{<attr>/item-after-code}
  \begin{syntax}
    <attr>/item-after-code = <code>
  \end{syntax}

  该选项只适用于类型为 |clist| 的属性,用来设置展示列表每个元素\zhafter 需要执
  行的代码。
\end{option}

\subsection{使用 \cs{dbNewReviewPoints} 定义复习点}

\begin{function}[added=2022-01-05]{\dbNewReviewPoints}
  \begin{syntax}
    \cs{dbNewReviewPoints} \marg{name} \marg{points}
  \end{syntax}

  定义名为 \meta{name} 的复习点。这是专门为错题本或复习所定制的功能,
  \meta{points}是一系列整数,现在假设每道错题你都将写错时的日期记录在了 |date|
  属性中,并且你希望每隔2,5,15天复习一次。下面的代码给出了一个实现示例。
\end{function}

\begin{verbatim}
  \dbNewReviewPoints{review-point}{2, 5, 15}            % 定义复习点
  \begin{dbFilters}
    \dbNewConditional{cond1}{date}{review-point|\Today} % 定义复习条件
    \dbCombineConditionals{filter1}{cond1}              % 定义过滤器
  \end{dbFilters}
  \dbNewStyle{review-style}{ques}{filter=filter1}       % 定义展示样式
\end{verbatim}

\subsection{在 \env{dbFilters} 环境中定义过滤器}

\begin{environment}[added=2022-01-05]{dbFilters}
  \begin{syntax}
    |\begin{dbFilters}|\marg{database} \\
    ~~\meta{code}
    |\end{dbFilters}| \\
  \end{syntax}

  \env{dbFilters}用来定义过滤器,此环境中定义了 \cs{dbNewConditional} 命令用来
  定义条件和 \cs{dbCombineConditionals} 命令用来组合条件定义过滤器。过滤器独立
  于每个 \meta{database},这意味着你可以在不同数据库中定义名称相同的过滤条件和
  过滤器。
\end{environment}

\begin{function}[added=2022-01-05, updated=2022-01-08]{\dbNewConditional, \dbNewConditional*}
  \begin{syntax}
    \cs{dbNewConditional}  \marg{name}        \marg{attr} \marg{cond spec} \\
    \cs{dbNewConditional}* \marg{name}        \marg{attr} \marg{cond spec} \\[2pt]
    \cs{dbNewConditional}  \marg{name} \marg{int/fp attr} \marg{expr} \\
    \cs{dbNewConditional}* \marg{name} \marg{int/fp attr} \marg{expr} \\
    \cs{dbNewConditional}  \marg{name} \marg{str/tl attr} \marg{regex expr} \\
    \cs{dbNewConditional}* \marg{name} \marg{str/tl attr} \marg{regex expr} \\
    \cs{dbNewConditional}  \marg{name}  \marg{clist attr} \marg{val list} \\
    \cs{dbNewConditional}* \marg{name}  \marg{clist attr} \marg{val list} \\
    \cs{dbNewConditional}  \marg{name}   \marg{date attr} \marg{expr}
    \cs{dbNewConditional}* \marg{name}   \marg{date attr} \{\meta{review points}\orbar\meta{date}\} \\
  \end{syntax}

  \cs{dbNewConditional} 用来定义名为 \meta{name} 的条件,\meta{attr} 指定条件
  所绑定的属性,在 \meta{cond spec} 中可以用 \cs{dbval} 指代属性的值。
\end{function}

  \changes{1.3}{2022-01-10}{Update doc}{truncated division}
  对于类型为 |int| 和 |fp| 的属性,\meta{expr} 传递给 \cs{int_compare:nTF} 或
  \cs{fp_compare:nTF} 处理。
  \begin{note}
    |/| 为四舍五入除法,截断除法请用 \cs{dbIntDivTruncate}。
  \end{note}

  对于类型为 |str| 和 |tl| 的属性,\meta{regex} 为正则表达式,
  \cs{dbNewConditional} 表示部分匹配,\cs{dbNewConditional*} 表示整体匹配。

\begin{verbatim}
  \dbNewConditional {cond1}{str-attr}{abc} % 匹配 abc, abcd, 1abc, =abc= 等
  \dbNewConditional*{cond2}{str-attr}{abc} % 只匹配 abc
\end{verbatim}

  对于类型为 |clist| 的属性,使用 \cs{dbNewConditional} 定义的条件只要
  \meta{val list} 中的任意一个元素在属性值(列表)中则条件成立;使用
  \cs{dbNewConditional*} 定义的条件只有 \meta{val list} 中每一个值都在属性值
  (列表)中条件才成立。

\begin{verbatim}
  \dbNewConditional {cond1}{clist-attr}{a, b, c} % a, b, d 满足条件
  \dbNewConditional*{cond2}{clist-attr}{a, b, c} % a, b, d 不满足条件
\end{verbatim}

  \changes{1.3}{2022-01-08}{Update logic}{swap definition of starred and
  unstarred conditionals of date}
  对于类型为 |date| 的属性,\cs{dbNewConditional} 定义的条件后续处理中会将
  \meta{expr} 中的所有日期转换成相对\textit{1971年1月1日}的一个整数值,然后将
  处理后的表达式传递给 \cs{int_compare:nTF} 做进一步处理;
  \cs{dbNewConditional*} 使用复习点来定义过滤条件,\meta{review points} 是
  \cs{dbNewReviewPoints} 定义的复习点,\meta{date} 是用来比较的日期。

\begin{function}[added=2022-01-05]{\dbCombineConditionals}
  \begin{syntax}
    \cs{dbCombineConditionals} \marg{name} \marg{cond combination} \oarg{info}
  \end{syntax}

  \cs{dbCombineConditionals} 定义名为 \marg{name} 的过滤器,并将
  \cs{dbNewConditional} 定义的条件组合起来,比如
  \verb=\dbCombineConditionals{filter}{(cond1 && cond2) || !cond3}=。
  \meta{cond combination} 中可以使用的关系操作符为 \verb=&&, ||, !=。
  可以将 \opt{filter} 选项设置为 \meta{name} 来应用过滤器。\meta{info} 为过滤
  器的相关信息,在展示数据库的时候可以用 \cs{dbFilterInfo} 指代。
\end{function}

\subsection{使用 \env{dbitem} 环境存储数据}

\begin{environment}[added=2022-01-05]{dbitem}
  \begin{syntax}
    |\begin{dbitem}|\marg{database}[ \\
    ~~\meta{attr1} = \meta{val1}, \\
    ~~\meta{attr2} = \meta{val2}, \\
    ~~\ldots{} \\
    ] \\
    ~~\meta{code} \\
    |\end{dbitem}|
  \end{syntax}

  \env{dbitem} 环境用来存储数据。有两种存储数据的方法,较短的数据可以在选项列
  表中通过键值对设置值,较长的数据可以在 \meta{code} 中使用 \cs{dbsave} 存储。
  \cs{dbsave}会覆盖选项中设置的值。没有设置的值将会被设置为全局默认值,下面给
  出一个存储示例。
\end{environment}

\begin{verbatim}
  \begin{dbitem}[date = 2022-01-01, info = 测试]
    \dbsave{question}{这是一个测试问题}
    \dbsave{answer}  {这是一个测试答案}
  \end{dbitem}
\end{verbatim}

\subsection{\cs{dbsave} 和 \cs{dbuse}}

\changes{1.3}{2022-01-08}{Add macro}{\cs{dbsave*}}
\begin{function}[added=2022-01-05, updated=2022-01-08]{\dbsave, \dbsave*}
  \begin{syntax}
    \cs{dbsave}  \marg{attr} \marg{data} \\
    \cs{dbsave}* \marg{attr} \marg{data}
  \end{syntax}

  \cs{dbsave} 用来存储数据,只能在 \env{item} 环境中使用。使用 \cs{dbsave*} 存
  储的数据会被 \cs{exp_not:n} 包裹。
\end{function}

\changes{1.2}{2022-01-08}{Update macro}{make \cs{dbuse} fully-expandable}
\begin{function}[added=2022-01-05, updated=2022-01-08, EXP]{\dbuse}
  \begin{syntax}
    \cs{dbuse} \marg{attr}
  \end{syntax}

  \cs{dbuse} 用来展示数据,只能在 \opt{item-code} 选项中使用。\cs{dbuse} 是可
  展开的。
\end{function}

\subsection{条件判别式}

\begin{function}[added=2022-01-05, EXP]{\dbIfEmptyT, \dbIfEmptyF, \dbIfEmptyTF}
  \begin{syntax}
    \cs{dbIfEmptyTF} \marg{true code} \marg{false code} \\
    \cs{dbIfEmptyT} \marg{true code} \\
    \cs{dbIfEmptyF} \marg{false code}
  \end{syntax}

  该判别式用来判断当前数据库是否为空。下面的示例展示了如何预防空的列表环境。
\end{function}

\begin{verbatim}
  \dbNewStyle{style-cond1}{database-test}{
    before-code = {\dbIfEmptyF{\begin{enumerate}}},
    after-code = {\dbIfEmptyF{\end{enumerate}}},
    item-code = {\item \dbuse{attr-test}}
  }
\end{verbatim}

\changes{1.2}{2022-01-08}{Remove macros}{\cs{dbItemIfEmpty(TF)}, \cs{dbClistItemIfEmpty(TF)}}

\subsection{表达式函数}

\changes{1.3}{2022-01-10}{Add macros}{expression function aliases}
\begin{function}[added=2022-01-10, EXP]{
  \dbIntAbs, \dbIntSign, \dbIntDivRound, \dbIntDivTruncate, \dbIntMax,
  \dbIntMin, \dbIntMod, \dbFpSign,
}
  \begin{syntax}
    \cs{dbIntAbs} \Arg{intexpr}
    \cs{dbIntSign} \Arg{intexpr}
    \cs{dbIntDivRound} \Arg{intexpr_1} \marg{intexpr_2}
    \cs{dbIntDivTruncate} \Arg{intexpr_1} \marg{intexpr_2}
    \cs{dbIntMax} \Arg{intexpr_1} \marg{intexpr_2}
    \cs{dbIntMin} \Arg{intexpr_1} \marg{intexpr_2}
    \cs{dbIntMod} \Arg{intexpr_1} \marg{intexpr_2}
    \cs{dbFpSign} \Arg{fpexpr}
  \end{syntax}
  \cs{dbIntAbs} 等同于 \cs{int_abs:n} \\
  \cs{dbIntSign} 等同于 \cs{int_sign:n} \\
  \cs{dbIntDivRound} 等同于 \cs{int_div_round:nn} \\
  \cs{dbIntDivTruncate} 等同于 \cs{int_div_truncate:nn} \\
  \cs{dbIntMax} 等同于 \cs{int_max:nn} \\
  \cs{dbIntMin} 等同于 \cs{int_min:nn} \\
  \cs{dbIntMod} 等同于 \cs{int_mod:nn} \\
  \cs{dbFpSign} 等同于 \cs{fp_sign:n} \\
   详细的文档见 \pkg{interface3} \\
\end{function}

\subsection{特殊命令}

\pkg{dbshow} 定义了一些特殊的命令,会根据语境展开为不同的内容。

\changes{1.1}{2022-01-05}{Add macro}{
  \cs{dbarabic}, \cs{dbalph}, \cs{dbAlph}, \cs{dbroman},
  \cs{dbRoman}
}
\changes{1.1}{2022-01-06}{Fix bug}{\cs{dbIndex} not defined}
\begin{function}[added=2022-01-05, EXP]{
  \dbval, \dbDatabase, \dbFilterName, \dbFilterInfo,
  \dbIndex, \dbarabic, \dbalph, \dbAlph, \dbroman, \dbRoman
}
\begin{tblr}{ll}
  \cs{dbval} & 当前属性的值 \\
  \cs{dbDatabase} & 数据库名称 \\
  \cs{dbFilterName} & 当前样式过滤器的名称 \\
  \cs{dbFilterInfo} & 当前样式过滤器的相关信息 \\
  \cs{dbIndex} & 数据索引,等同于 \cs{dbuse}|{id}| \\
  \cs{dbarabic} & 用数字表示的查询集数据计数 \\
  \cs{dbalph} & 用小写字母表示的查询集数据计数 \\
  \cs{dbAlph} & 用大写字母表示的查询集数据计数 \\
  \cs{dbroman} & 用小写罗马字母表示的查询集数据计数 \\
  \cs{dbroman} & 用大写罗马字母表示的查询集数据计数 \\
  \end{tblr}
\end{function}

\section{错题本示例}
见第 \ref{sec:example} 节。

\changes{1.1}{2022-01-07}{Update doc}{improve example}

\title{
  Package \pkg{dbshow} \version%
  \protect\footnote{%
    Repository: \url{https://github.com/ZhiyuanLck/dbshow},
    Telegram Group: \url{https://t.me/latex_dbshow}}
  \rlap{\makebox[4cm][r]{
    \normalsize $\Longrightarrow$ \color{red}
    \linktarget{zh}{en}{中文版本}
  }}
}
\author{Li Changkai \texttt{<lichangkai225@qq.com>}}
\date{\endate}
\maketitle

\section{Introduction}

The initial motivation to write this package is that I want to write a
template, which can collect questions you gave the wrong answer and can
display those questions you would like to review by some conditionals, such as
questions with certain label, questions you have answered uncorrectly for
certain times or questions having not been reviewed for certain days. So this
package provides a database to do such thing.

The package provides four core functions: data storage and display, data
filtering, data sorting and data display. All data is saved once and then you
can display these data with custom filters, orders and styles.

\changes{1.2}{2022-01-09}{Add doc}{descripton for expansion}
\begin{itemize}
  \item Macros with a $\star$ are fully-expandable;
  \item Macros with a \ding{73} are restricted-expandable;
  \item Macros without appending a special symbol are nonexpandable;
  \item Options with a $\star$ \textit{do not} affect the expandability of
    related macros;
  \item Options with a \ding{73} affect the expandability of related macros
    according to its value;
  \item Options without appending a special symbol make the related macros
    nonexpandable.
\end{itemize}

\subsection{Data Types}

The package constructs 6 types based on the internal typed of \pkg{expl3}:
\begin{Description}[\texttt{clist}]
  \item[\texttt{date}]
    date saved in |yyyy/mm/dd| format, supports comparison, sorting
    (converting to string), default \cs{dbtoday}.
  \item[\texttt{str}]
    string,supports regex match and sorting, default empty.
  \item[\texttt{tl}]
    token list, supports regex match, default empty.
  \item[\texttt{int}]
    integer, supports comparison and sorting, default 0.
  \item[\texttt{fp}]
    floating point, supports comparison and sorting, default 0.
  \item[\texttt{clist}]
    comma list, default empty.
\end{Description}

\changes{1.3}{2022-01-08}{Remove dependency}{\pkg{datatime2}}
All types are internal types of \pkg{expl3} except |date| type, which provides
by \pkg{dbshow} itself and supports converting to integer and printing with
style.

\subsection{Comparison to \pkg{datatool}}

\changes{1.2}{2022-01-07}{Add doc}{add comparison to \pkg{datatool}}

\pkg{dbshow} and \pkg{datatool} implement the same core functions. But
\pkg{dbshow} is based on \pkg{expl3} and it supports string regex and
multi-level sorting. \pkg{dbshow} tries to divide style from the contents
(data in database): all styles are predefined and can be reused conveniently
so that there can be only codes to save data and one-line code to show the
database inside the \env{document} environment. You can hide the details in
the preamble and focus on the data you want to display. \pkg{dbshow} provides
a simple temporary runtime database, which means it can not input and output
data from/to extern files (they should be responsible by some professional
programming languages). When you need to delete or revise a record, just go to
where it is recorded in the source code rather than use a macro to manipulate
data after they are saved. In a sense, \TeX~file is also a kind of data
persistence.

\section{Interfaces}

\subsection{Create, Display and Clear Database}

\begin{function}[added=2022-01-05]{\dbNewDatabase, \dbNewDatabase*}
  \begin{syntax}
    \cs{dbNewDatabase} \oarg{base database} \marg{database} \{ \\
    ~~\meta{attr1} = \meta{type spec1}, \\
    ~~\meta{attr2} = \meta{type spec2}, \\
    ~~\ldots{} \\
    \} \\
    \cs{dbNewDatabase}* \marg{database} \{ \\
    ~~\meta{attr1} = \meta{type spec1}, \\
    ~~\meta{attr2} = \meta{type spec2}, \\
    ~~\ldots{} \\
    \} \\
  \end{syntax}

\end{function}

Create a new database named \meta{database}, unstarred form provides the optional
\meta{base database} from which current database inherit the attributes settings.
The unstarred form always replace the old definition, while starred form
appends the new options.

\begin{syntax}
  \meta{attr} = \meta{type} \\
  \meta{attr} = \meta{type}\orbar\meta{default}
\end{syntax}

The first form defines the \meta{attr} as \meta{type}, and the second also
sets the default value.

\begin{note}
  Every database has a default attribute |id| to store the index of the item.
\end{note}

The example below define a database named |ques|.
\begin{verbatim}
  \dbNewDatabase{ques}{
    question = tl, % store question
    answer = tl,   % store corresponding answer
    date = date,   % store the date when you were wrong
    info = tl,     % store extra info
    labels = clist % store question labels
  }
\end{verbatim}

\begin{function}[added=2022-01-05]{\dbshow}
  \begin{syntax}
    \cs{dbshow} \marg{style} \marg{database}
  \end{syntax}

  Show the \meta{database} with \meta{style}.
\end{function}

\changes{1.2}{2022-01-07}{Add macro}{\cs{dbclear}}
\begin{function}[added=2022-01-07]{\dbclear}
  \begin{syntax}
    \cs{dbclear} \marg{database}
  \end{syntax}

  Clear the content of \meta{database}.
\end{function}

\subsection{\cs{dbNewStyle} and Style Options}

\begin{function}[added=2022-01-05]{\dbNewStyle}
  \begin{syntax}
    \cs{dbNewStyle} \oarg{base styles} \marg{style} \marg{database} \marg{opts}
  \end{syntax}

  Define a new \meta{style} that binds to \meta{database}. The style can
  inherit from a list of \meta{base styles} such as
  |\dbNewStyle[base1, base2]{new-style}{ques}{}|.
\end{function}

\subsubsection{General Options}

\begin{option}[added=2022-01-05]{filter}
  \begin{syntax}
    filter = <filter>
  \end{syntax}

  Set the \meta{filter} defined by \cs{dbCombineFilters}.
\end{option}

\changes{1.1}{2022-01-06}{Add option}{\opt{raw-filter}}
\begin{option}[added=2022-01-06]{raw-filter}
  \begin{syntax}
    raw-filter = <conditional expression>
  \end{syntax}

  Set anonymous with conditionals defined by \cs{dbNewConditional}. Two
  filters shows in the code below have the same meaning.
\end{option}

\begin{verbatim}
  % method 1
  \begin{dbFilters}{db}
    \dbNewConditional{cond1}{int-attr}{\rval > 1}
    \dbNewConditional*{cond2}{str-attr}{\d+}
  \end{dbFilters}
  \dbNewStyle{style}{db}{raw-filter={cond1 && cond2}}
  % method 2
  \begin{dbFilters}{db}
    \dbNewConditional{cond1}{int-attr}{\rval > 1}
    \dbNewConditional*{cond2}{str-attr}{\d+}
    \dbCombineFilters{filter}{cond1 && cond2}
  \end{dbFilters}
  \dbNewStyle{style}{db}{filter=filter}
\end{verbatim}

\changes{1.2}{2022-01-08}{Fix bug}{string sorting bug}
\begin{option}[added=2022-01-05]{sort}
  \begin{syntax}
    sort = \{ <attr spec1>, <attr spec2>, \ldots{} \}
  \end{syntax}

  Set sorting rules. Attributes of type |str, date, int, fp| is supported to
  sort.  Multi-level sort is allowed. \meta{attr} represents for ascending
  order, and \meta{attr}* represents for descending order. The example below
  use four fields to determine the order of the records. It sorts on |level|
  in descending order first and if two |levels| are same then sorts on |birth|
  in ascending order and so on.
\end{option}

\begin{verbatim}
  \dbNewDatabase{sort-example}{
    name = str,
    birth = date,
    level = int,
    weight = fp,
  }
  \dbNewStyle{sort-style}{sort-example}{
    sort = { level*, birth, name, weight }
  }
\end{verbatim}

\begin{option}[added=2022-01-05, rEXP]{item-code}
  \begin{syntax}
    item-code = <code>
  \end{syntax}

  Set the code that show a single record. You can use \cs{dbuse} to display
  certian attribute.
\end{option}

\changes{1.3}{2022-01-09}{Update option}{\opt{<attr>/sep}}
\begin{option}[added=2022-01-05, updated=2022-01-08, rEXP]{<attr>/sep}
  \begin{syntax}
    <attr>/sep = <separator> \\
    <attr>/sep = \{ \\
    ~~\meta{separator between two}, \\
    ~~\meta{separator between more than two}, \\
    ~~\meta{separator between final two} \\
    \} \\
    <attr>/sep = \{ \\
    ~~\meta{separator before year}, \\
    ~~\meta{separator between year and month}, \\
    ~~\meta{separator between month and day}, \\
    ~~\meta{separator after day} \\
    \} \\
  \end{syntax}

  Only for attributes of type |clist| or |date|. Set the separator between
  items. If the argument is an one-item comma list, all separators are set to
  \meta{separator} but \meta{separator before year} and \meta{separator after
  day} is set empty.
\end{option}

  If the argument is a comma list of 3 items, it is used to set the separator
  between items of the comma list. Following documentation is quoted from
  \pkg{interface3}:
  \begin{quote}
    If the comma list has more than two items, the \meta{separator between
    more than two} is placed between each pair of items except the last, for
    which the \meta{separator between final two} is used. If the comma list
    has exactly two items, then they are placed in the input stream separated
    by the \meta{separator between two}. If the comma list has a single item,
    it is placed in the input stream, and a comma list with no items produces
    no output.
  \end{quote}
  For attributes of type |clist|, incorrect number (numbers exclude 1 and 3)
  of items of the argument will raise an error.

\begin{verbatim}
  % clist-attr is an attribute of database db
  % suppose the val of clist-attr is { 1, 2, 3 }
  \dbNewStyle{clist-sep}{db}{
    clist-attr/sep = { ,~ },                % print 1, 2, 3
    clist-attr/sep = { {,~}, {,~}, {and~} } % print 1, 2 and 3
  }
\end{verbatim}

  If the argument is a comma list of 4 items, it is used to set the separators
  of the date. For attributes of type |date|, incorrect number (numbers
  exclude 1 and 4) will raise an error.

\begin{verbatim}
  % date-attr is an attribute of database db
  % suppose the val of date-attr is 2022/01/01
  \dbNewStyle{date-sep}{db}{
    date-attr/sep = -,             % print 2022-01-01
    date-attr/sep = { |, -, -, | } % print |2022-01-01|
  }
\end{verbatim}

\changes{1.3}{2022-01-08}{Add option}{\opt{<attr>/zfill}}
\begin{option}[added=2022-01-08, EXP]{<attr>/zfill}
  \begin{syntax}
    <attr>/zfill = <\TTF>
  \end{syntax}

  Only for attributes of type |date|. Control whether to fill zero on the left
  of the month or day.
\end{option}

\subsubsection{Decorators}

The options below serves as decorators. In some cases, decorator can also be
encoded directly into |item-code| or some other places, which is convenient
sometimes. The benefit of defining decorators with options is that styles step
further to be divided with contents. In the examples below, \meta{style1} and
\meta{style2} is the same style, which wrap \meta{attr1} with *. When you want
another style which wrap \meta{attr1} with =, if you choose the way of
\meta{style1}, \meta{item code} are repeated, otherwise if you choose the way
of \meta{style2}, \meta{item code} is inherited and you only need define the
decorators.

\begin{verbatim}
  \dbNewStyle{style1}{db}{
    item-code = {%
      *\rvuse{attr1}*\rvuse{attr2}
      % more code
    }
  }
  \dbNewStyle{base-style}{db}{
    item-code = {%
      \rvuse{attr1}\rvuse{attr2}
      % more code
    }
  }
  \dbNewStyle[base-style]{style2}{db}{
    attr1/before-code = { * },
    attr1/after-code = { * },
  }
  \dbNewStyle[base-style]{style3}{db}{
    attr1/before-code = { = },
    attr1/after-code = { = },
  }
\end{verbatim}

\changes{1.3}{2022-01-08}{Add option}{\opt{<attr>/wrapper}}
\begin{option}[added=2022-01-08, rEXP]{<attr>/wrapper}
  \begin{syntax}
    <attr>/wrapper = <control sequence>
  \end{syntax}

  Only for attributes of type |date|. Output of \cs{dbuse}\marg{date attr}
  will be \meta{control sequence}\marg{date}.
\end{option}

\begin{option}[added=2022-01-05, rEXP]{before-code}
  \begin{syntax}
    before-code = <code>
  \end{syntax}

  Set the \meta{code} that is executed \enbefore displaying the database.
\end{option}

\begin{option}[added=2022-01-05, rEXP]{after-code}
  \begin{syntax}
    after-code = <code>
  \end{syntax}

  Set the \meta{code} that is executed \enafter displaying the database.
\end{option}

\changes{1.2}{2022-01-08}{Add options}{\opt{record-before-code},
\opt{record-after-code}}
\begin{option}[added=2022-01-05, rEXP]{record-before-code}
  \begin{syntax}
    record-before-code = <code>
  \end{syntax}

  Set the \meta{code} that is executed \enbefore displaying a record.
\end{option}

\begin{option}[added=2022-01-05, rEXP]{record-after-code}
  \begin{syntax}
    record-after-code = <code>
  \end{syntax}

  Set the \meta{code} that is executed \enafter displaying the record.
\end{option}

\begin{option}[added=2022-01-05, rEXP]{<attr>/before-code}
  \begin{syntax}
    <attr>/before-code = <code>
  \end{syntax}

  Set the \meta{code} that is executed by \cs{dbuse} \enbefore displaying
  certain attribute.
\end{option}

\begin{option}[added=2022-01-05, rEXP]{<attr>/after-code}
  \begin{syntax}
    <attr>/after-code = <code>
  \end{syntax}

  Set the \meta{code} that is executed by \cs{dbuse} \enafter displaying
  certain attribute.
\end{option}

\begin{option}[added=2022-01-05, rEXP]{<attr>/item-before-code}
  \begin{syntax}
    <attr>/item-before-code = <code>
  \end{syntax}

  Only for attributes of type |clist|. Set the \meta{code} that is excuted
  \enbefore displaying the item of the comma list.
\end{option}

\begin{option}[added=2022-01-05, rEXP]{<attr>/item-after-code}
  \begin{syntax}
    <attr>/item-after-code = <code>
  \end{syntax}

  Only for attributes of type |clist|. Set the \meta{code} that is excuted
  \enafter displaying the item of the comma list.
\end{option}

\subsection{Use \cs{dbNewReviewPoints} to Define Review Points}

\begin{function}[added=2022-01-05]{\dbNewReviewPoints}
  \begin{syntax}
    \cs{dbNewReviewPoints} \marg{name} \marg{points}
  \end{syntax}

  Define the new \meta{points} that is specially designed for reviewing
  something. \meta{points} is a list of integers. Suppose you record the date
  when you did not answer correctly and you plan to review every 2, 5 and 15
  days. The following code give what you want.
\end{function}

\begin{verbatim}
  \dbNewReviewPoints{review-point}{2, 5, 15}            % define points
  \begin{dbFilters}
    \dbNewConditional{cond1}{date}{review-point|\Today} % define conditional
    \dbCombineConditionals{filter1}{cond1}              % define filter
  \end{dbFilters}
  \dbNewStyle{review-style}{ques}{filter=filter1}       % define style
\end{verbatim}

\subsection{Define Filters inside \env{dbFilters} Environment}

\begin{environment}[added=2022-01-05]{dbFilters}
  \begin{syntax}
    |\begin{dbFilters}|\marg{database} \\
    ~~\meta{code}
    |\end{dbFilters}| \\
  \end{syntax}

  Filters are defined inside \env{dbFilters} environment, inside which,
  \cs{dbNewConditional} is defined to declare conditionals and
  \cs{dbCombineConditionals} is defined to combine conditionals. Filters are
  independent in different databases, which means the same name of filters is
  allowed in different databases.
\end{environment}

\begin{function}[added=2022-01-05, updated=2022-01-08]{\dbNewConditional, \dbNewConditional*}
  \begin{syntax}
    \cs{dbNewConditional}  \marg{name}        \marg{attr} \marg{cond spec} \\
    \cs{dbNewConditional}* \marg{name}        \marg{attr} \marg{cond spec} \\[2pt]
    \cs{dbNewConditional}  \marg{name} \marg{int/fp attr} \marg{expr} \\
    \cs{dbNewConditional}* \marg{name} \marg{int/fp attr} \marg{expr} \\
    \cs{dbNewConditional}  \marg{name} \marg{str/tl attr} \marg{regex expr} \\
    \cs{dbNewConditional}* \marg{name} \marg{str/tl attr} \marg{regex expr} \\
    \cs{dbNewConditional}  \marg{name}  \marg{clist attr} \marg{val list} \\
    \cs{dbNewConditional}* \marg{name}  \marg{clist attr} \marg{val list} \\
    \cs{dbNewConditional}  \marg{name}   \marg{date attr} \marg{expr}
    \cs{dbNewConditional}* \marg{name}   \marg{date attr} \{\meta{review points}\orbar\meta{date}\} \\
  \end{syntax}

  Define the conditional named \meta{name} that binds to \meta{attr}. \cs{dbval}
  is replaced with the real value of the attribute inside the \meta{cond spec}.
\end{function}

  \changes{1.3}{2022-01-10}{Update doc}{truncated division}
  For attributes of type |int| and |fp|, \meta{expr} is passed to
  \cs{int_compare:nTF} or \cs{fp_compare:nTF}.
  \begin{note}
    Division using |/| rounds to the closest integer. Use \cs{dbIntDivTruncate} to rounds
    the result toward 0.
  \end{note}

  For attribute of type |str| and |tl|, unstarred form matches any part while
  starred form matches the whole part with the \meta{regex expr}.

\begin{verbatim}
  \dbNewConditional {cond1}{str-attr}{abc}  % match abc, abcd, 1abc, =abc=, etc
  \dbNewConditional*{cond2}{str-attr}{abc} % only match abc
\end{verbatim}

  For attributes of type |clist|, the conditional defined by unstarred form is
  true if any item of \meta{val list} is in the comma list. While the
  conditional defined by starred form is true only if every item of \meta{val
  list} is in the comma list. As is showed below, for |cond1|, |a| is in
  |{a, b, d}| so |cond1| is true. While |c| is not in |{a, b, d}| so |cond2|
  is false.

\begin{verbatim}
  \dbNewConditional {cond1}{clist-attr}{a, b, c}  % {a, b, d} -> true
  \dbNewConditional*{cond2}{clist-attr}{a, b, c} % {a, b, d} -> false
\end{verbatim}

  \changes{1.3}{2022-01-08}{Update logic}{swap definition of starred and
  unstarred conditionals of date}
  For attributes of type |date|, unstarred form replace each date with a
  integer representing for the days between \meta{date} and
  \textit{1971/01/01}, and the result is passed to \cs{int_compare:nTF}.
  Starred form defines the conditional with review points defined by
  \cs{dbNewRdbNewReviewPoints} and \meta{date} is the date to be compared.

\begin{function}[added=2022-01-05]{\dbCombineConditionals}
  \begin{syntax}
    \cs{dbCombineConditionals} \marg{name} \marg{cond combination} \oarg{info}
  \end{syntax}

  Define the filter \meta{name}, which combine the conditionals and store the
  extra \meta{info} into \cs{dbFilterInfo}. So you can write something as\\
  \verb=\dbCombineConditionals{filter}{(cond1 && cond2) || !cond3}=.\\
  Supported operators are \verb=&&, ||, !=. You can set the option \opt{filter}
  to \meta{name} to apply the filter when you display the database.
\end{function}

\subsection{Store Data with \env{dbitem} Environment}

\begin{environment}[added=2022-01-05]{dbitem}
  \begin{syntax}
    |\begin{dbitem}|\marg{database}[ \\
    ~~\meta{attr1} = \meta{val1}, \\
    ~~\meta{attr2} = \meta{val2}, \\
    ~~\ldots{} \\
    ] \\
    ~~\meta{code} \\
    |\end{dbitem}|
  \end{syntax}

  The data are stored with \env{dbitem} environment in two ways. Smaller data
  can be stored in the option list and the bigger data can be stored by
  \cs{dbsave}, which will suppress the value set by the option list. An
  example code is showned below.
\end{environment}

\begin{verbatim}
  \begin{dbitem}[date=2022-01-01, info=test]
    \dbsave{question}{This is a test question.}
    \dbsave{answer}  {This is a test answer.}
  \end{dbitem}
\end{verbatim}

\subsection{\cs{dbsave} and \cs{dbuse}}

\changes{1.3}{2022-01-08}{Add macro}{\cs{dbsave*}}
\begin{function}[added=2022-01-05, updated=2022-01-08]{\dbsave, \dbsave*}
  \begin{syntax}
    \cs{dbsave}  \marg{attr} \marg{data} \\
    \cs{dbsave}* \marg{attr} \marg{data}
  \end{syntax}

  \cs{dbsave} save the \meta{data} to \meta{attr} of current record.
  \cs{dbsave} can be used only inside the \env{dbitem} environment.
  \meta{data} stored by \cs{dbsave*} is wrapped with \cs{exp_not:n} while
  \meta{data} stored by \cs{dbsave} keeps the same.
\end{function}

\changes{1.2}{2022-01-08}{Update macro}{make \cs{dbuse} fully-expandable}
\begin{function}[added=2022-01-05, updated=2022-01-08, EXP]{\dbuse}
  \begin{syntax}
    \cs{dbuse} \marg{attr}
  \end{syntax}

  Display the value of \meta{attr} of current record. \cs{dbuse} is
  \textbf{expandable} and can be only used inside the option \opt{item-code}.
\end{function}

\subsection{Conditionals}

\begin{function}[added=2022-01-05, EXP]{\dbIfEmptyT, \dbIfEmptyF, \dbIfEmptyTF}
  \begin{syntax}
    \cs{dbIfEmptyTF} \marg{true code} \marg{false code} \\
    \cs{dbIfEmptyT} \marg{true code} \\
    \cs{dbIfEmptyF} \marg{false code}
  \end{syntax}

  Test if the database is empty. The example below shows how to avoid an empty
  list environment.
\end{function}

\begin{verbatim}
  \dbNewStyle{style-cond1}{database-test}{
    before-code = {\dbIfEmptyF{\begin{enumerate}}},
    after-code = {\dbIfEmptyF{\end{enumerate}}},
    item-code = {\item \dbuse{attr-test}}
  }
\end{verbatim}

\changes{1.2}{2022-01-08}{Remove macros}{\cs{dbItemIfEmpty(TF)}, \cs{dbClistItemIfEmpty(TF)}}

\subsection{Expression Functions}

\changes{1.3}{2022-01-10}{Add macros}{expression function aliases}
\begin{function}[added=2022-01-10, EXP]{
  \dbIntAbs, \dbIntSign, \dbIntDivRound, \dbIntDivTruncate, \dbIntMax,
  \dbIntMin, \dbIntMod, \dbFpSign,
}
  \begin{syntax}
    \cs{dbIntAbs} \Arg{intexpr}
    \cs{dbIntSign} \Arg{intexpr}
    \cs{dbIntDivRound} \Arg{intexpr_1} \marg{intexpr_2}
    \cs{dbIntDivTruncate} \Arg{intexpr_1} \marg{intexpr_2}
    \cs{dbIntMax} \Arg{intexpr_1} \marg{intexpr_2}
    \cs{dbIntMin} \Arg{intexpr_1} \marg{intexpr_2}
    \cs{dbIntMod} \Arg{intexpr_1} \marg{intexpr_2}
    \cs{dbFpSign} \Arg{fpexpr}
  \end{syntax}
  \cs{dbIntAbs} is identical to \cs{int_abs:n} \\
  \cs{dbIntSign} is identical to \cs{int_sign:n} \\
  \cs{dbIntDivRound} is identical to \cs{int_div_round:nn} \\
  \cs{dbIntDivTruncate} is identical to \cs{int_div_truncate:nn} \\
  \cs{dbIntMax} is identical to \cs{int_max:nn} \\
  \cs{dbIntMin} is identical to \cs{int_min:nn} \\
  \cs{dbIntMod} is identical to \cs{int_mod:nn} \\
  \cs{dbFpSign} is identical to \cs{fp_sign:n} \\
   Detailed documentation see \pkg{interface3} \\
\end{function}

\subsection{Special Macros}

Some special macros are defined to expand to different contents according to context.

\changes{1.1}{2022-01-05}{Add macro}{
  \cs{dbarabic}, \cs{dbalph}, \cs{dbAlph}, \cs{dbroman},
  \cs{dbRoman}
}
\changes{1.1}{2022-01-06}{Fix bug}{\cs{dbIndex} not defined}
\begin{function}[added=2022-01-05, EXP]{
  \dbval, \dbDatabase, \dbFilterName, \dbFilterInfo,
  \dbIndex, \dbarabic, \dbalph, \dbAlph, \dbroman, \dbRoman
}
\begin{tblr}{ll}
  \cs{dbval} & Attribute value, only according in \cs{dbNewConditional}. \\
  \cs{dbDatabase} & Database name. \\
  \cs{dbFilterName} & Filter name. \\
  \cs{dbFilterInfo} & Filter information. \\
  \cs{dbIndex} & Record index, identical to \cs{dbuse}|{id}| \\
  \cs{dbarabic} & Show the counter of query set as digits. \\
  \cs{dbalph} & Show the counter of query set as lowercase letters. \\
  \cs{dbAlph} & Show the counter of query set as uppercase letters. \\
  \cs{dbroman} & Show the counter of query set as lowercase roman numerals. \\
  \cs{dbroman} & Show the counter of query set as uppercase roman numerals. \\
  \end{tblr}
\end{function}

\section{Example of Flaw Sweeper Template}
\label{sec:example}

\changes{1.1}{2022-01-07}{Update doc}{improve example}

\begin{tcblisting}{enhanced jigsaw,lower separated=false,
  leftlower=0pt,rightlower=0pt,
  colframe=red!50!black,colback=yellow!10!white,
  listing options={style=tcblatex,texcsstyle=*\color{red!70!black}},
  listing and comment,
  pdf comment,freeze pdf,
  compilable listing,
  breakable,
  run pdflatex
}
\documentclass{article}
\usepackage{amsmath, physics}
\usepackage{geometry}
\usepackage{dbshow}
\usepackage{tikz}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\usetikzlibrary{shadings}
\usepackage[hidelinks]{hyperref}

\geometry{
  margin=2cm
}

% #1 link node #2 target node #3 text to show
\NewDocumentCommand \linktarget { m m m } {%
  \hyperlink{#1}{#3}%
  \raisebox{1em}{\hypertarget{#2}{}}%
}

% question box
\tcbset{
  base/.style={
    empty,
    frame engine=path,
    colframe=yellow!10,
    coltitle=red!70,
    fonttitle=\bfseries\sffamily,
    sharp corners,
    left=4pt,
    right=4pt,
    drop fuzzy shadow,
    drop fuzzy shadow,
    borderline west={3pt}{-3pt}{red!80},
  }
}

\newtcolorbox{mybox}[1]{%
  base, title = {#1}
}

\dbNewReviewPoints{review}{1, 3, 7, 15, 30, 60}

\dbNewDatabase{ques-book}{
  ques = tl,
  answer = tl,
  count = int|1,
  labels = clist,
  date = date,
}

\begin{dbFilters}{ques-book}
  \dbNewConditional{hard}{labels}{hard}
  \dbNewConditional{bad}{count}{\dbval > 1}
  \dbNewConditional*{review}{date}{review|2022/01/07}
  \dbNewConditional{after}{date}{\dbval > 2022/01/02}
\end{dbFilters}

% show all questions with hyperlink to answers
\dbNewStyle{ques}{ques-book}{
  before-code = {\section{Questions}},
  item-code = {
    \begin{mybox}{%
      \linktarget{answer_\dbIndex}{ques_\dbIndex}{%
        Question \dbarabic%
        \hspace{2em}\dbuse{date}%
        \hspace{2em}\dbuse{labels}%
        \hfill\dbuse{count}%
      }%
    }
      \dbuse{ques}%
    \end{mybox}
  },
  labels/sep = /,
}

% show all questions and answers with hyperlink to questions
\dbNewStyle{answer}{ques-book}{
  before-code = {\section{Questions and Answers}},
  item-code = {
    \begin{mybox}{%
      \linktarget{ques_\dbIndex}{answer_\dbIndex}{%
        Question \dbarabic%
        \hspace{2em}\dbuse{date}%
        \hspace{2em}\dbuse{labels}%
        \hfill\dbuse{count}%
      }%
    }
      \dbuse{ques}\tcbsubtitle{Answer}\dbuse{answer}%
    \end{mybox}
  },
  labels/sep = /,
}

% show all hard questions with hyperlink to answers
\dbNewStyle{hard}{ques-book}{
  before-code = {\section{Hard Questions}},
  item-code = {
    \begin{mybox}{%
      \hyperlink{answer_\dbIndex}{%
        Question \dbarabic%
        \hspace{2em}\dbuse{date}%
        \hspace{2em}\dbuse{labels}%
        \hfill\dbuse{count}%
      }%
    }
      \dbuse{ques}%
    \end{mybox}
  },
  raw-filter = hard,
  labels/sep = /,
}

% show all hard questions that have been answered incorrectly for more than
% one time with hyperlink to answers
\dbNewStyle[hard]{bad}{ques-book}{
  before-code = {\section{Bad Questions}},
  raw-filter = {bad && hard},
}
% show all questions that plan to be reviewed on 2022/01/07 with hyperlink to
% answers
\dbNewStyle[hard]{review}{ques-book}{
  before-code = {\section{Questions to be Reviewed}},
  raw-filter = {review},
}
% show all questions that is record after 2022/01/02 with hyperlink to answers
\dbNewStyle[hard]{after}{ques-book}{
  before-code = {\section{Questions after 2022/01/02}},
  raw-filter = {after},
}

\AtEndDocument{
  \dbshow{review}{ques-book}
  \dbshow{hard}{ques-book}
  \dbshow{bad}{ques-book}
  \dbshow{after}{ques-book}
  \dbshow{ques}{ques-book}
  \dbshow{answer}{ques-book}
}

\begin{document}

\begin{dbitem}{ques-book}[
  date=2022/01/01,
  labels={math, equation, easy},
  count=2
  ]
  \dbsave{ques}{%
    Solve the linear equation: $x + 16 = 31$.
  }
  \dbsave{answer}{%
    $x = 31 - 16 = 15$
  }
\end{dbitem}

\begin{dbitem}{ques-book}[
  date=2022/01/01,
  labels={math, equation, hard},
  count=3
  ]
  \dbsave{ques}{%
    Solve the linear equation: $2y = 16$.
  }
  \dbsave{answer}{%
    $y = 16 / 2 = 8$
  }
\end{dbitem}

\begin{dbitem}{ques-book}[
  date=2022/01/04,
  labels={math, integral, hard},
  count=1
  ]
  \dbsave{ques}{%
    Find the indefinite integral: $\int 2x \dd x$.
  }
  \dbsave{answer}{%
    $\int 2x \dd x = x^2$
  }
\end{dbitem}

\end{document}
\end{tcblisting}

\end{documentation}
\end{document}