summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2022-01-06 21:07:47 +0000
committerKarl Berry <karl@freefriends.org>2022-01-06 21:07:47 +0000
commit2847c629f1a7b0032ace17d02dea127721d967a4 (patch)
treea0e043808361f7f2f4edbc9a8be3dcad817b38df
parente7f43a7dce3e1260163ed2a5f83289a656435264 (diff)
dbshow (6jan22)
git-svn-id: svn://tug.org/texlive/trunk@61513 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Master/texmf-dist/doc/latex/dbshow/dbshow-doc.pdfbin252249 -> 348241 bytes
-rw-r--r--Master/texmf-dist/doc/latex/dbshow/dbshow-doc.tex386
-rw-r--r--Master/texmf-dist/tex/latex/dbshow/dbshow.sty22
3 files changed, 311 insertions, 97 deletions
diff --git a/Master/texmf-dist/doc/latex/dbshow/dbshow-doc.pdf b/Master/texmf-dist/doc/latex/dbshow/dbshow-doc.pdf
index 5f709c5f0aa..3809cbc296a 100644
--- a/Master/texmf-dist/doc/latex/dbshow/dbshow-doc.pdf
+++ b/Master/texmf-dist/doc/latex/dbshow/dbshow-doc.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/dbshow/dbshow-doc.tex b/Master/texmf-dist/doc/latex/dbshow/dbshow-doc.tex
index 7799f42dc62..02332a12575 100644
--- a/Master/texmf-dist/doc/latex/dbshow/dbshow-doc.tex
+++ b/Master/texmf-dist/doc/latex/dbshow/dbshow-doc.tex
@@ -7,6 +7,9 @@
\usepackage{geometry}
\usepackage{tabularray}
\usepackage{xcolor}
+\usepackage{tcolorbox}
+\tcbuselibrary{listings, skins, raster, breakable}
+\usepackage{tabularray}
\IndexPrologue
{
@@ -56,6 +59,10 @@
}
\ExplSyntaxOn
+\NewDocumentCommand { \strcs } { m } {
+ \texttt{\tl_to_str:n { #1 }}
+}
+
\dim_new:N \l__my_syntax_dim
\box_new:N \g__my_syntax_box
\NewDocumentEnvironment { Syntax } { s }
@@ -128,14 +135,11 @@
\protect\hypertarget{zh}{}
}}
}
-\author{\textit{李昌锴} \texttt{<lichangkai225\@qq.com>}}
-\date{2022年1月3日}
+\author{\textit{李昌锴} \texttt{<lichangkai225@qq.com>}}
+\date{2022年1月7日}
\maketitle
-{\small
\tableofcontents
-}
-\newpage
\begin{documentation}
@@ -235,6 +239,26 @@
为当前样式设置由 \cs{dbCombineFilters} 所定义的过滤器
\end{option}
+\begin{option}{opt=raw-filter, desc={= \meta{cond combination}}}
+ 用已定义的条件为当前样式设置匿名过滤器。下面两个例子的作用是等同的。
+\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}
+
\begin{option}{
opt = sort,
desc = {= \{ \meta{attr spec1}, \meta{attr spec2}, \ldots{} \}},
@@ -528,12 +552,29 @@
}
\end{verbatim}
-\subsection{常量}
+\subsection{特殊命令}
-\begin{function}{\dbDatabase, \dbFilterName, \dbFilterInfo, \dbIndex}
- \cs{dbDatabase} 指代数据库名,\cs{dbFilterName} 指代过滤器名称,
- \cs{dbFilterInfo} 指代过滤器额外信息,\cs{dbIndex} 指代当前索引。
-\end{function}
+\pkg{dbshow} 定义了一些特殊的命令,会根据语境展开为不同的内容。
+
+\DescribeMacro{\dbval}当前属性的值,只能在 \cs{dbNewConditional} 中使用
+
+\DescribeMacro{\dbDatabase}数据库名称
+
+\DescribeMacro{\dbFilterName}过滤器名称
+
+\DescribeMacro{\dbFilterInfo}过滤器信息
+
+\DescribeMacro{\dbIndex}原始数据索引,等同于 |\dbuse{id}| 但是 \cs{dbuse} 是不可展开的
+
+\DescribeMacro{\dbarabic}用数字表示的查询集数据计数
+
+\DescribeMacro{\dbalph}用小写字母表示的查询集数据计数
+
+\DescribeMacro{\dbAlph}用小写字母表示的查询集数据计数
+
+\DescribeMacro{\dbroman}用小写罗马数字表示的查询集数据计数
+
+\DescribeMacro{\dbRoman}用大写罗马数字表示的查询集数据计数
\section{错题本示例}
见第 \ref{sec:example} 节。
@@ -547,8 +588,8 @@
\protect\hypertarget{en}{}
}}
}
-\author{Li Changkai \texttt{<lichangkai225\@qq.com>}}
-\date{2022/01/03}
+\author{Li Changkai \texttt{<lichangkai225@qq.com>}}
+\date{2022/01/07}
\maketitle
\section{Introduction}
@@ -647,6 +688,27 @@ from a list of \meta{base styles} such as
Set the \meta{filter} defined by \cs{dbCombineFilters}.
\end{option}
+\begin{option}{opt=raw-filter, desc={= \meta{cond combination}}}
+ Set anonymous with defined conditionals. Two examples below perform the same
+ function.
+\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}
+
\begin{option}{
opt = sort,
desc = {= \{ \meta{attr spec1}, \meta{attr spec2}, \ldots{} \}},
@@ -956,102 +1018,240 @@ code is showned below.
}
\end{verbatim}
-\subsection{Constants}
+\subsection{Special Macros}
-\begin{function}{\dbDatabase, \dbFilterName, \dbFilterInfo, \dbIndex}
- \cs{dbDatabase} represents for the database name, \cs{dbFilterName} represents for
- the filter name, \cs{dbFilterInfo} represents for the extra info of the
- filter and \cs{dbIndex} represents for the item index.
-\end{function}
+Some special macros are defined to expand to different contents according to context.
+
+\DescribeMacro{\dbval} Attribute value, only accessible in \cs{dbNewConditional}.
+
+\DescribeMacro{\dbDatabase} Database name.
+
+\DescribeMacro{\dbFilterName} Filter name.
+
+\DescribeMacro{\dbFilterInfo} Filter information.
+
+\DescribeMacro{\dbIndex} Index of original records, which is equal to |\rvuse{id}| but \cs{rvuse} is nonexpandable.
+
+
+\DescribeMacro{\dbarabic} Show the counter of query set as digits.
+
+\DescribeMacro{\dbalph} Show the counter of query set as lowercase letters.
+
+\DescribeMacro{\dbAlph} Show the counter of query set as uppercase letters.
+
+\DescribeMacro{\dbroman} Show the counter of query set as roman numerals.
+
+\DescribeMacro{\dbRoman} Show the counter of query set as Roman numerals.
\section{Example of Flaw Sweeper Template}
\label{sec:example}
-\begin{verbatim}
- \documentclass{article}
- \usepackage{dbshow}
- \usepackage{hyperref}
+\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}
- \NewDocumentCommand { \hyperlinktarget } { m m m } {%
- \hyperlink{#1}{#3}\hypertarget{#2}{}
- }
+\geometry{
+ margin=2cm
+}
- \dbNewDatabase{ques}{
- question=tl,
- answer=tl,
- date=date,
- count=int,
- labels=clist
- }
- \dbNewReviewPoints{review}{1, 3, 7, 15, 30, 60}
-
- \begin{dbFilters}{ques}
- % which need reviewed today?
- \dbNewConditional{date}{date}{review|2021-12-25}
- \dbNewConditional{easy}{labels}{easy}
- \dbNewConditional{not-easy}{labels}{mid, hard}
- % questions you haven't answered correctly for more than 3 times!
- \dbNewConditional{bad}{count}{\dbval > 3}
- \dbCombineConditionals{date}{date}[to be review today]
- \dbCombineConditionals{easy}{easy}[easy questions]
- \dbCombineConditionals{not-easy}{not-easy}[hard questions]
- \dbCombineConditionals{bad}{bad}[bad questions]
- \dbCombineConditionals{bad-easy}{bad && easy}[bad but easy questions]
- \end{dbFilters}
+% #1 link node #2 target node #3 text to show
+\NewDocumentCommand \linktarget { m m m } {%
+ \hyperlink{#1}{#3}%
+ \raisebox{1em}{\hypertarget{#2}{}}%
+}
- \newcounter{ques}
-
- \dbNewStyle{test}{ques} {
- before-code = {\setcounter{ques}{0}\section{Test}},
- item-code = {
- \refstepcounter{ques}
- \par\noindent\arabic{ques}. \dbuse{labels} \dbuse{date}\hfill \dbuse{count}
- \par\noindent ques: \dbuse{question}
- \par\noindent\hyperlinktarget
- {answer_\dbIndex}{ques_\dbIndex}{go to answer}
- },
- }
- \dbNewStyle{check}{ques} {
- before-code = {\setcounter{ques}{0}\section{Answer}},
- item-code = {
- \refstepcounter{ques}
- \par\noindent\arabic{ques}. \dbuse{labels} \dbuse{date}\hfill \dbuse{count}
- \par\noindent ques: \dbuse{question}
- \par\noindent\hyperlinktarget
- {ques_\dbIndex}{answer_\dbIndex}{back to question}
- \par\noindent answer: \dbuse{answer}
- },
- }
- \dbNewStyle[test]{test-bad}{ques}{
- filter=bad,
- before-code = {\setcounter{ques}{0}\section{Bad Question}}
+% 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},
}
+}
- \AtEndDocument{
- \dbshow{test}{ques}
- \dbshow{test-bad}{ques}
- \dbshow{check}{ques}
- }
+\newtcolorbox{mybox}[1]{%
+ base, title = {#1}
+}
- \begin{document}
+\dbNewReviewPoints{review}{1, 3, 7, 15, 30, 60}
- \begin{dbitem}{ques}[date=2021-12-21, count=1, labels=easy]
- \dbsave{question}{This is test question 1.}
- \dbsave{answer}{This is test question 1.}
- \end{dbitem}
+\dbNewDatabase{ques-book}{
+ ques = tl,
+ answer = tl,
+ count = int|1,
+ labels = clist,
+ date = date,
+}
- \begin{dbitem}{ques}[date=2021-12-22, count=4, labels=easy]
- \dbsave{question}{This is test question 2.}
- \dbsave{answer}{This is test question 2.}
- \end{dbitem}
+\begin{dbFilters}{ques-book}
+ \dbNewConditional{hard}{labels}{hard}
+ \dbNewConditional{bad}{count}{\dbval > 1}
+ \dbNewConditional{review}{date}{review|2022-01-07}
+\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 = /,
+}
- \begin{dbitem}{ques}[date=2021-12-23, count=3, labels=hard]
- \dbsave{question}{This is test question 3.}
- \dbsave{answer}{This is test question 3.}
- \end{dbitem}
+% 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 = /,
+}
- \end{document}
-\end{verbatim}
+% 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 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},
+}
+
+\AtEndDocument{
+ \dbshow{review}{ques-book}
+ \dbshow{hard}{ques-book}
+ \dbshow{bad}{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}
+
+\section*{Change History}
+\markboth{Change History}{Change History}
+\addcontentsline{toc}{section}{Change History}
+\noindent
+\begin{tblr}{
+ colspec = {lll},
+ row{1} = {font=\bfseries},
+}
+ Date & Ver. & Describe \\
+ 2022-01-05 & 1.0 & {
+ First version \\
+ Add macro: \cmd{\dbarabic}, \cmd{\dbalph}, \cmd{\dbAlph}, \cmd{\dbroman}, \cmd{\dbRoman}
+ } \\
+ 2022-01-06 & & {
+ Fix bug: \cmd{\dbIndex} undefined \\
+ Add style option: \opt{raw-filter}
+ } \\
+ 2022-01-07 & 1.1 & Improve example \\
+\end{tblr}
\end{documentation}
diff --git a/Master/texmf-dist/tex/latex/dbshow/dbshow.sty b/Master/texmf-dist/tex/latex/dbshow/dbshow.sty
index 6e51f048a45..0b02c20311e 100644
--- a/Master/texmf-dist/tex/latex/dbshow/dbshow.sty
+++ b/Master/texmf-dist/tex/latex/dbshow/dbshow.sty
@@ -14,8 +14,8 @@
% The Current Maintainer of this work is Li Changkai.
%
% This work consists of the files dbshow.sty, dbshow-doc.tex.
-\def\myfileversion{1.0}
-\def\myfiledate{2022/01/02}
+\def\myfileversion{1.1}
+\def\myfiledate{2022/01/07}
\RequirePackage{expl3, xparse}
\RequirePackage[calc]{datetime2}
\ProvidesExplPackage
@@ -444,7 +444,6 @@
\tl_gset_eq:cN { g__dbshow_filter_bool_tl_#1_#2 } \l_tmpa_tl
}
-\cs_generate_variant:Nn \regex_replace_all:nnN { nnc }
% #1 database #2 content
\NewDocumentEnvironment { dbFilters } { m +b } {
\seq_gclear_new:c { g__dbshow_cond_list_#1 }
@@ -488,12 +487,19 @@
}
}
+\int_gzero_new:N \g__dbshow_raw_filter_int
% #1 style name #2 database name
\cs_new_protected:Nn \dbshow_new_database_style:nn {
\dbshow_check_database:n { #2 }
\keys_define:nn { dbshow/style/#1 } {
filter .tl_gset:c = { g__dbshow_filter_#1_#2 },
filter .initial:n = -none-,
+ raw-filter .code:n = {
+ \int_gincr:N \g__dbshow_raw_filter_int
+ \str_set:Nx \l_tmpa_str { -raw\int_use:N \g__dbshow_raw_filter_int - }
+ \exp_args:NnV \tl_gset:cn { g__dbshow_filter_#1_#2 } \l_tmpa_str
+ \exp_args:NnV \dbshow_combine_conditional:nnn { #2 } \l_tmpa_str { ##1 }
+ },
sort .clist_gset:c = { g__dbshow_sort_#1_#2 },
before-code .tl_gset:c = { g__dbshow_style_before_#1_#2 },
before-code .initial:n = ,
@@ -604,7 +610,16 @@
{ \dbshow_sort:nNn { #2 } \l_index { #1 } }
% ##1 index
+ \int_zero_new:N \l_counter_int
\cs_set:Nn \dbshow_iter:n {
+ \int_incr:N \l_counter_int
+ \tl_set:Nx \dbalph { \int_to_alph:n { \l_counter_int } }
+ \tl_set:Nx \dbAlph { \int_to_Alph:n { \l_counter_int } }
+ \tl_set:Nx \dbarabic { \int_to_arabic:n { \l_counter_int } }
+ \tl_set:Nx \dbRoman { \int_to_Roman:n { \l_counter_int } }
+ \tl_set:Nx \dbroman { \int_to_roman:n { \l_counter_int } }
+ \tl_set:Nn \dbIndex { ##1 }
+
% ####1 attr
\cs_set:Npn \dbuse ####1 {
\dbshow_check_attr:nn { #2 } { ####1 }
@@ -614,7 +629,6 @@
{ g__dbshow_style_item_before_#1_#2_####1 }
\tl_set_eq:Nc \l_style_item_after_code
{ g__dbshow_style_item_after_#1_#2_####1 }
- \tl_set:Nn \dbIndex { ##1 }
\prop_get:cnN { g__dbshow_type_map_#2 } { ####1 } \l_tmp_type
% \tl_show:N \l_tmp_type