2

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 108

\ProvidesPackage{ex_test}[15/03/2024 for Ex_test version 3.

0 beta 6, Tran Anh Tuan and Duong Phuoc


Sang]

\RequirePackage{ifthen}

\RequirePackage{ntheorem}

\RequirePackage{longtable,xtab}

\RequirePackage{array}

\RequirePackage{multicol}

\RequirePackage{multirow}

\RequirePackage{enumerate}

\RequirePackage{fancyhdr}

\RequirePackage{answers}

\RequirePackage{tikz}

\RequirePackage{calc}

\usetikzlibrary{backgrounds}

\RequirePackage{etoolbox}

\RequirePackage{probsoln}

\RequirePackage{picinpar}

\RequirePackage{varwidth,mathrsfs}

\RequirePackage{filecontents,xstring}

\RequirePackage{expl3,xparse,epic,cntformats,xtemplate,environ}

\RequirePackage[shortlabels]{enumitem}

\let\Square\undefine

\RequirePackage{bbding}

%Fix immini

\def\thindent{}

%Fix in đáp án trắc nghiệm cho các môi trường vd, bt,...

\def\saveFileAns{}\def\keyEX{}\def\chType{0}

\newcommand{\fixshowans}[1]{%
\foreach \env in {#1} {%

\AtBeginEnvironment{\env}{%

\gdef\saveFileAns{}\gdef\keyEX{}\gdef\chType{0}%

\setcounter{dapan}{0}%

\def\dotEX{.}%

\setcounter{numTrueSol}{0}%

\AtEndEnvironment{\env}{%

\ifthenelse{\equal{\saveFileAns}{}}{}{

\Writetofile{ans}{\string\begin{Solution}{\Currentlabel}}%

\Writetofile{ans}{\saveFileAns^^J\string\end{Solution}}

\setcounter{numTrueSol}{0}%

\setcounter{numTrue}{0}%

\gdef\saveFileAns{}\gdef\keyEX{}\gdef\chType{0}%

\labelex%

\fixshowans{ex,bt,vd}

%Ghi đáp số bên phải câu hỏi

\newcommand{\dapso}[1]{\hspace{\fill}\mbox{}\linebreak[0]\hspace*{\fill}\textbf{ĐS:} #1}

\newcommand{\exitdapso}{\renewcommand{\dapso}[1]{\leavevmode\unskip}}%

%Gán tên và đánh số hình vẽ trong môi trường \immini

\def\IMname{}

\def\IMlabel{}

\newcommand{\imlabel}[2]{%

\def\IMname{\refstepcounter{figure}\label{#2}}%
\def\IMlabel{Hình \thefigure: #1}%

%hide choice

\makeatletter

\newcommand{\hidechoice}[1]{%

\AtBeginEnvironment{#1}{\renewcommand{\choice}[5][]{}}%

%hide choice From To

\newcommand{\hidechoiceFT}[3][ex]{%

\AtBeginEnvironment{#1}{%

\ifthenelse{\value{#1}>\the\numexpr #2-2\relax \AND \value{#1}<\the\numexpr #3\


relax}%

{\renewcommand{\choice}[5][]{}}{}%

%hideenviron

\newcommand{\hideenviron}[1]{\RenewEnviron{#1}{}}

%dotlineEX equal number line

\newdimen\linepar

\newlength{\paroutindent}

\newlength{\lineheight}

\setlength{\lineheight}{\heightof{A}}

\NewDocumentCommand{\Ifint}{mmm}{\IfInteger{#1}{#2}{#3}}

\newcommand{\ifint}[3]{\Ifint{#1}{#2}{#3}}

\newif\ifInTcolorbox

\newcounter{iftcbcounter}

\BeforeBeginEnvironment{tcolorbox}{%

\stepcounter{iftcbcounter}%
\InTcolorboxtrue%

\AfterEndEnvironment{tcolorbox}{%

\addtocounter{iftcbcounter}{-1}%

\ifnum\value{iftcbcounter}=0

\InTcolorboxfalse%

\fi%

\makeatletter

\newcommand{\writeansbook}[1]{}

\newcommand{\chooseNSA}{\def\kindSA{}}

\newcommand{\dotlinefull}[2][]{%

\renewcommand{\chooseNSA}{\def\kindSA{\kindSAapply}}

\AtBeginEnvironment{#2}{%

\def\colorEX{}%

\ifthenelse{\equal{\kindSA}{ShowSAKeyColor}}{\chooseNSA}{}%

\ifthenelse{\equal{\kindSA}{ShowSAKeyLG}}{\chooseNSA}{}%

\renewcommand{\TrueTF}{\FalseTF}

\renewcommand{\TrueEX}{\FalseEX}

\renewcommand{\writekeyTFone}{}

\renewcommand{\writekeyTF}{&&}

\renewcommand{\loigiai}[1]{%

\ifInTcolorbox

\ifdef{\endboxex}{\endboxex\def\endboxex{}}{}%

\fi

\setlength{\paroutindent}{\expandafter\parindent}

\setbox0=\vbox{\hbox{

\noindent\begin{minipage}{\linewidth}%
\setlength{\parindent}{\paroutindent}##1\end{minipage}

}}

\linepar=\ht0

\pgfmathparse{round((\linepar-\fboxsep)/(\lineheight))}

\par\noindent\textbf{\loigiaiEX}%

\dotlineEX{\pgfmathresult}%

\ifthenelse{\equal{#1}{ansbook}}{\writeansbook{##1}}{}%

%Ẩn hiện công thức tự động

\newlength\wsh

\newlength\hsh

\newlength\dsh

\def\dotfillans#1{\cleaders\hbox to #1{.}\hfill}

\newcommand\dotlinesh[2][.5em]{\leavevmode\hbox to #2{\dotfillans{#1}\hfil}}

\newcommand{\sh}[1]{%

\settowidth\wsh{#1}%

\settoheight\hsh{#1}%

\settodepth\dsh{#1}%

\ifdim\wsh<20pt\relax\setlength{\wsh}{20pt}\fi%

\raisebox{0pt}[\hsh][\dsh]{%

\dotlinesh{\wsh}%

\newcommand{\TF}[1]{\EXboxTF{\textbf{\colorEX#1}}}

\newcommand{\boxEX}[2][9pt]{%

\def\sizeboxEX{#1}%
\setbox1=\hbox{#2}%

\ \EXbox{#2}\ %

%Lệnh tagEX gán nhãn công thức thủ công

\newcommand{\tagEX}[1]{%

\hfill{\rm (#1)}%

\par

\@ifnextchar\begin%

{\vspace{-\baselineskip}}

{}

%Đánh dấu phương án đúng

\newcommand*\circled[1]{\tikz[baseline=(char.base)]{

\node[shape=circle,draw,inner sep=0.5pt] (char) {#1};}}

\newcommand{\circT}[2][red,fill=yellow!50]{\tikz[baseline=(char.base)]{\draw[#1,scale=\f@size/11.5]
(0,0) circle(7pt);\node (char)[above=-1.4ex]{\color{red}#2};\node (char)[right=6pt,scale=0.95]{\
color{black}\parbox[t]{2.6mm}{\centering Đ}};}\vspace{0.1mm}}

\newcommand{\circF}[2][red,fill=yellow!50]{\tikz[baseline=(char.base)]{\draw[#1,scale=\f@size/11.5]
(0,0) circle(7pt);\node (char)[above=-1.4ex]{\color{red}#2};\node (char)[right=6pt,scale=0.95]{\
color{black}\parbox[t]{2.6mm}{\centering S}};}\vspace{0.1mm}}

\newcommand{\circX}[2][red,fill=yellow!50]{\tikz[baseline=(char.base)]{\draw[#1,scale=\f@size/11.5]
(0,0) circle(7pt);\node (char)[above=-1.3ex]{\color{red}#2};}\vspace{0.1mm}}

\newcommand{\Onlycirc}{%

\renewcommand{\circT}[2][draw=black,fill=blue]{\,\tikz[baseline=(char.base)]{\
node[shape=circle,inner sep=0.4pt,##1] (char) {\phantom{H}};\node (0,0) {\bf\color{white}##2};}}

\renewcommand{\circF}[2][draw=black,fill=white]{\,\tikz[baseline=(char.base)]{\
node[shape=circle,inner sep=0.4pt,##1] (char) {\phantom{H}};\node (0,0) {\bf\color{black}##2};}}

\newcommand{\Fullcirc}{%
\renewcommand{\circT}[2][red,fill=yellow!40]{\tikz[baseline=(char.base)]{\draw[##1] (0,0)
circle(7pt);\node (char)[above=-1.4ex]{\color{black}##2};\node (char)[right=6pt,scale=0.95]{\
color{black}Đúng};}}

\renewcommand{\circF}[2][red,fill=yellow!40]{\tikz[baseline=(char.base)]{\draw[##1] (0,0)
circle(7pt);\node (char)[above=-1.4ex]{\color{black}##2};\node (char)[right=6pt,scale=0.95]{\
phantom{Đúng}};\node (char)[right=12pt,scale=0.95]{\color{black}Sai};}}

\newcommand{\Returncirc}{%

\renewcommand{\circT}[2][red,fill=yellow!50]{\tikz[baseline=(char.base)]{\draw[##1,scale=\
f@size/11.5] (0,0) circle(7pt);\node (char)[above=-1.4ex]{\color{red}##2};\node (char)
[right=6pt,scale=0.95]{\color{black}\parbox[t]{2.6mm}{\centering Đ}};}\vspace{0.1mm}}

\renewcommand{\circF}[2][red,fill=yellow!50]{\tikz[baseline=(char.base)]{\draw[##1,scale=\
f@size/11.5] (0,0) circle(7pt);\node (char)[above=-1.4ex]{\color{red}##2};\node (char)
[right=6pt,scale=0.95]{\color{black}\parbox[t]{2.6mm}{\centering S}};}\vspace{0.1mm}}

\newcommand{\circEX}[2][fill=yellow!50,draw=red]{%

\tikz[baseline=(char.base)]{\node[shape=circle,inner sep=1pt,#1] (char) {\color{red}#2};}

\newcommand{\squareEX}[2][fill=yellow!50,draw=red]{%

\tikz[baseline=(char.base)]{\node[shape=rectangle,inner sep=2.5pt,#1] (char) {\color{red}#2};}

\newcommand{\squareTF}[2][fill=yellow!50,draw=red]{%

\tikz[baseline=(char.base)]{\node[shape=rectangle,inner sep=0.5pt,#1] (char) {~#2\


phantom{~}};}

%%==============================

%Hiện Chọn đáp án trong lời giải chi tiết

\def\multichoice{0}% Có được chọn nhiều hơn 1 PA hay không.

\def\selectchoice{Chọn đáp án} \def\keyCh{\circEX[fill=yellow!50,draw=red]{\color{red}\keyEX}}

\def\selectchoiceTF{Chọn đáp án}\def\keyTF{\squareTF[fill=yellow!5,draw=black]{\color{black}\keyEX}}


\def\selectshortans{Đáp án:} \def\keySA{\squareEX[fill=yellow!40,draw=red]{\color{red}\keyEX}}

\newcommand{\textchoice}{%

\ifnum\multichoice>0 \def\keyCh{\squareTF[fill=yellow!50,draw=red]{\color{red}\keyEX}}\fi

\par\noindent

\ifnum\chType=0 \selectchoice\ \keyCh\fi

\ifnum\chType=1 \selectchoiceTF\ \keyTF\fi

\ifnum\chType=-1\selectshortans\ \keySA\fi

\ifthenelse{\equal{\qedEX}{}}{}{\dotfill\qedEX\par}%

\newcommand{\hidetextchoice}{%

\renewcommand{\textchoice}{}%

\newcommand{\showtextchoice}{%

\renewcommand{\textchoice}{%

\ifnum\multichoice>0 \def\keyCh{\squareTF[fill=yellow!50,draw=red]{\color{red}\
keyEX}}\fi

\par\noindent

\ifnum\chType=0 \selectchoice\ \keyCh\fi

\ifnum\chType=1 \selectchoiceTF\ \keyTF\fi

\ifnum\chType=-1\selectshortans\ \keySA\fi

\ifthenelse{\equal{\qedEX}{}}{}{\dotfill\qedEX\par}%

%Tương thích môi trường enumerate,itemize,taskEX

\makeatletter

\newcommand{\listenumerate}[1]{%

\def\temp##1{%

\ifcsname ##1\endcsname
\ifcsname listened@##1\endcsname\else

\expandafter\let\csname old##1\expandafter\endcsname\csname ##1\endcsname

\expandafter\renewcommand\csname ##1\endcsname{%

\@ifnextchar\begin{\csname old##1\expandafter\endcsname\hfill}{\csname old##1\


endcsname}%

}%

\expandafter\newcommand\csname listened@##1\endcsname{}%

\fi\fi%

}%

\forcsvlist\temp{#1}%%

\AtBeginDocument{\listenumerate{ex,vd,bt}}

%Lời giải

\def\loigiaiEX{\noindent\parbox[c]{\linewidth-1mm}{\centering\color{blue}Lời giải.}}

%Danh sách môi trường hiện dòng kẻ trong lời giải

\newcommand{\dotlineans}[3][]{%

\renewcommand{\chooseNSA}{\def\kindSA{\kindSAapply}}

\AtBeginEnvironment{#3}{%

\makeatletter

\def\colorEX{}%

\ifthenelse{\equal{\kindSA}{ShowSAKeyColor}}{\chooseNSA}{}%

\ifthenelse{\equal{\kindSA}{ShowSAKeyLG}}{\chooseNSA}{}%

\renewcommand{\TrueTF}{\FalseTF}

\renewcommand{\TrueEX}{\FalseEX}

\renewcommand{\writekeyTFone}{}

\renewcommand{\writekeyTF}{&&}

\renewcommand{\loigiai}[1]{%

\ifInTcolorbox
\ifdef{\endboxex}{\endboxex\def\endboxex{}}{}%

\fi

\par\noindent\textbf{\loigiaiEX}%

\dotlineEX{#2}%

\ifthenelse{\equal{#1}{ansbook}}{\writeansbook{##1}}{}%

%Danh sách môi trường hiện dòng kẻ trong lời giải

\newcommand{\showansEX}[2][]{%

% \renewcommand{\chooseNSA}{\def\kindSA{ShowSAKeyColor}}

\AtBeginEnvironment{#2}{%

\makeatletter

% \chooseNSA

\showanswers

%Xuất hiện chữ Lời giải trong môi trường onlysolution

\renewcommand{\do@onlysolution}[1]{%

\par\noindent\textbf{\loigiaiEX}%

\ifshowanswers

\@ifnextchar\immini

{}

{ \@ifnextchar\begin

{}

{\par\noindent}

##1%

\fi

\ifthenelse{\equal{\keyEX}{}}{}
{\leavevmode\unskip\textchoice\ignorespaces\xdef\keyEX{}}%

\setcounter{numTrueSol}{0}%

\renewcommand{\loigiai}[1]{%

\ifInTcolorbox \ifdef{\endboxex}{\endboxex\def\endboxex{}}{} \fi

\labelex \def\labelex{}

\begin{onlysolution}

##1

\end{onlysolution}%

\ifthenelse{\equal{#1}{ansbook}}{\writeansbook{##1}}{}%

\newcommand{\exitshowansEX}[1]{%

% \renewcommand{\chooseNSA}{\def\kindSA{}}

\AtBeginEnvironment{#1}{%

\makeatletter

% \chooseNSA

\renewcommand{\loigiai}[1]{%

\writeansbook{##1}%

}%

%Danh sách môi trường hiện dòng kẻ trong lời giải

\makeatletter

\newcommand{\hideansEX}[2][]{%

\renewcommand{\chooseNSA}{\def\kindSA{\kindSAapply}}

\AtBeginEnvironment{#2}{%
\def\colorEX{}%

\ifthenelse{\equal{\kindSA}{ShowSAKeyColor}}{\chooseNSA}{}%

\ifthenelse{\equal{\kindSA}{ShowSAKeyLG}}{\chooseNSA}{}%

\renewcommand{\TrueTF}{\FalseTF}

\renewcommand{\TrueEX}{\FalseEX}

\renewcommand{\writekeyTFone}{\gdef\TrueX{}\gdef\FalseX{}}

\renewcommand{\writekeyTF}{&&}

\renewcommand{\loigiai}[1]{%

\ifthenelse{\equal{#1}{ansbook}}{\writeansbook{##1}}{}%

\newcommand{\exithideansEX}[1]{}

%Định nghĩa QED kết thúc chứng minh

\def\qedEX{\ensuremath{\square}}

%Đáp số câu hỏi tự luận

\Newassociation{solshort}{Solshort}{ansshort}

\renewcommand{\Solshortlabel}[1]{\color{violet}\textbf{#1.}}

\newcommand{\shortsolnum}[1]{

\renewenvironment{Solshort}[1]

{\begin{minipage}{\linewidth/#1-1.2\fboxsep}

\color{violet}\textbf{##1.}

\color{black}

{\end{minipage}}

\newcommand{\shortsol}[1]{

\scantokens{
\begin{solshort}

#1

\end{solshort}}

%Trích dẫn nguồn

\def\labelex{}

\newcommand{\nameex}{\color{violet}Câu}

\newcommand{\namebt}{\color{blue}Bài}

\newcommand{\namevd}{\color{red}Ví dụ}

%Tương thích gói picinpar

\def\picinpar{\setlength{\linewidth}{\linewidth}}

\AtBeginEnvironment{window}{\def\picinpar{\setlength{\linewidth}{\linewidth-\picwd-\lwindowsep-2\
fboxsep}}}

%Tùy chọn lời giải

\newcommand{\choicew}[1]{\setlength{\widthch}{#1}}

\newcommand{\loigiai}[1]{%

\begin{onlysolution}

#1

\end{onlysolution}

%Cách hiển thị cho các phương án

\newcounter{debai}

\newcounter{dapan}

\newcounter{numTrue}

\newcounter{numTrueSol}

\def\colorEX{} % Màu cho phương án đúng


\def\dotEX{.} % Dấu câu sau mỗi phương án

\newcommand{\DapAnTF}{\alph{dapan}}

\newcommand{\DapAnSA}{\alph{dapan}}

\newcommand{\FalseTF}{\stepcounter{dapan}\textbf{\DapAnTF\sepTF}\ignorespaces}

\newcommand{\TrueTF}{\FalseTF}

\newcommand{\FalseEX}{\stepcounter{dapan}\textbf{\Alph{dapan}.}\ignorespaces}

\newcommand{\TrueEX}{\FalseEX}

\newcommand{\True}{\ifnum\chType=0\setcounter{numTrueSol}{\thedapan}\setcounter{numTrue}{\
thedapan}\fi}

\newlength\widthalpha

\newlength\widthalphaT

\newlength\widthalphaF

\ifnum\chType=0\settowidth\widthalphaT{\TrueEX}\else\settowidth\widthalphaT{\TrueTF}\fi

\ifnum\chType=0\settowidth\widthalphaF{\FalseEX}\else\settowidth\widthalphaF{\FalseTF}\fi

\ifdim\widthalpha<\widthalphaT\relax\setlength{\widthalpha}{\widthalphaT}\fi%

\ifdim\widthalpha<\widthalphaF\relax\setlength{\widthalpha}{\widthalphaF}\fi%

\makeatletter

\newcommand{\begindapan}{%

\@ifnextchar\True

\begin{minipage}[t]{\widthalpha}

\ifnum\chType=0\TrueEX\else\TrueTF\fi

\end{minipage}

\begin{minipage}[t]{\dorong}

\ifnum\chType=1

\xdef\saveFileAns{\saveFileAns\string\circT{\DapAnTF}}%

\ifnum\thedapan=1 \xdef\keyEX{\DapAnTF\ đúng}

\else \xdef\keyEX{\keyEX\ \big| \DapAnTF\ đúng} \fi%


\else

\ifnum\multichoice=0

\xdef\saveFileAns{\Alph{dapan}}%

\xdef\keyEX{\Alph{dapan}}%

\else

\xdef\saveFileAns{\saveFileAns\Alph{dapan}}%

\ifthenelse{\equal{\keyEX}{}}

{\xdef\keyEX{\Alph{dapan}}}

{\xdef\keyEX{\keyEX\ \big| \Alph{dapan}}}

\fi

\fi%

\begin{minipage}[t]{\widthalpha}

\ifnum\chType=0\FalseEX\else\FalseTF\fi

\end{minipage}

\begin{minipage}[t]{\dorong}

\ifnum\chType=1

\xdef\saveFileAns{\saveFileAns\string\circF{\DapAnTF}}%

\ifnum\thedapan=1 \xdef\keyEX{\keyEX\DapAnTF\ sai}

\else \xdef\keyEX{\keyEX\ \big| \DapAnTF\ sai} \fi%

\fi%

\newcommand{\begindapanhaiba}{

\@ifnextchar\True

\begin{minipage}[t]{\widthalpha}
\TrueEX

\end{minipage}

\begin{minipage}[t]{0.67\dorong}

\xdef\saveFileAns{\Alph{dapan}}%

\xdef\keyEX{\Alph{dapan}}%

\begin{minipage}[t]{\widthalpha}

\FalseEX

\end{minipage}

\begin{minipage}[t]{0.67\dorong}

\newcommand{\begindapanTFt}{%

\@ifnextchar\True

\begin{minipage}[t]{\widthalpha}

\TrueTF

\end{minipage}

\begin{minipage}[t]{\dorong}

\ifnum\chType=1

\xdef\saveFileAns{\saveFileAns\string\circT{\DapAnTF}}%

\ifnum\thedapan=1 \xdef\keyEX{\DapAnTF\ đúng}

\else \xdef\keyEX{\keyEX\ \big| \DapAnTF\ đúng} \fi%

\else

\xdef\saveFileAns{\Alph{dapan}}%

\xdef\keyEX{\Alph{dapan}}%

\fi%
}

\begin{minipage}[t]{\widthalpha}

\FalseTF

\end{minipage}

\begin{minipage}[t]{\dorong}

\ifnum\chType=1

\xdef\saveFileAns{\saveFileAns\string\circF{\DapAnTF}}%

\ifnum\thedapan=1 \xdef\keyEX{\keyEX\DapAnTF\ sai}

\else \xdef\keyEX{\keyEX\ \big| \DapAnTF\ sai} \fi%

\fi%

\newcommand{\boncot}[4]{%

\picinpar

\setlength{\dorong}{0.25\linewidth-0.005\dorongfix-\widthalpha-3\fboxsep}

\par\setcounter{dapan}{0}%

\ifnum\chType<1

\setcounter{numTrue}{0}%

\setcounter{numTrueSol}{0}%

\fi%

\noindent\hspace{0.02\dorongfix}\begindapan

#1\dotEX\strut

\end{minipage}

\noindent\begindapan

#2\dotEX\strut

\end{minipage}

\noindent\begindapan
#3\dotEX\strut

\end{minipage}

\noindent\begindapan

#4\dotEX\strut

\end{minipage}

%%%%

\def\parskipchoice{0cm}

\newcommand{\haicot}[4]{%

\picinpar

\setlength{\dorong}{0.5\linewidth-0.01\dorongfix-\widthalpha-3\fboxsep}

\par\setcounter{dapan}{0}%

\ifnum\chType<1

\setcounter{numTrue}{0}%

\setcounter{numTrueSol}{0}%

\fi%

\noindent\hspace{0.02\dorongfix}\begindapan

#1\dotEX\strut\ignorespaces

\end{minipage}

\noindent\begindapan

#2\dotEX\strut\ignorespaces

\end{minipage}

\par\setlength{\parskip}{\parskipchoice}

\noindent\hspace{0.02\dorongfix}\begindapan

#3\dotEX\strut\ignorespaces

\end{minipage}

\noindent\begindapan
#4\dotEX\strut\ignorespaces

\end{minipage}

\newcommand{\motcot}[4]{%

\picinpar

\setlength{\dorong}{\linewidth-0.02\dorongfix-\widthalpha-3\fboxsep}

\par

\setcounter{dapan}{0}%

\ifnum\chType<1

\setcounter{numTrue}{0}%

\setcounter{numTrueSol}{0}%

\fi%

\noindent\hspace{0.02\dorongfix}\begindapan

#1\dotEX\strut\ignorespaces

\end{minipage}

\par\setlength{\parskip}{\parskipchoice}

\noindent\hspace{0.02\dorongfix}\begindapan

#2\dotEX\strut\ignorespaces

\end{minipage}

\par\setlength{\parskip}{\parskipchoice}

\noindent\hspace{0.02\dorongfix}\begindapan

#3\dotEX\strut\ignorespaces

\end{minipage}

\par\setlength{\parskip}{\parskipchoice}

\noindent\hspace{0.02\dorongfix}\begindapan

#4\dotEX\strut\ignorespaces

\end{minipage}
}

%%%%%%%Tự động chọn \motcot, \haicot, \boncot

\newlength\widthcha

\newlength\widthchb

\newlength\widthchc

\newlength\widthchd

\newlength\widthche

\newlength\widthch

\newlength\tabmaxwidth

\newlength\fourthtabwidth

\newlength\halftabwidth

\newlength\fifthtabwidth

\newlength\thirdtabwidth

%Tìm chỗ \def\multichoice{0}% Có được chọn nhiều hơn 1 PA hay không.

\newcommand{\choice}[5][0]{%

\gdef\chType{0}\setcounter{dapan}{0}%

%Tương thích môi trường {center}

\let\originalcenter\center%

\let\originalendcenter\endcenter%

\renewenvironment{center}%

{\par\centering\bgroup}%

{\egroup\par}%

\setlength\tabmaxwidth{\linewidth-0.02\dorongfix-\widthalpha-3\fboxsep}

\setlength\fourthtabwidth{0.25\linewidth-0.005\dorongfix-\widthalpha-3\fboxsep}

\setlength\halftabwidth{0.5\linewidth-0.01\dorongfix-\widthalpha-3\fboxsep}

\settowidth\widthcha{#2\dotEX}
\ifdim\widthch<\widthcha\relax\setlength{\widthch}{\widthcha}\fi%

\settowidth\widthchb{#3\dotEX}%

\ifdim\widthch<\widthchb\relax\setlength{\widthch}{\widthchb}\fi%

\settowidth\widthchc{#4\dotEX}%

\ifdim\widthch<\widthchc\relax\setlength{\widthch}{\widthchc}\fi%

\settowidth\widthchd{#5\dotEX}%

\ifdim\widthch<\widthchd\relax\setlength{\widthch}{\widthchd}\fi%

\ifthenelse{\equal{#1}{0}}

\ifdim\widthch<\fourthtabwidth

\boncot{#2}{#3}{#4}{#5}

\else\ifdim\widthch<\halftabwidth

\haicot{#2}{#3}{#4}{#5}

\else

\motcot{#2}{#3}{#4}{#5}

\fi\fi

\ifthenelse{\equal{#1}{1}}

\def\parskipchoice{0.2cm}

\motcot{#2}{#3}{#4}{#5}}

\ifthenelse{\equal{#1}{2}}

\def\parskipchoice{0.2cm}

\haicot{#2}{#3}{#4}{#5}}

{
\ifthenelse{\equal{#1}{4}}

\def\parskipchoice{0.2cm}

\boncot{#2}{#3}{#4}{#5}}

\def\parskipchoice{#1}

\ifdim\widthch<\fourthtabwidth

\boncot{#2}{#3}{#4}{#5}

\else\ifdim\widthch<\halftabwidth

\haicot{#2}{#3}{#4}{#5}

\else

\motcot{#2}{#3}{#4}{#5}

\fi\fi

}}}}%

%Trả lại định nghĩa gốc môi trường {center}

\let\center\originalcenter%

\let\endcenter\originalendcenter%

%\choicen

%Tìm chỗ \def\multichoice{0}% Có được chọn nhiều hơn 1 PA hay không.

\makeatletter

\newcommand{\choicen}[1][1]{%

\gdef\chType{0}\picinpar%

\setcounter{dapan}{0}%

\ifint{#1}{%

\setlength{\dorong}{\linewidth/#1-0.02\dorongfix/#1-\widthalpha-3\fboxsep}

\setcounter{debai}{1}

\writerowChn[#1]}
{\Error}%

\newcommand{\writerowChn}[2][1]{%

\setlength{\parskip}{\parskipchoice}%

\ifnum\thedebai=1\par\noindent\hspace{0.02\dorongfix}\fi

\stepcounter{debai}%

\ifnum\thedebai>#1\setcounter{debai}{1}\fi%

\begindapan

#2\dotEX\strut

\end{minipage}

\@ifnextchar\bgroup{\writerowChn[#1]}{\par}

%Trắc nghiệm 5 lựa chọn

\newcommand{\nammot}[5]{%

\picinpar

\setlength{\dorong}{0.2\linewidth-0.022\dorongfix-2\fboxsep-\widthalpha}

\par\gdef\chType{0}\setcounter{dapan}{0}%

\noindent\hspace{0.02\dorongfix}\begindapan

#1\dotEX

\end{minipage}

\noindent\begindapan

#2\dotEX

\end{minipage}

\noindent\begindapan

#3\dotEX

\end{minipage}

\noindent\begindapan

#4\dotEX
\end{minipage}

\noindent\begindapan

#5\dotEX

\end{minipage}

\newcommand{\bahai}[5]{%

\picinpar\gdef\chType{0}\setcounter{dapan}{0}%

\setlength{\dorong}{0.5\linewidth-0.02\dorongfix-\fboxsep-3\widthalpha}

\par\noindent\hspace{0.02\dorongfix}\begindapanhaiba

#1\dotEX

\end{minipage}

\noindent\begindapanhaiba

#2\dotEX

\end{minipage}

\noindent\begindapanhaiba

#3\dotEX

\end{minipage}

\par\noindent\hspace{0.02\dorongfix}\begindapan

#4\dotEX

\end{minipage}

\noindent\begindapan

#5\dotEX

\end{minipage}

\newcommand{\haiba}[5]{%
\picinpar\gdef\chType{0}\setcounter{dapan}{0}%

\setlength{\dorong}{0.5\linewidth-0.02\dorongfix-\fboxsep-3\widthalpha}

\par\noindent\hspace{0.02\dorongfix}\begindapan

#1\dotEX

\end{minipage}

\noindent\begindapan

#2\dotEX

\end{minipage}

\par\noindent\hspace{0.02\dorongfix}\begindapanhaiba

#3\dotEX

\end{minipage}

\noindent\begindapanhaiba

#4\dotEX

\end{minipage}

\noindent\begindapanhaiba

#5\dotEX

\end{minipage}

\newcommand{\motnam}[5]{%

\picinpar\gdef\chType{0}\setcounter{dapan}{0}%

\setlength{\dorong}{\linewidth-0.02\dorongfix-\fboxsep-2\widthalpha}

\par

\noindent\hspace{0.02\dorongfix}\begindapan

#1\dotEX\strut

\end{minipage}

\par\noindent\hspace{0.02\dorongfix}\begindapan

#2\dotEX\strut
\end{minipage}

\par\noindent\hspace{0.02\dorongfix}\begindapan

#3\dotEX\strut

\end{minipage}

\par\noindent\hspace{0.02\dorongfix}\begindapan

#4\dotEX\strut

\end{minipage}

\par\noindent\hspace{0.02\dorongfix}\begindapan

#5\dotEX\strut

\end{minipage}

\newlength\wmothai

\newlength\wmothaiba

\newlength\wmothaibabon

\newlength\wbonnam

\newlength\wbabonnam

\newlength\whaibabonnam

\newcounter{numChoice}

\newcommand{\choicefive}[5]{%

\gdef\chType{0}\setcounter{dapan}{0}%

\setlength\tabmaxwidth{\linewidth-\picwd-\lwindowsep}

\setlength\fourthtabwidth{0.25\linewidth-0.25\picwd-0.25\lwindowsep-\widthalpha}

\setlength\halftabwidth{0.5\linewidth-0.5\picwd-0.5\lwindowsep-\widthalpha}

\setlength\fifthtabwidth{0.2\linewidth-0.2\picwd-0.2\lwindowsep-\widthalpha}

\setlength\thirdtabwidth{0.33\linewidth-0.33\picwd-0.33\lwindowsep-\widthalpha}

\settowidth\widthcha{AM.#1}

\ifdim\widthch<\widthcha\relax\setlength{\widthch}{\widthcha}\fi%
\ifdim\wmothai<\widthcha\relax\setlength{\wmothai}{\widthcha}\fi%

\ifdim\wmothaiba<\widthcha\relax\setlength{\wmothaiba}{\widthcha}\fi%

\ifdim\wmothaibabon<\widthcha\relax\setlength{\wmothaibabon}{\widthcha}\fi%

\settowidth\widthchb{BM.#2}%

\ifdim\widthch<\widthchb\relax\setlength{\widthch}{\widthchb}\fi%

\ifdim\wmothai<\widthchb\relax\setlength{\wmothai}{\widthchb}\fi%

\ifdim\wmothaiba<\widthchb\relax\setlength{\wmothaiba}{\widthchb}\fi%

\ifdim\wmothaibabon<\widthchb\relax\setlength{\wmothaibabon}{\widthchb}

\fi%

\ifdim\whaibabonnam<\widthchb\relax\setlength{\whaibabonnam}{\widthchb}

\fi%

\settowidth\widthchc{CM.#3}%

\ifdim\widthch<\widthchc\relax\setlength{\widthch}{\widthchc}\fi%

\ifdim\wmothaiba<\widthchc\relax\setlength{\wmothaiba}{\widthchc}\fi%

\ifdim\wmothaibabon<\widthchc\relax\setlength{\wmothaibabon}{\widthchc}\fi%

\ifdim\wbabonnam<\widthchc\relax\setlength{\wbabonnam}{\widthchc}\fi%

\ifdim\whaibabonnam<\widthchc\relax\setlength{\whaibabonnam}{\widthchc}

\fi%

\settowidth\widthchd{DM.#4}%

\ifdim\widthch<\widthchd\relax\setlength{\widthch}{\widthchd}\fi%

\ifdim\wmothaibabon<\widthchd\relax\setlength{\wmothaibabon}{\widthchd}\fi%

\ifdim\wbabonnam<\widthchd\relax\setlength{\wbabonnam}{\widthchd}\fi%

\ifdim\wbonnam<\widthchd\relax\setlength{\wbonnam}{\widthchd}\fi%

\ifdim\whaibabonnam<\widthchd\relax\setlength{\whaibabonnam}{\widthchd}

\fi%

\settowidth\widthche{EM.#5}%

\ifdim\widthch<\widthche\relax\setlength{\widthch}{\widthche}\fi%

\ifdim\wbabonnam<\widthche\relax\setlength{\wbabonnam}{\widthche}\fi%
\ifdim\wbonnam<\widthche\relax\setlength{\wbonnam}{\widthche}\fi%

\ifdim\whaibabonnam<\widthchd\relax\setlength{\whaibabonnam}{\widthchd}

\fi%

%Khởi tạo điều kiện

\setcounter{numChoice}{0}

\ifdim\wmothai<\halftabwidth

\ifdim\wbabonnam<\thirdtabwidth

\setcounter{numChoice}{1}

\fi\fi

\ifdim\wmothaiba<\thirdtabwidth

\ifdim\wbonnam<\halftabwidth

\setcounter{numChoice}{2}

\fi\fi

\ifdim\widthch<\fifthtabwidth

\setcounter{numChoice}{3}

\fi

%Lựa chọn cách sắp xếp

\ifnum\the\value{numChoice}=3

\nammot{#1}{#2}{#3}{#4}{#5}

\else

\ifnum\the\value{numChoice}=2

\bahai{#1}{#2}{#3}{#4}{#5}

\else

\ifnum\the\value{numChoice}=1

\haiba{#1}{#2}{#3}{#4}{#5}

\else

\motnam{#1}{#2}{#3}{#4}{#5}

\fi\fi\fi
}

%%============= CÁC LỆNH MỚI =============

%\choiceTF

\def\tickT{X} % Chỗ này dùng để định nghĩa dấu tick đúng hoặc sai

\def\tickF{X}

\gdef\TrueX{}\gdef\FalseX{\tickF}

\let\tabcolsep\undefined %Hủy \command\tabcolsep để tạo thành length

\newlength{\tabcolsep}

\let\TabCOLSEP\tabcolsep

\setlength{\TabCOLSEP}{1.5mm}

\newtoggle{InMulticols}\togglefalse{InMulticols}

\AtBeginEnvironment{multicols}{\toggletrue{InMulticols}}

\AtEndEnvironment{multicols}{\togglefalse{InMulticols}}

\newtoggle{InParacol}\togglefalse{InParacol}

\AtBeginEnvironment{paracol}{\toggletrue{InParacol}}

\AtEndEnvironment{paracol}{\togglefalse{InParacol}}

\makeatletter

\newlength\lengthDS

\newcommand{\boldTF}{\bf}

\define@key{optn}{dapanTF}{\def\dapanTF{#1}}

\define@key{optn}{kindTF}{\def\kindTF{#1}%

\ifthenelse{\equal{#1}{t0}}{\def\kindTF{t}\def\cotDS{0}}{}%

\define@key{optn}{boldTF}{%

\ifthenelse{\equal{#1}{0}}

{\renewcommand{\boldTF}{}}

{\renewcommand{\boldTF}{\bf}}%

}
\define@key{optn}{phatbieu}{\def\phatbieu{#1}}

\define@key{optn}{viettat}{\def\viettat{#1}}

\define@key{optn}{cotDS}{\def\cotDS{#1}}% dùng để ẩn hiện cột đánh dấu Đúng/Sai

\define@key{optn}{sepTF}{\def\sepTF{#1}}% dấu ngăn cách cho abcd với phát biểu Đ/S

\newcommand{\TFOPTN}[1]{%

\setkeys{optn}{#1}%

\ifthenelse{\equal{\viettat}{0}}

{\def\Dung{Đúng}\def\Sai{Sai}\setlength{\lengthDS}{11mm}}

{\def\Dung{Đ}\def\Sai{S}\setlength{\lengthDS}{5.5mm}}%

\IfSubStr{#1}{sepTF}{%

\ifthenelse{\equal{\dapanTF}{A}}

{\renewcommand{\DapAnTF}{\Alph{dapan}}}

{\ifthenelse{\equal{\dapanTF}{1}}

{\renewcommand{\DapAnTF}{\arabic{dapan}}}

{\renewcommand{\DapAnTF}{\alph{dapan}}}}%

}{%

\ifthenelse{\equal{\dapanTF}{A}}

{\renewcommand{\DapAnTF}{\Alph{dapan}}\def\sepTF{.}}

{\ifthenelse{\equal{\dapanTF}{1}}

{\renewcommand{\DapAnTF}{\arabic{dapan}}\def\sepTF{)}}

{\renewcommand{\DapAnTF}{\alph{dapan}}\def\sepTF{)}}}%

\TFOPTN{kindTF=,dapanTF=a,cotDS=1,boldTF=1,phatbieu=Phát biểu,viettat=1}

\makeatletter

\newcommand{\callcotDS}{}

\newcommand{\choiceTF}[5][0cm]{%

\gdef\chType{1}\callcotDS%
%Tương thích môi trường {center}

\let\originalcenter\center%

\let\originalendcenter\endcenter%

\xdef\sdotEX{\dotEX}

\renewenvironment{center}%

{\xdef\dotEX{}%

\par\centering\bgroup}%

{\egroup\par}%

\ifthenelse{\equal{\kindTF}{0}}

{\choiceTFfix[#1]{#2}{#3}{#4}{#5}}

{\ifthenelse{\equal{\kindTF}{1t}}

{\motbang{#2}{#3}{#4}{#5}}

{\ifthenelse{\equal{\kindTF}{2t} \OR \equal{#1}{tt}}

{\haibang{#2}{#3}{#4}{#5}}

{\ifthenelse{\equal{\kindTF}{t}}

{\settowidth\widthcha{#2\dotEX}%

\ifdim\widthch<\widthcha\relax\setlength{\widthch}{\widthcha}\fi%

\settowidth\widthchb{#3\dotEX}%

\ifdim\widthch<\widthchb\relax\setlength{\widthch}{\widthchb}\fi%

\settowidth\widthchc{#4\dotEX}%

\ifdim\widthch<\widthchc\relax\setlength{\widthch}{\widthchc}\fi%

\settowidth\widthchd{#5\dotEX}%

\ifdim\widthch<\widthchd\relax\setlength{\widthch}{\widthchd}\fi%

\ifnum\cotDS=1%

\setlength\halftabwidth{0.5\linewidth-\widthalpha-6\tabcolsep-15mm-2\fboxsep}

\else%

\setlength\halftabwidth{0.5\linewidth-\widthalpha-2\tabcolsep-7mm-0\fboxsep}
\fi%

\ifdim\widthch<\halftabwidth

\haibang{#2}{#3}{#4}{#5}

\else \motbang{#2}{#3}{#4}{#5}

\fi}

{\ifthenelse{\equal{#1}{t}}

{\settowidth\widthcha{#2\dotEX}%

\ifdim\widthch<\widthcha\relax\setlength{\widthch}{\widthcha}\fi%

\settowidth\widthchb{#3\dotEX}%

\ifdim\widthch<\widthchb\relax\setlength{\widthch}{\widthchb}\fi%

\settowidth\widthchc{#4\dotEX}%

\ifdim\widthch<\widthchc\relax\setlength{\widthch}{\widthchc}\fi%

\settowidth\widthchd{#5\dotEX}%

\ifdim\widthch<\widthchd\relax\setlength{\widthch}{\widthchd}\fi%

\ifnum\cotDS=1%

\setlength\halftabwidth{0.5\linewidth-\widthalpha-6\tabcolsep-15mm-2\fboxsep}

\else%

\setlength\halftabwidth{0.5\linewidth-\widthalpha-2\tabcolsep-7mm-0\fboxsep}

\fi%

\ifdim\widthch<\halftabwidth

\haibang{#2}{#3}{#4}{#5}

\else \motbang{#2}{#3}{#4}{#5}

\fi}

{\ifthenelse{\equal{#1}{1t}}

{\motbang{#2}{#3}{#4}{#5}}

{\ifthenelse{\equal{#1}{2t} \OR \equal{#1}{tt}}

{\haibang{#2}{#3}{#4}{#5}}

{\choiceTFfix[#1]{#2}{#3}{#4}{#5}}}}}}}}%\medskip%
%Trả lại định nghĩa gốc môi trường {center}

\let\center\originalcenter%

\let\endcenter\originalendcenter%

\newcommand{\ifInMulticol}[2]{%

\iftoggle{InMulticols}{#1}{%

\iftoggle{InParacol}{#1}{#2}}%

\newcommand{\writerowTF}[1]{%

\hline\rule[0pt]{0pt}{14pt}%

\xdef\dotEX{\sdotEX}%

\ifnum\cotDS=1%

\ifnum\thedapan=0 \writekeyTFone \fi%

\noindent\hspace{-1.3mm}\begindapanTFt%

#1\dotEX\strut%

\end{minipage}\vspace{1pt}%

\writekeyTF\\

\else%

\ifnum\thedapan=0 \writekeyTFone \fi%

\noindent\hspace{-1.3mm}\begindapanTFt%

#1\dotEX\strut%

\end{minipage}\vspace{1pt}%

\\

\fi%

\newcommand{\writekeyTFone}{\gdef\TrueX{}\gdef\FalseX{}}

\newcommand{\writekeyTF}{&&}

\newcommand{\STF}{{\bf\large\color{red}
Lệnh này giờ vô dụng vì đã có lệnh khác linh hoạt hơn.\\\noindent Hãy đổi lệnh lại thành {\
color{blue}\string\TFOPTN\{kindTF=0\}}

}}

\newcommand{\standardchoiceTF}{{\bf\large\color{red}

Lệnh này giờ vô dụng vì đã có lệnh khác linh hoạt hơn.\\\noindent Hãy đổi lệnh lại thành {\
color{blue}\string\TFOPTN\{kindTF=0\}}

}}

\newcommand{\choiceTFfix}[5][0cm]{%

\gdef\chType{1}%

\setlength\tabmaxwidth{\linewidth-0.02\dorongfix-\widthalpha-3\fboxsep}

\setlength\fourthtabwidth{0.25\linewidth-0.02\dorongfix-\widthalpha-3\fboxsep}

\setlength\halftabwidth{0.5\linewidth-0.02\dorongfix-\widthalpha-3\fboxsep}

\settowidth\widthcha{#2\dotEX}%

\ifdim\widthch<\widthcha\relax\setlength{\widthch}{\widthcha}\fi%

\settowidth\widthchb{#3\dotEX}%

\ifdim\widthch<\widthchb\relax\setlength{\widthch}{\widthchb}\fi%

\settowidth\widthchc{#4\dotEX}%

\ifdim\widthch<\widthchc\relax\setlength{\widthch}{\widthchc}\fi%

\settowidth\widthchd{#5\dotEX}%

\ifdim\widthch<\widthchd\relax\setlength{\widthch}{\widthchd}\fi%

\def\parskipchoice{0.1cm}

\ifthenelse{\equal{#1}{1}}

{\motcot{#2}{#3}{#4}{#5}}

{\ifthenelse{\equal{#1}{2}}

{\haicot{#2}{#3}{#4}{#5}}

{\ifthenelse{\equal{#1}{4}}

{\boncot{#2}{#3}{#4}{#5}}
{\ifthenelse{\equal{#1}{t} \OR \equal{#1}{1t} \OR \equal{#1}{2t} \OR \equal{#1}{tt} \OR \
equal{#1}{} \OR \equal{#1}{0}}{}

{\def\parskipchoice{#1}}

\ifdim\widthch<\fourthtabwidth

\boncot{#2}{#3}{#4}{#5}

\else\ifdim\widthch<\halftabwidth

\haicot{#2}{#3}{#4}{#5}

\else\motcot{#2}{#3}{#4}{#5}

\fi\fi}}}

\newcommand{\motbang}[4]{%

\gdef\TrueX{}\gdef\FalseX{}%

\ifnum\cotDS=1%

\setlength{\dorong}{\linewidth-\widthalpha-6\tabcolsep-2\lengthDS-7mm-2\fboxsep}%

\else%

\setlength{\dorong}{\linewidth-\widthalpha-2\tabcolsep-7mm-2\fboxsep}%

\fi%

\ifInMulticol

{\par\medskip\hfill\xentrystretch{-0.15}%

\ifnum\cotDS=1%

\begin{xtabular}{|m{\linewidth-6\tabcolsep-2\lengthDS-7mm}|m{\lengthDS}|
m{\lengthDS}|}

\else%

\begin{xtabular}{|m{\linewidth-2\tabcolsep-7mm}|}

\fi}

{\ifnum\cotDS=1%

\begin{longtable}{|m{\linewidth-6\tabcolsep-2\lengthDS-7mm}|m{\lengthDS}|m{\
lengthDS}|}

\else%
\begin{longtable}{|m{\linewidth-2\tabcolsep-7mm}|}

\fi}

\ifnum\cotDS=1%

\hline\centering{\boldTF\phatbieu} & \centering{\boldTF\Dung} & \centering{\


boldTF\Sai}\tabularnewline%

\else%

\hline\centering{\boldTF\phatbieu} \tabularnewline%

\fi

\ifInMulticol{}{\endhead}%

\writerowTF{#1}

\writerowTF{#2}

\writerowTF{#3}

\writerowTF{#4}

\hline

\ifInMulticol

{\end{xtabular}\par}

{\end{longtable}\vspace{-\baselineskip}}

\medskip%

\newcommand{\haibang}[4]{%

\ifInMulticol

{{\bf\large\color{red}Trong môi trường chia cột, tùy chọn tách đôi bảng của \string\choiceTF
không hoạt động. Bạn kiểm tra lại nhé!}}

{\gdef\TrueX{}\gdef\FalseX{}%

\ifnum\cotDS=1%

\setlength{\dorong}{0.5\linewidth-\widthalpha-6\tabcolsep-2\lengthDS-7mm-
2\fboxsep}%

\else%

\setlength{\dorong}{0.5\linewidth-\widthalpha-2\tabcolsep-7mm-2\fboxsep}%
\fi%

\par\noindent

\begin{minipage}[t][][b]{0.5\textwidth}

\vspace{-\baselineskip}

\ifnum\cotDS=1%

\begin{longtable}{|m{\linewidth-6\tabcolsep-2\lengthDS-7mm}|m{\
lengthDS}|m{\lengthDS}|}

\hline\centering{\boldTF\phatbieu} & \centering{\boldTF\Dung}


& \centering{\boldTF\Sai}\tabularnewline%

\else%

\begin{longtable}{|m{\linewidth-2\tabcolsep-7mm}|}

\hline\centering{\boldTF\phatbieu}\tabularnewline

\fi%

\ifInMulticol{}{\endhead}%

\writerowTF{#1}

\writerowTF{#2}

\hline

\end{longtable}\vspace{-\baselineskip}

\end{minipage}

\begin{minipage}[t][][b]{0.5\textwidth}

\vspace{-\baselineskip}

\ifnum\cotDS=1%

\begin{longtable}{|m{\linewidth-6\tabcolsep-2\lengthDS-7mm}|m{\
lengthDS}|m{\lengthDS}|}

\hline\centering{\boldTF\phatbieu} & \centering{\boldTF\Dung}


& \centering{\boldTF\Sai}\tabularnewline%

\else%

\begin{longtable}{|m{\linewidth-2\tabcolsep-7mm}|}

\hline\centering{\boldTF\phatbieu}\tabularnewline
\fi%

\ifInMulticol{}{\endhead}%

\writerowTF{#3}

\writerowTF{#4}

\hline

\end{longtable}\vspace{-\baselineskip}

\end{minipage}

\par\medskip}%

%\choiceTFn

\makeatletter

\newcommand{\choiceTFn}[1][1]{%

\gdef\chType{1}\picinpar

\setcounter{dapan}{0}

\ifint{#1}{%

\setlength{\dorong}{\linewidth/#1-0.02\dorongfix-\widthalpha-3.5\fboxsep}

\setcounter{debai}{1}

\writerowTFn[#1]}

{\Error}%

\newcommand{\Error}[2][]{%

\@ifnextchar\bgroup{\Error}{%

\par\centering{\bf\color{red}Tùy chọn số cột phải là 1 số nguyên dương!}}

\newcommand{\writerowTFn}[2][1]{%

\setlength{\parskip}{\parskipchoice}

\ifnum\thedebai=1\par\noindent\fi%

\stepcounter{debai}%
\ifnum\thedebai>#1\setcounter{debai}{1}\fi%

\hspace{0.02\dorongfix}\begindapan%

#2\dotEX\strut%

\end{minipage}%

\@ifnextchar\bgroup{\writerowTFn[#1]}{\par}

%\choiceTFt

\makeatletter

\newcommand{\choiceTFt}[1][]{%

\gdef\chType{1}%

\gdef\TrueX{}\gdef\FalseX{}%

\setlength{\dorong}{\linewidth-\widthalpha-6\TabCOLSEP-2\lengthDS-5.8mm-2\fboxsep}%

\ifthenelse{\equal{#1}{}}{}{\renewcommand{\arraystretch}{#1}}%

\ifInMulticol

{\par\medskip\hfill\xentrystretch{-0.15}%

\begin{xtabular}{|m{\linewidth-2\lengthDS-15mm}|m{\lengthDS}|m{\lengthDS}|}}

{\begin{longtable}{|m{\linewidth-2\lengthDS-15mm}|m{\lengthDS}|m{\lengthDS}|}}

\hline\centering{\boldTF\phatbieu} & \centering{\boldTF\Dung} & \centering{\boldTF\


Sai}\tabularnewline%

\ifInMulticol{}{\endhead}%

\writerowTFt

\newcommand{\writerowTFt}[1]{%

\hline\rule[0pt]{0pt}{14pt}%

\ifnum\thedapan=0 \writekeyTFone \fi%

\noindent\hspace{-1.3mm}\begindapanTFt

#1\dotEX\strut%
\end{minipage}\vspace{1pt}

\writekeyTF

\@ifnextchar\bgroup{\tabularnewline\writerowTFt}{\tabularnewline\hline%

\ifInMulticol

{\end{xtabular}\par}%

{\end{longtable}\vspace{-\baselineskip}}%

\medskip}

%\shortans

\makeatletter

\def\applykindSA{1} % Chuẩn bị ĐK để áp dụng \kindSA

\def\kindSAapply{} % Để ưu tiên sử dụng khi \hideansEX

\define@key{optn}{kindSA}{\ifnum\applykindSA=1 \def\kindSA{#1} \fi}

\define@key{optn}{ketquaSA}{\def\ketqua{#1}\def\ketquaSA{\ketqua}}

\define@key{optn}{widthSA} {\def\SAwidth{#1}\def\widthSA{\SAwidth}}

\define@key{optn}{heightSA}{\def\SAheight{#1}\def\heightSA{\SAheight}}

\define@key{optn}{dapanSA}{\def\dapanSA{#1}}

\newcommand{\SAOPTN}[1]{%

\setkeys{optn}{#1}%

\renewcommand{\chooseNSA}{\xdef\kindSA{\kindSAapply}}

\ifthenelse{\equal{\dapanSA}{A}}

{\renewcommand{\DapAnSA}{\Alph{dapan}}}

{\ifthenelse{\equal{\dapanSA}{1}}

{\renewcommand{\DapAnSA}{\arabic{dapan}}}

{\renewcommand{\DapAnSA}{\alph{dapan}}}}%

\SAOPTN{kindSA=,ketquaSA=KQ:,widthSA=4,heightSA=0.9,dapanSA=a}

\makeatletter
% Command to clean the string

\newcommand{\cleanstring}[1]{%

\StrSubstitute{#1}{ }{}[\cleaned]% Remove spaces

% \StrSubstitute{\cleaned}{$}{}[\cleaned]%

% Command to check if the string contains only valid characters

\newcommand{\isvalidstring}[1]{%

\StrSubstitute{#1}{ }{}[\temp]% Remove spaces

\StrSubstitute{\temp}{-}{}[\temp]% Remove minus signs

\StrSubstitute{\temp}{{,}}{}[\temp]% Remove opening curly braces

\StrSubstitute{\temp}{,}{}[\temp]% Remove commas

\StrSubstitute{\temp}{0}{}[\temp]% Remove digits

\StrSubstitute{\temp}{1}{}[\temp]%

\StrSubstitute{\temp}{2}{}[\temp]%

\StrSubstitute{\temp}{3}{}[\temp]%

\StrSubstitute{\temp}{4}{}[\temp]%

\StrSubstitute{\temp}{5}{}[\temp]%

\StrSubstitute{\temp}{6}{}[\temp]%

\StrSubstitute{\temp}{7}{}[\temp]%

\StrSubstitute{\temp}{8}{}[\temp]%

\StrSubstitute{\temp}{9}{}[\temp]%

\IfEq{\temp}{}{\validtrue}{\validfalse}% Check if remaining string is empty

\newif\ifvalid

\validfalse

\newcommand{\TachO}[1]{%

\isvalidstring{#1}%

\ifvalid%
\cleanstring{#1}% Clean the input string

\StrLen{\cleaned}[\length]% Get the length of the cleaned string

\ifnum\length<5%

\begin{tabular}{|m{2.5mm}|m{2.5mm}|m{2.5mm}|m{2.5mm}|}

\hline%

\ifnum\length>0 \StrChar{\cleaned}{1}[\firstchar]\centering $\
firstchar$ \fi &%

\ifnum\length>1 \StrChar{\cleaned}{2}[\secondchar]\centering
$\secondchar$ \fi &%

\ifnum\length>2 \StrChar{\cleaned}{3}[\thirdchar]\centering $\
thirdchar$ \fi &%

\ifnum\length>3 \StrChar{\cleaned}{4}[\fourthchar]\centering
$\fourthchar$ \fi \tabularnewline%

\hline%

\end{tabular}%

\else #1 \fi%

\else #1 \fi%

\makeatletter

\newcommand{\SA}[2][]{\shortans[#1]{#2}}

\newcommand{\ifInList}[2]{\ifnumgreater{\@listdepth}{0}{#1}{#2}}

\newcommand{\oKQ}[2][]{%

\ifthenelse{\equal{#1}{}}

{\raisebox{0pt}{\tikz[baseline=(char.base)]{\node (char)[left]{\ketquaSA};

\draw[rounded corners=2pt] (0,-0.5*\heightSA) rectangle (#2,0.5*\heightSA);}}}

{\ifthenelse{\equal{#1}{oly}}

{\raisebox{0pt}{\tikz[baseline=(char.base)]{\node (char)[left]{\ketquaSA};

\foreach \i in {1,...,#2}{\draw (0.75*\i-0.75,-0.35)rectangle(0.75*\


i,0.35);}}}}
{\ifthenelse{\equal{#1}{...}}

{\raisebox{0pt}{\tikz[baseline=(char.base)]{\node (char)[left]{\
ketquaSA};

\clip[rounded corners=2pt] (0,-0.4*\heightSA) rectangle


(#2,0.6*\heightSA);

\node (char)[right,yshift=-2]{\ldots\ldots\ldots\ldots\ldots\
ldots\ldots\ldots};}}}

{}}}%

\newcommand{\shortans}[2][]{%

\gdef\chType{-1}%

\ifthenelse{\equal{\kindSA}{}}

{\shortansfix[#1]{\TachO{#2}}}

{\ifthenelse{\equal{\kindSA}{ShowSAKeyColor}}

{\hfill\raisebox{0pt}{\tikz[baseline=(char.base)]{%

\node (char)[rectangle,inner sep=2pt,rounded corners=2pt,fill=yellow!


50,draw=red]{\color{red}~\selectshortans\ \TachO{#2}\phantom{~}};}}%

\ifInList{\hspace{-2mm}}{\par}}

{\ifthenelse{\equal{\kindSA}{ShowSAKeyLG}}

{\hfill\raisebox{0pt}{\tikz[baseline=(char.base)]{%

\node (char)[rectangle,inner sep=2pt,rounded corners=2pt]{\


color{red}~\selectshortans\ \TachO{#2}\phantom{~}};}}%

\ifInList{\hspace{-2mm}}{\par}}

{\shortansfix[\kindSA]{\TachO{#2}}}%

}%

}%

\ifInList

{\stepcounter{dapan}\xdef\saveFileAns{\saveFileAns\ \string\circX{\DapAnSA} \detokenize{\


TachO{#2}}}}

{\xdef\saveFileAns{\detokenize{\TachO{#2}}}}%
}

\newcommand{\shortansfix}[2][]{%

\ifthenelse{\equal{#1}{0}}{}

{\ifthenelse{\equal{#1}{}}

{\hfill\oKQ{\widthSA}}

{\ifthenelse{\equal{#1}{oly}}

{\hfill\oKQ[oly]{4}}

{\ifthenelse{\equal{#1}{...}}

{\hfill\oKQ[...]{\widthSA}}

{\hfill\oKQ{#1}}}}%

\ifInList{\hspace{-1mm}}{\par}%

}%

\newcommand{\SSA}{\standardshortans}

\newcommand{\hideshortans}{\standardshortans}

\newcommand{\hideSA}{\standardshortans}

\newcommand{\standardshortans}{{\bf\large\color{red}

Lệnh này giờ vô dụng vì đã có lệnh khác linh hoạt hơn.\\\noindent Hãy đổi lệnh lại thành {\
color{blue}\string\SAOPTN\{kindSA=0\}}

}}

\newcommand{\NSA}{\normalshortans}

\newcommand{\normalshortans}{{\bf\large\color{red}

Lệnh này giờ vô dụng vì đã có lệnh khác linh hoạt hơn.\\\noindent Hãy đổi lệnh lại thành {\
color{blue}\string\SAOPTN\{kindSA=\}}

}}

%%Môi trường gõ Lời giải theo từng ý cho câu nhiều ý

\makeatletter
\newenvironment{itemchoice}[1][]

{\newcommand{\Eitem}{\itemch {\bf\color{blue}\mbox{\boldmath $\leftarrow$} Chỗ này gõ {\


Large\color{red}$\backslash$itemch} mới đúng, thiếu chữ {\LARGE\color{red}ch} rồi thầy cô!\\}}%

\newcommand{\Esubitemch}{\item {\bf\color{blue}\mbox{\boldmath $\leftarrow$} Chỗ


này gõ {\Large\color{red}$\backslash$item} mới đúng, dư chữ {\LARGE\color{red}ch} kìa thầy cô!\\}}%

\let\itemch\item\let\item\Eitem%

\ifthenelse{\equal{#1}{}}

{\ifnum\chType=1

\ifthenelse{\equal{\dapanTF}{1}}

{\begin{enumerate}[\bf 1\sepTF]}

{\ifthenelse{\equal{\dapanTF}{A}}

{\begin{enumerate}[\bf A\sepTF]}

{\begin{enumerate}[\bf a\sepTF]}}

\else\begin{enumerate}[\bf A.]\fi}

{\begin{enumerate}[\bf#1]}

\delError{itemize,enumerate,enumEX,listEX,center}%

{\AtBeginEnvironment{enumerate}{\let\itemch\item\let\item\Eitem}%

\end{enumerate}%

\AtBeginEnvironment{enumerate}{\let\Eitem\item}

\let\itemT\item

\newcommand{\delError}[1]{%

\foreach \xEnvN in {#1} {%

\AtBeginEnvironment{\xEnvN}{%

\let\item\itemT\let\itemch\Esubitemch%

}
}

\newcommand{\finditemchoice}{%

\renewenvironment{itemchoice}[1][]{%

\newcommand{\Eitem}{\itemch[\Large\bf\circEX{item}]}%

\newcommand{\Esubitemch}{\item[\large\bf\circEX{itemch}]}%

\let\itemch\item\let\item\Eitem%

\setlist[enumerate,1]{label=\bf\large\color{blue}itemch}

\begin{enumerate}

\delError{itemize,enumerate,enumEX,listEX,center}%

}{\AtBeginEnvironment{enumerate}{\let\itemch\item\let\item\Eitem}%

\end{enumerate}}

%%=====================================

\makeatletter

\newcommand{\defboxex}[1][]{

\ifthenelse{\equal{#1}{ex}}{\def\boxexcl{green!10}}{\def\boxexcl{yellow!10}}

\def\beginboxex{\begin{tcolorbox}[before skip=3.5mm,after skip=3.5mm,drop fuzzy shadow


southeast,colframe=black, colback=\boxexcl, breakable, enhanced, boxrule=0.45mm]

\tikzset{node style/.append style = {fill=\boxexcl,opacity=1}}

\tikzset{double style/.append style={double distance=1.6pt,double=\boxexcl}}}

\def\endboxex{\end{tcolorbox}}

\makeatletter

\@ifpackageloaded{tcolorbox}{%

\newcommand{\createbox}[1]{%

\AtBeginEnvironment{#1}{%

\defboxex[#1]%

\refstepcounter{#1}
\renewcommand{\Currentlabel}{\@currentlabel}%

\addtocounter{#1}{-1}%

\gdef\chType{0}\gdef\saveFileAns{}\gdef\keyEX{}%

\setcounter{dapan}{0}%

\setcounter{numTrueSol}{0}%

\setcounter{numChoice}{0}%

\beginboxex%

\AtEndEnvironment{#1}{\endboxex\def\endboxex{}}

}%

}{%

\newcommand{\createbox}[1]{{\noindent\bf\large\color{red}

\begin{itemize}

\item Gói lệnh {\color{blue}tcolorbox} cần được khai báo trước khi khai báo gói
ex-test.

\item Hãy tắt lệnh {\color{blue}\string\createbox\{\}} đi nếu bạn thấy không cần
thiết.

\item Hoặc bổ sung {\color{blue}\string\usepackage[most,xparse,many]\


{tcolorbox\}} vào dòng phía trên của dòng khai báo {\color{black}\string\usepackage[...]\{ex\_test\}}.

\end{itemize}

}}%

%%=====================================

\DeclareOption{solcolor}{

\renewcommand{\TF}[1]{\EXboxTF{\textbf{\colorEX#1}}}

\renewcommand{\boxEX}[2][9pt]{%

\setbox1=\hbox{#2}%

\def\sizeboxEX{#1}%
\ \EXbox{#2}\ %

\renewcommand{\sh}[1]{\text{#1}}

\makeatletter

\def\applykindSA{0} % Để huỷ áp dụng \kindSA

\def\colorEX{\color{red}}

\renewcommand{\TrueTF} {\stepcounter{dapan}\squareEX{\bf\DapAnTF}\ignorespaces}

\renewcommand{\TrueEX} {\stepcounter{dapan}\squareEX{\bf\Alph{dapan}}\ignorespaces}

\renewcommand{\True}{%

\ifnum\chType=0\setcounter{numTrue}{\thedapan}\setcounter{numTrueSol}{\
thedapan}%

\else \gdef\TrueX{\circEX{\tickT}}\gdef\FalseX{} \fi%

\leavevmode\colorEX%

%\choiceTF

\renewcommand{\callcotDS}{\def\cotDS{1}}%

\renewcommand{\writekeyTFone}{\gdef\TrueX{}\gdef\FalseX{\tickF}}

\renewcommand{\writekeyTF}{%

&\vspace{-1pt}\centering\leavevmode\TrueX%

&\vspace{-3pt}\parbox[t]{\linewidth}{\centering\leavevmode\FalseX}%

\gdef\TrueX{}\gdef\FalseX{\tickF}%

%\shortans

\def\kindSA{ShowSAKeyColor}

\showanswers

%Xuất hiện chữ Lời giải trong môi trường onlysolution

\renewcommand{\do@onlysolution}[1]{%

\par\noindent\textbf{\loigiaiEX}%
\ifshowanswers

\@ifnextchar\immini

{}

{ \@ifnextchar\begin

{}

{\par\noindent}

#1%

\fi

\ifthenelse{\equal{\keyEX}{}}{}

{\leavevmode\unskip\textchoice\ignorespaces\xdef\keyEX{}}%

\setcounter{numTrueSol}{0}%

\renewcommand{\loigiai}[1]{

\ifInTcolorbox \ifdef{\endboxex}{\endboxex\def\endboxex{}}{} \fi

\labelex

\def\labelex{}

\begin{onlysolution}

#1

\end{onlysolution}

\renewcommand{\exitshowansEX}[1]{}

\renewcommand{\exithideansEX}[1]{%

\makeatletter

\AtBeginEnvironment{#1}{%

\def\kindSA{ShowSAKeyColor}%

\def\colorEX{\color{red}}%
\renewcommand{\TrueTF} {\stepcounter{dapan}\squareEX{\bf\DapAnTF}\
ignorespaces}

\renewcommand{\TrueEX} {\stepcounter{dapan}\squareEX{\bf\Alph{dapan}}\
ignorespaces}

\renewcommand{\writekeyTFone}{\gdef\TrueX{}\gdef\FalseX{\tickF}}

\renewcommand{\writekeyTF}{%

&\vspace{-1pt}\centering\leavevmode\TrueX%

&\vspace{-3pt}\parbox[t]{\linewidth}{\centering\leavevmode\FalseX}%

\gdef\TrueX{}\gdef\FalseX{\tickF}%

\renewcommand{\loigiai}[1]{%

\ifInTcolorbox \ifdef{\endboxex}{\endboxex\def\endboxex{}}{} \fi

\labelex

\def\labelex{}

\begin{onlysolution}

##1

\end{onlysolution}

%%=====================================

\DeclareOption{loigiai}{

\makeatletter

\def\applykindSA{0} % Để huỷ áp dụng \kindSA

\renewcommand{\TF}[1]{\EXboxTF{\textbf{\colorEX#1}}}

\renewcommand{\boxEX}[2][9pt]{%
\setbox1=\hbox{#2}%

\def\sizeboxEX{#1}%

\ \EXbox{#2}\ %

\renewcommand{\sh}[1]{\text{#1}}

\showanswers

%Xuất hiện chữ Lời giải trong môi trường onlysolution

\makeatletter

\renewcommand{\do@onlysolution}[1]{%

\par\noindent\textbf{\loigiaiEX}%

\ifshowanswers

\@ifnextchar\immini

{}

{ \@ifnextchar\begin

{}

{\par\noindent}

#1%

\fi

\ifthenelse{\equal{\keyEX}{}}{}

{\leavevmode\unskip\textchoice\ignorespaces\xdef\keyEX{}}%

\setcounter{numTrueSol}{0}%

\renewcommand{\loigiai}[1]{

\ifInTcolorbox \ifdef{\endboxex}{\endboxex\def\endboxex{}}{} \fi

\labelex

\def\labelex{}

\begin{onlysolution}
#1

\end{onlysolution}

\renewcommand{\True}{%

\ifnum\chType=0\setcounter{numTrue}{\thedapan}\setcounter{numTrueSol}{\
thedapan}%

\else \gdef\TrueX{\tickT}\gdef\FalseX{}\fi%

%\choiceTF

\renewcommand{\callcotDS}{\def\cotDS{1}}%

\renewcommand{\writekeyTFone}{\gdef\TrueX{}\gdef\FalseX{\tickF}}

\renewcommand{\writekeyTF}{%

&\vspace{-1pt}\centering\leavevmode\TrueX%

&\vspace{-3pt}\parbox[t]{\linewidth}{\centering\leavevmode\FalseX}%

\gdef\TrueX{}\gdef\FalseX{\tickF}%

%\shortans

\def\kindSA{ShowSAKeyLG}

\renewcommand{\exitshowansEX}[1]{}

\renewcommand{\exithideansEX}[1]{%

\makeatletter

\AtBeginEnvironment{#1}{%

\def\kindSA{ShowSAKeyLG}%

\renewcommand{\writekeyTFone}{\gdef\TrueX{}\gdef\FalseX{\tickF}}

\renewcommand{\writekeyTF}{%

&\vspace{-1pt}\centering\leavevmode\TrueX%

&\vspace{-3pt}\parbox[t]{\linewidth}{\centering\leavevmode\FalseX}%

\gdef\TrueX{}\gdef\FalseX{\tickF}%
}

\renewcommand{\loigiai}[1]{%

\ifInTcolorbox \ifdef{\endboxex}{\endboxex\def\endboxex{}}{} \fi

\labelex

\def\labelex{}

\begin{onlysolution}

##1

\end{onlysolution}

%%=====================================

\DeclareOption{color}{

\makeatletter

\def\applykindSA{0} % Để huỷ áp dụng \kindSA

\def\colorEX{\color{red}}

\renewcommand{\TrueTF} {\stepcounter{dapan}\squareEX{\bf\DapAnTF}\ignorespaces}

\renewcommand{\TrueEX} {\stepcounter{dapan}\squareEX{\bf\Alph{dapan}}\ignorespaces}

\renewcommand{\True}{%

\ifnum\chType=0\setcounter{numTrue}{\thedapan}\setcounter{numTrueSol}{\
thedapan}%

\else \gdef\TrueX{\circEX{\tickT}}\gdef\FalseX{} \fi%

\leavevmode\colorEX%

%\choiceTF

\renewcommand{\callcotDS}{\def\cotDS{1}}%
\renewcommand{\writekeyTFone}{\gdef\TrueX{}\gdef\FalseX{\tickF}}

\renewcommand{\writekeyTF}{%

&\vspace{-1pt}\centering\leavevmode\TrueX%

&\vspace{-3pt}\parbox[t]{\linewidth}{\centering\leavevmode\FalseX}%

\gdef\TrueX{}\gdef\FalseX{\tickF}%

%\shortans

\def\kindSA{ShowSAKeyColor}

\renewcommand{\exithideansEX}[1]{%

\makeatletter

\AtBeginEnvironment{#1}{%

\def\kindSA{ShowSAKeyColor}%

\def\colorEX{\color{red}}%

\renewcommand{\TrueTF} {\stepcounter{dapan}\squareEX{\bf\DapAnTF}\
ignorespaces}

\renewcommand{\TrueEX} {\stepcounter{dapan}\squareEX{\bf\Alph{dapan}}\
ignorespaces}

\renewcommand{\writekeyTFone}{\gdef\TrueX{}\gdef\FalseX{\tickF}}

\renewcommand{\writekeyTF}{%

&\vspace{-1pt}\centering\leavevmode\TrueX%

&\vspace{-3pt}\parbox[t]{\linewidth}{\centering\leavevmode\FalseX}%

\gdef\TrueX{}\gdef\FalseX{\tickF}%

%%=====================================
\DeclareOption{book}{

\makeatletter

\showanswers

\renewcommand{\loigiai}[1]{%

\labelex \def\labelex{}

\writeansbook{#1}%

\renewcommand{\writeansbook}[1]{%

\Writetofile{ansbook}{\string\begin{Solbook}{\Currentlabel}}%

\Writetofile{ansbook}{\string\def\string\chType\string{\chType\string}}%

\ifthenelse{\equal{\saveFileAns}{}}{}{%

\ifnum\chType=0

\ifnum\the\value{numTrueSol}>0

\Writetofile{ansbook}{\detokenize{\selectchoice}\ \string\
circEX{\saveFileAns}}%

\fi

\else\ifnum\chType=1

\Writetofile{ansbook}{\detokenize{\selectchoiceTF}: \saveFileAns}%

\else

\Writetofile{ansbook}{\detokenize{\selectshortans}\ \saveFileAns}%

\fi\fi%

}%

\Writetofile{ansbook}{\string\par\string\noindent^^J\detokenize{#1}^^J\string\par\
string\noindent}%

\Writetofile{ansbook}{\string\end{Solbook}}%

\setcounter{numTrueSol}{0}%

}
\renewcommand{\exithideansEX}[1]{%

\AtBeginEnvironment{#1}{%

\renewcommand{\loigiai}[1]{%

\labelex \def\labelex{}

\writeansbook{##1}%

}%

}%

%%=====================================

\DeclareOption{dethi}{

\makeatletter

\renewcommand{\TF}[1]{\EXboxTF{}}

\renewcommand{\boxEX}[2][9pt]{%

\def\sizeboxEX{#1}%

\setbox1=\hbox{#2}%

\ \EXbox{}\ %

\ExecuteOptions{dethi}

\ProcessOptions

%Nội dung gói ex_test

\theorempreskipamount0.1\baselineskip

\theorempostskipamount0.2\baselineskip

\newlength\dorongfix

\dorongfix=\linewidth

\newlength\dorong

\dorong=\linewidth
\newcommand{\reducedstrut}{\vrule width 0pt height .9\ht\strutbox depth .9\dp\strutbox\relax}

\def\hfillenum{\hfill}

\makeatletter

\newtheoremstyle{immini}%

{\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\theorem@separator]

\def\thindent{%

\setbox0\vbox{\hbox{\leavevmode\unskip\theorem@headerfont ##1\ ##2\


theorem@separator\ignorespaces}}%

\hspace*{\wd0}%

}%

\def\labelthm{##1}%

\def\labelthmfull{{\theorem@headerfont ##1\ ##2\theorem@separator\ }}

}%

{%

\setbox1\vbox{\hbox{\theorem@headerfont ##1\ ##2\ (##3)\theorem@separator\


ignorespaces}}%

\ifdim\wd1>0.4\linewidth\relax%

\item\hbox to \linewidth{\theorem@headerfont ##1\ ##2\

(##3)\theorem@separator\hfill}

\else

\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\ (##3)\theorem@separator]

\fi

\ifdim\wd1>0.4\linewidth\relax

\def\hfillenum{}

\def\thindent{%

}%

\def\labelthmfull{%

}
\else

\def\hfillenum{\hfill}

\def\thindent{%

\setbox0\vbox{\hbox{\leavevmode\unskip\theorem@headerfont ##1\ ##2\ (##3)\


theorem@separator\ignorespaces}}%

\hspace*{\wd0}%

}%

\def\labelthmfull{{\theorem@headerfont ##1\ ##2\ (##3)\theorem@separator\ }}

\fi

\def\labelthm{##1}%

\newtheoremstyle{imminib}%

{\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\theorem@separator]

\def\thindent{%

\setbox0\vbox{\hbox{\leavevmode\unskip\theorem@headerfont ##1\ ##2\


theorem@separator\ignorespaces}}%

\hspace*{\wd0}%

}%

\def\labelthm{##1}%

\def\labelthmfull{{\theorem@headerfont ##1\ ##2\theorem@separator\ }}

}%

{%

\setbox1\vbox{\hbox{\theorem@headerfont ##1\ ##2\ (##3)\theorem@separator\


ignorespaces}}%

\ifdim\wd1>0.4\linewidth\relax%

\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\theorem@separator]

\else

\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\ (##3)\theorem@separator]

\fi
\ifdim\wd1>0.4\linewidth\relax

\def\labelex{%

\begin{flushright}

\vspace*{-5pt}

\textit{\textbf{(##3)}}

\vspace*{-5pt}

\end{flushright}}

\def\thindent{%

\setbox0\vbox{\hbox{\leavevmode\unskip\theorem@headerfont ##1\ ##2\


theorem@separator\ignorespaces}}%

\hspace*{\wd0}%

}%

\def\labelthmfull{{\theorem@headerfont ##1\ ##2\theorem@separator\ }}

\else

\def\thindent{%

\setbox0\vbox{\hbox{\leavevmode\unskip\theorem@headerfont ##1\ ##2\ (##3)\


theorem@separator\ignorespaces}}%

\hspace*{\wd0}%

}%

\def\labelthmfull{{\theorem@headerfont ##1\ ##2\ (##3)\theorem@separator\ }}

\fi

\def\labelthm{##1}%

\newtheoremstyle{exbreak}%

{\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\theorem@separator]}%

{\item\hbox to \linewidth{\theorem@headerfont ##1\ ##2\

(##3)\theorem@separator\hfill}}

\newtheoremstyle{explain}%
{\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\theorem@separator]}%

{\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\theorem@separator]\def\labelex{

\begin{flushright}

\vspace*{-5pt}

\textit{\textbf{(##3)}}

\vspace*{-5pt}

\end{flushright}}}

%Danh sách môi trường trích dẫn nguồn câu hỏi

\newcommand{\listtheorem}[1]{

\foreach \x in {#1} {%môi trường

\AtEndEnvironment{\x}{%

\labelex

}}%

\makeatother

\theoremstyle{immini}

\theoremseparator{.}

\theorembodyfont{\rm}

\Newassociation{solbook}{Solbook}{ansbook}

\renewcommand{\Solbooklabel}[1]{\textbf{\nameex\ #1.}}

\Newassociation{EXsol}{Solution}{ans}

\Newassociation{sol}{Solution}{ans_old}

\newtheorem{ex}{\nameex}

\AtBeginEnvironment{Solbook}{

\renewcommand{\IMleftright}[3]{

\par\noindent

\begin{minipage}[t][][t]{\linewidth-\widthimmini-4\fboxsep-#1\linewidth}

#2
\end{minipage}

\hspace{#1\linewidth}\hspace{2\fboxsep}

\begin{minipage}[t][][b]{\widthimmini}\vspaceIM

#3

\end{minipage}

\par\nointerlineskip

\newtheorem{vdex}{Ví dụ}

\AtBeginEnvironment{vdex}{\setcounter{numTrueSol}{0}\def\dotEX{.}}

%Các phương pháp đưa hình vào văn bản

\def\vspaceIM{\vspace{-0.5\baselineskip}}

\def\breakIM{\filbreak}

\def\numpicinpar{0}

\newdimen\heightline

\newdimen\widthimmini

\newdimen\heightimmini

\newdimen\heighttextimmini

\newdimen\himmini

\newdimen\spaceleft

\newbox\imbox

\newbox\imboxtext

\newcommand{\hspaceIM}[1]{

\def\hspaceIMEX{\hspace{#1\linewidth}}

\def\hspaceEXIM{#1\linewidth}

\newcommand{\IMleftright}[3]{
\hfill\par\noindent

\begin{minipage}[t][][t]{\linewidth-\widthimmini-4\fboxsep-#1\linewidth}

#2

\end{minipage}

\hspace{#1\linewidth}\hspace{2\fboxsep}

\begin{minipage}[t][][b]{\widthimmini}\vspaceIM

#3

\centering \IMname\IMlabel

\end{minipage}

\par\nointerlineskip

\newcommand{\IMrightleft}[3]{

\hfill\par\noindent

\begin{minipage}[t][][b]{\widthimmini}\vspaceIM

#3

\centering \IMname\IMlabel

\end{minipage}

\hspace{#1\linewidth}\hspace{2\fboxsep}

\begin{minipage}[t][][t]{\linewidth-\widthimmini-4\fboxsep-#1\linewidth}

#2

\end{minipage}

\par\nointerlineskip

\newcommand{\immini}[3][0]{

\savebox{\imbox}{#3}

\widthimmini=\wd\imbox

\heightimmini=\ht\imbox

\ifthenelse{\equal{#1}{thm}}
{%

\savebox{\imboxtext}{\vbox{#2}}

\xdef\saveFileAns{}\xdef\keyEX{}\setcounter{dapan}{0}

\vspace{-0.3\baselineskip}

\leavevmode\nopagebreak\IMleftright{0}{\protect\leavevmode\labelthmfull#2}{#3}

\IMleftright{#1}{#2}{#3}

\newcommand{\imminiL}[3][0]{

\setbox\imbox=\vbox{\hbox{#3}}

\widthimmini=\wd\imbox

\heightimmini=\ht\imbox

\spaceleft=\dimexpr\textheight-\pagetotal-2\baselineskip\relax

\ifdim\heightimmini>\spaceleft

\breakIM

\fi

\IMrightleft{#1}{#2}{#3}

%%===================================

%%-- Thử lệnh \immini và \imminiL mới

\makeatletter

\def\IMheight{2mm}

\def\title{}

%\@ifpackageloaded{tcolorbox}{%

% \makeatletter

% \newcommand{\immini}[3][]{%
% \ifthenelse{\equal{##1}{}}{}{%

% \ifthenelse{\equal{##1}{thm}}{}%

% {\def\IMheight{##1cm}}}%

% \savebox{\imbox}{##3}%

% \tcbsidebyside[blanker,

% sidebyside adapt=right,

% sidebyside align=top seam,

% sidebyside gap=\IMheight,

% top=0pt,left=0pt,right=0pt,bottom=0pt,

% ]{{\title}##2}{\usebox{\imbox}}%

% \gdef\title{}%

% }

% \newcommand{\imminiL}[3][]{%

% \ifthenelse{\equal{##1}{}}{}{%

% \ifthenelse{\equal{##1}{thm}}{}%

% {\def\IMheight{##1cm}}}%

% \savebox{\imbox}{##3}%

% \tcbsidebyside[blanker,

% sidebyside adapt=left,

% sidebyside align=top seam,

% sidebyside gap=\IMheight,

% top=0pt,left=0pt,right=0pt,bottom=0pt,

% ]{\usebox{\imbox}}{{\title}##2}%

% \gdef\title{}%

% }

% \newcommand{\fiximmini}[2][]{

% \ifcsname #2\endcsname

% \NewImmini
% \renewenvironment{#2}[1][]{%

% \refstepcounter{#2}%

% \ifthenelse{\equal{##1}{}}{%

% \@ifnextchar\immini{\gdef\title{\bf#1{ }\@currentlabel.}}%

% {\@ifnextchar\imminiL{\gdef\title{\bf#1{ }\@currentlabel.}}%

% {\par\noindent\textbf{\bf#1{ }\@currentlabel.{ }}}}%

% }{%

% \@ifnextchar\immini{\gdef\title{\bf#1{ }\@currentlabel{ }(##1).}}%

% {\@ifnextchar\imminiL{\gdef\title{\bf#1{ }\@currentlabel{ }(##1).}}%

% {\par\noindent\textbf{#1{ }\@currentlabel{ }(##1).{ }}}}%

% }}{\gdef\title{}}

% \fi

% }

% \fiximmini[\nameex]{ex}

%}{%

% \newcommand{\fiximmini}[2][]{{\noindent\bf\large\color{red}

% \begin{itemize}

% \item Gói lệnh {\color{blue}tcolorbox} cần được khai báo trước khi khai
báo gói ex-test.

% \item Hãy tắt {\color{blue}\string\fiximmini[name]\{env\}} đi nếu bạn


thấy không cần thiết.

% \item Hoặc bổ sung {\color{blue}\string\


usepackage[most,xparse,many]\{tcolorbox\}} vào dòng phía trên của dòng khai báo {\color{black}\
string\usepackage[...]\{ex\_test\}}.

% \end{itemize}

% }}%

%}

\@ifpackageloaded{tcolorbox}{%

\newcommand{\NewImmini}{%
%Lệnh \immini theo khai báo của thầy Trần Lê Nam

\makeatletter

\renewcommand{\immini}[3][]{%

\ifthenelse{\equal{##1}{}}{}{%

\ifthenelse{\equal{##1}{thm}}{}%

{\def\IMheight{##1cm}}}%

\savebox{\imbox}{##3}%

\tcbsidebyside[blanker,

sidebyside adapt=right,

sidebyside align=top seam,

sidebyside gap=\IMheight,

top=0pt,left=0pt,right=0pt,bottom=0pt,

]{{\title}##2}{\usebox{\imbox}}%

\gdef\title{}%

\renewcommand{\imminiL}[3][]{%

\ifthenelse{\equal{##1}{}}{}{%

\ifthenelse{\equal{##1}{thm}}{}%

{\def\IMheight{##1cm}}}%

\savebox{\imbox}{##3}%

\tcbsidebyside[blanker,

sidebyside adapt=left,

sidebyside align=top seam,

sidebyside gap=\IMheight,

top=0pt,left=0pt,right=0pt,bottom=0pt,

]{\usebox{\imbox}}{{\title}##2}%

\gdef\title{}%

}
}

\newcommand{\fiximmini}[2][]{%

\ifthenelse{\equal{#1}{}}

{\ifthenelse{\equal{#2}{ex}}

{\def\namefix{\nameex}}

{\ifthenelse{\equal{#2}{bt}}

{\def\namefix{\namebt}}

{}\ifthenelse{\equal{#2}{vd}}

{\def\namefix{\namevd}}

{\def\namefix{#1}}}}

{\def\namefix{#1}}%

\ifcsname #2\endcsname

\NewImmini

\renewenvironment{#2}[1][]{%

\refstepcounter{#2}%

\ifthenelse{\equal{##1}{}}{%

\@ifnextchar\immini{\gdef\title{\bf\namefix{ }\
@currentlabel.}}%

{\@ifnextchar\imminiL{\gdef\title{\bf\namefix{ }\
@currentlabel.}}%

{\par\noindent\textbf{\bf\namefix{ }\@currentlabel.
{ }}}}%

}{%

\@ifnextchar\immini{\gdef\title{\bf\namefix{ }\
@currentlabel{ }(##1).}}%

{\@ifnextchar\imminiL{\gdef\title{\bf\namefix{ }\
@currentlabel{ }(##1).}}%

{\par\noindent\textbf{\namefix{ }\@currentlabel{ }
(##1).{ }}}}%

}}{\gdef\title{}}
\fi

}{%

\newcommand{\fiximmini}[2][]{{\noindent\bf\large\color{red}

\begin{itemize}

\item Gói lệnh {\color{blue}tcolorbox} cần được khai báo trước khi khai báo gói
ex-test.

\item Hãy tắt {\color{blue}\string\fiximmini[name]\{env\}} đi nếu bạn thấy


không cần thiết.

\item Hoặc bổ sung {\color{blue}\string\usepackage[most,xparse,many]\


{tcolorbox\}} vào dòng phía trên của dòng khai báo {\color{black}\string\usepackage[...]\{ex\_test\}}.

\end{itemize}

}}%

%%===================================

%-- Hết lệnh \immini và \imminiL mới

\newcommand{\impicinpar}[2]{

\begin{window}[\numpicinpar,r,{

#2

}, {}]

\begin{flushleft}

#1

\end{flushleft}

\end{window}

%Hết cách đưa hình vào văn bản

% Biểu diễn khoảng, đoạn trên trục số

\usetikzlibrary{decorations.pathreplacing,decorations.markings,patterns}
\def\colorInterval{black}

\def\skipInterval{0.4cm}

\newcommand{\Interval}[4]{%

\coordinate [label={center:$#1$},label=below:$\rule{0pt}{\skipInterval}#2$] (a) at (#2,0);

\coordinate [label={center:$#3$},label=below:$\rule{0pt}{\skipInterval}#4$] (b) at (#4,0);

\draw[color=\colorInterval] decorate[decoration={ticks,amplitude=3pt,segment length=1mm}] {(a)--


(b)};

\newcommand{\IntervalR}[4]{%

\coordinate [label={center:$#1$},label=below:$\rule{0pt}{\skipInterval}#2$] (a) at (#2,0);

\coordinate [label={center:$#3$},label=below:$\rule{0pt}{\skipInterval}#4$] (b) at (#4,0);

\draw decorate[decoration={markings,mark=% actually add a mark

between positions 0 and 1 step 1mm

with

\draw[color=\colorInterval] (-3pt,-3pt) -- (3pt,3pt);

}}] {(a)--(b)};

\newcommand{\IntervalL}[4]{%

\coordinate [label={center:$#1$},label=below:$\rule{0pt}{\skipInterval}#2$] (a) at (#2,0);

\coordinate [label={center:$#3$},label=below:$\rule{0pt}{\skipInterval}#4$] (b) at (#4,0);

\draw decorate[decoration={

markings,

mark=between positions 0 and 1 step 1mm

with

\draw[color=\colorInterval] (-3pt,3pt) -- (3pt,-3pt);

}
}

] {(a)--(b)};

\newcommand{\IntervalLF}[4]{%

\coordinate [label={center:$#1$},label=below:$\rule{0pt}{\skipInterval}#2$] (a) at (#2,0);

\coordinate [label={center:$#3$},label=below:$\rule{0pt}{\skipInterval}#4$] (b) at (#4,0);

\fill[pattern=north west lines,pattern color=\colorInterval](#2,-3pt)rectangle(#4,3pt);

\newcommand{\IntervalRF}[4]{%

\coordinate [label={center:$#1$},label=below:$\rule{0pt}{\skipInterval}#2$] (a) at (#2,0);

\coordinate [label={center:$#3$},label=below:$\rule{0pt}{\skipInterval}#4$] (b) at (#4,0);

\fill[pattern=north east lines,pattern color=\colorInterval](#2,-3pt)rectangle(#4,3pt);

\def\pre{0}

\def\next{2}

\newcommand{\IntervalLR}[2]{

\def\pre{#1}

\def\next{#2}

\newcommand{\IntervalG}[4]{%

\coordinate [label={center:$#1$},label=below:$\rule{0pt}{\skipInterval}#2$] (a) at (\pre,0);

\coordinate [label={center:$#3$},label=below:$\rule{0pt}{\skipInterval}#4$] (b) at (\next,0);

\draw[color=\colorInterval] decorate[decoration={ticks,amplitude=3pt,segment length=1mm}] {(a)--


(b)};

\newcommand{\IntervalGL}[4]{%

\coordinate [label={center:$#1$},label=below:$\rule{0pt}{\skipInterval}#2$] (a) at (\pre,0);

\coordinate [label={center:$#3$},label=below:$\rule{0pt}{\skipInterval}#4$] (b) at (\next,0);


\draw decorate[decoration={markings,mark=% actually add a mark

between positions 0 and 1 step 1mm

with

\draw[color=\colorInterval] (-3pt,3pt) -- (3pt,-3pt);

}}] {(a)--(b)};

\newcommand{\IntervalGR}[4]{%

\coordinate [label={center:$#1$},label=below:$\rule{0pt}{\skipInterval}#2$] (a) at (\pre,0);

\coordinate [label={center:$#3$},label=below:$\rule{0pt}{\skipInterval}#4$] (b) at (\next,0);

\draw decorate[decoration={markings,mark=% actually add a mark

between positions 0 and 1 step 1mm

with

\draw[color=\colorInterval] (-3pt,-3pt) -- (3pt,3pt);

}}] {(a)--(b)};

\newcommand{\IntervalGLF}[4]{%

\coordinate [label={center:$#1$},label=below:$\rule{0pt}{\skipInterval}#2$] (a) at (\pre,0);

\coordinate [label={center:$#3$},label=below:$\rule{0pt}{\skipInterval}#4$] (b) at (\next,0);

\fill[pattern=north west lines,pattern color=\colorInterval](\pre,-3pt)rectangle(\next,3pt);

\newcommand{\IntervalGRF}[4]{%

\coordinate [label={center:$#1$},label=below:$\rule{0pt}{\skipInterval}#2$] (a) at (\pre,0);

\coordinate [label={center:$#3$},label=below:$\rule{0pt}{\skipInterval}#4$] (b) at (\next,0);

\fill[pattern=north east lines,pattern color=\colorInterval](\pre,-3pt)rectangle(\next,3pt);

}
%Định nghĩa dots fill

\xdef\blskip{\the\baselineskip}

\xdef\pskip{\the\parskip}

\xdef\mtcs{\the\multicolsep}

\newcommand{\dotlineEX}[2][1]{%

\baselineskip=22pt%

\setlength{\multicolsep}{1pt}%

\setlength{\parskip}{0pt}%

\xdef\numline{#2}%

\xdef\numlinedot{\the\numexpr#2*#1}%

\ifnum#1=1

\par\foreach \dotline in{1,...,\numlinedot}

{\noindent\ifnum\dotline=1\reflectbox{\large\HandPencilLeft}\fi\dotfill\par}

\else\begin{multicols}{#1}

\foreach \dotline in{1,...,\numlinedot}

{\pgfmathparse{int((\dotline-1)*100/\numline-100*int((\dotline-1)/\
numline))}

\noindent\ifnum\pgfmathresult=0\reflectbox{\large\HandPencilLeft}\fi\
dotfill\par}

\end{multicols}

\fi

\vspace{8pt}\noindent%

\setlength{\multicolsep}{\mtcs}%

\setlength{\parskip}{\pskip}%

\baselineskip=\blskip%

%Liệt kê danh sách đáp án

\newsavebox{\myboxans}
\newcommand{\boxans}

\renewenvironment{Solution}[1]

{\begin{lrbox}{\myboxans}\begin{minipage}{0.1\linewidth-4\fboxsep}

\parbox[b]{0.55\linewidth}{\color{blue}##1.}

\color{violet}

{\end{minipage}\end{lrbox}\fbox{\usebox{\myboxans}}}

\newcommand{\listans}

\renewenvironment{Solution}[1]

{{\color{blue}##1}\hspace*{-4pt}}

{\hspace*{-5pt}}

\newcommand{\tabans}[1]

\renewenvironment{Solution}[1]

{\begin{minipage}{\linewidth/#1-1.2\fboxsep}

\parbox[b]{0.45\linewidth}{

\raggedleft\color{blue}##1.

\color{violet}

{\end{minipage}}

\newcommand{\rowans}

{
\renewenvironment{Solution}[1]

{\begin{minipage}{0.1\linewidth-1.2\fboxsep}

\parbox[b]{0.45\linewidth}{

\raggedleft\color{blue}##1.

\color{violet}

{\end{minipage}}

\makeatletter

\def\nameexans{Câu} %Từ xuất hiện ở bảng đáp án câu TF và SA

\newlength{\contentlength}

\newlength{\lengthCD}\settowidth{\lengthCD}{CD}

\def\firstofpair#1,#2{#1}

\def\secondofpair#1,#2{#2}

\newcommand{\inputans}[3][]{%

\ifthenelse{\equal{#1}{0}}{\Onlycirc}

{\ifthenelse{\equal{#1}{1}}{\Fullcirc}{\Returncirc}}%

\IfSubStr{#2}{,}

{\def\numABCD{\expandafter\firstofpair#2\relax}%

\def\numTFSA{\expandafter\secondofpair#2\relax}%

\Onlycirc}%

{\def\numABCD{#2}\def\numTFSA{#2}}%

{\fontfamily{qcs}\small\selectfont%

\RenewEnviron{Solution}[1]{%

\settowidth{\contentlength}{\BODY}%

\begin{lrbox}{\myboxans}

\ifdim\contentlength<\lengthCD
\begin{minipage}{\dimexpr\linewidth/\numABCD-4.28\fboxsep\relax}\else%

\begin{minipage}{\dimexpr\linewidth/\numTFSA-4.28\fboxsep\relax}\fi%

\parbox[b]{8mm}{\raggedleft\color{blue}##1.}\,\color{violet}\BODY%

\end{minipage}

\end{lrbox}\noindent\usebox{\myboxans}\;\vspace{0.15mm}

}%

\begin{flushleft}%

\foreach \file in {#3}{% Nếu muốn giữa 2 file được nhập có xuống dòng thì gõ file1 ,, file
2

\IfStrEq{\file}{}{\vspace{0.3mm}\par}{\input{\file}}%

\end{flushleft}

}}

\newcommand{\inputansbox}[3][]{%

\ifthenelse{\equal{#1}{0}}{\Onlycirc}

{\ifthenelse{\equal{#1}{1}}{\Fullcirc}{\Returncirc}}%

\IfSubStr{#2}{,}

{\def\numABCD{\expandafter\firstofpair#2\relax}%

\def\numTFSA{\expandafter\secondofpair#2\relax}%

\Onlycirc}%

{\def\numABCD{#2}\def\numTFSA{#2}}%

{\fontfamily{qcs}\small\selectfont%

\RenewEnviron{Solution}[1]{%

\settowidth{\contentlength}{\BODY}%

\begin{lrbox}{\myboxans}

\ifdim\contentlength<\lengthCD

\begin{minipage}{\dimexpr\linewidth/\numABCD-4.28\fboxsep\relax}

\color{blue}##1.
\hfill\color{violet}\BODY%

\end{minipage}

\else

\begin{minipage}{\dimexpr\linewidth/\numTFSA-4.28\fboxsep\relax}

\parbox[b]{15mm}{\color{blue}\nameexans~##1.}

\hfill\color{violet}\BODY%

\end{minipage}

\fi

\end{lrbox}\noindent\fbox{\usebox{\myboxans}}\;\vspace{0.15mm}

}%

\begin{flushleft}%

\foreach \file in {#3}{% Nếu muốn giữa 2 file được nhập có xuống dòng thì gõ file1 ,, file
2

\IfStrEq{\file}{}{\vspace{0.3mm}\par}{\input{\file}}%

\end{flushleft}

}}

\newcommand{\inputansTF}[3][2]{\inputans[#1]{#2}{#3}}

\newcommand{\inputansSA}[3][2]{\inputans[#1]{#2}{#3}}

\newcommand{\inputansboxTF}[3][2]{\inputansox[#1]{#2}{#3}}

\newcommand{\inputansboxSA}[3][2]{\inputansox[#1]{#2}{#3}}

\makeatletter

\@ifclasswith{article}{a5paper}

{%

\renewcommand{\rowans}

\renewenvironment{Solution}[1]

{\begin{minipage}{0.2\linewidth-1.2\fboxsep}
\parbox[b]{0.45\linewidth}{\color{blue}##1.}

\color{violet}

{\end{minipage}}

}{%

\@ifclasswith{book}{a5paper}

{%

\renewcommand{\rowans}

\renewenvironment{Solution}[1]

{\begin{minipage}{0.2\linewidth-1.2\fboxsep}

\parbox[b]{0.45\linewidth}{\color{blue}##1.}

\color{violet}

{\end{minipage}}

}{%

\makeatother

\def\hideans{

\renewcommand{\inputansbox}[2]{%

}%

\renewcommand{\inputans}[2]{%

}%

\renewcommand{\tabans}[1]{%

}%
}

%Hỗ trợ gói ex_test_rd

\newenvironment{fileEX}{\filecontents}{\endfilecontents}

\newcommand{\bankEX}[2]{

\input{#1}

\newtheorem{exrd}{Câu}

\def\listfile{

\bankEX{onefile.tex}{50}

\def\testname{

\begin{center}

\textbf{ĐỀ THI MẪU}

\end{center}

\rightline{

\setlength\fboxrule{2pt}

\setlength\fboxsep{5pt}

\fbox{\textbf{Mã đề thi\ \x}}

\newcommand{\randombank}[1]{

%\testname

\begin{center}

\textbf{

\color{red}

Bạn đang chạy bằng gói ex\_test xuất ra MỌI CÂU HỎI của ngân hàng nhằm soát lỗi.\\

Khi mọi thứ đã OK, hãy thay khai báo gói ex\_test bằng gói ex\_test\_rd

}
\end{center}

\Opensolutionfile{ans}[ans/ans_ex_test]

\listfile

\Closesolutionfile{ans}

\newcommand{\showansfull}{\par Các mã đề: }

\newcommand{\showans}{\par Các mã đề: }

%Đường tròn LG

\usetikzlibrary{plotmarks}

\newcommand{\trucLG}{

\draw[->] (0,-1.3) -- (0,1.3) node[left] {$\sin$};

\draw[->] (-1.3,0) -- (1.3,0) node[below] {$\cos$};

\draw (0,0) circle (1cm);

\newcommand{\pointLG}[4]

\foreach \i in {0,...,#2}

\draw[color=#4]

plot[mark=#3] coordinates {({#1+\i*360/#2}:1)};

\makeatletter

\def\sizeboxEX{9pt}

\def\EXbox#1{%

\begingroup%

\setlength{\fboxsep}{0.3ex}%

\setlength{\@tempdima}{\sizeboxEX}%
\setlength{\@tempdimb}{(\@tempdima-\ht1+\dp1)/2}%

\raise-\@tempdimb\hbox{\fbox{\vbox to \@tempdima{%

\vfil\hbox to \@tempdima{\hfil#1\hfil}\vfil}}}%

\endgroup%

\def\EXboxTF#1{%

\begingroup%

\setlength{\fboxsep}{0.3ex}%

\setbox1=\hbox{#1}%

\setlength{\@tempdima}{\sizeboxEX}%

\fbox{\vbox to \@tempdima{%

\vfil\hbox to \@tempdima{\hfil\copy1\hfil}\vfil}}%

\endgroup%

\makeatother

% Môi trường liệt kê dàn theo nhiều dòng khác nhau

\ExplSyntaxOn

% variants of kernel functions:

\cs_generate_variant:Nn \tl_if_eq:nnTF { V }

\cs_generate_variant:Nn \tl_if_eq:nnT { V }

% --------------------------------------------------------------------------

% variables:

\seq_new:N \l__listsEX_seq

\int_new:N \l__listsEX_depth_int

\int_new:N \g__listsEX_int

\int_new:N \g__listsEX_total_items_int
\int_new:N \l__listsEX_columns_int

\int_new:N \l__listsEX_rows_int

\int_new:N \g__listsEX_current_col_num_int

\int_new:N \g__listsEX_current_row_num_int

\int_new:N \l__listsEX_item_columns_int

\bool_new:N \l__listsEX_enumerate_bool

\bool_new:N \l__listsEX_resume_bool

\bool_new:N \l__listsEX_load_listsEX_bool

\bool_new:N \l__listsEX_label_width_bool

\bool_new:N \l__listsEX_item_indent_bool

\bool_new:N \l__listsEX_label_offset_bool

\bool_new:N \l__listsEX_custom_label_bool

\bool_new:N \l__listsEX_custom_after_item_skip_bool

\bool_new:N \l__listsEX_debug_bool

\bool_new:N \l__listsEX_item_full_line_bool

\bool_new:N \l__listsEX_item_rest_of_line_bool

\tl_new:N \l__listsEX_instance_tl

\tl_new:N \l__listsEX_label_tl

\tl_new:N \l__listsEX_custom_label_tl

\tl_new:N \l__listsEX_label_pattern_tl

\tl_new:N \l__listsEX_custom_label_pattern_tl

\tl_new:N \l__listsEX_label_format_tl

\tl_new:N \l__listsEX_custom_label_format_tl

\tl_new:N \l__listsEX_item_format_tl

\tl_new:N \l__listsEX_custom_item_format_tl

\tl_new:N \l__listsEX_item_fill_left_tl
\tl_new:N \l__listsEX_item_fill_right_tl

\tl_new:N \l__listsEX_label_align_tl

% \tl_new:N \listEX

\tl_new:N \l__listsEX_item_tl

\tl_new:N \l__listsEX_tmp_label_tl

\dim_new:N \l__listsEX_item_indent_dim

\dim_new:N \l__listsEX_item_default_indent_dim

\dim_new:N \l__listsEX_item_width_dim

\dim_new:N \l__listsEX_label_width_dim

\dim_new:N \l__listsEX_label_default_width_dim

\dim_new:N \l__listsEX_label_offset_dim

\dim_new:N \l__listsEX_label_default_offset_dim

\dim_new:N \l__listsEX_column_sep_dim

\skip_new:N \l__listsEX_after_item_skip

\skip_new:N \l__listsEX_custom_after_item_skip

\skip_new:N \l__listsEX_before_list_skip

\skip_new:N \l__listsEX_after_list_skip

\coffin_new:N \l__listsEX_item_coffin

\coffin_new:N \l__listsEX_label_coffin

\NewCounterPattern* [ listsEX ] { listEX } { tsk }

\ReadCounterFrom [ listsEX ] { listEX } \g__listsEX_int

% temporary variables:

\int_new:N \l__listsEX_tmpa_int
\int_new:N \l__listsEX_tmpb_int

\tl_new:N \l__listsEX_tmpa_tl

\coffin_new:N \l__listsEX_tmpa_coffin

\cs_new:Npn \__listsEX_debug:n #1

\bool_if:NTF \l__listsEX_debug_bool

{ \fbox {#1} }

{ \use:n {#1} }

% --------------------------------------------------------------------------

% collect the listsEX:

\cs_new_protected:Npn \__listsEX_collect_listsEX:nww #1#2 \end #3

\tl_put_right:Nn \l__listsEX_body_tl {#1}

\end {#3}

\tl_if_eq:nnF {#1} {#3}

{ \__listsEX_collect_listsEX:nww {#1} }

% #1: instance

% #2: number of columns

% #3: item separator

% #4: environment body

\cs_new_protected:Npn \__listsEX:nnnn #1#2#3#4

\bool_if:NT \l__listsEX_debug_bool { \dim_set:Nn \fboxsep {0pt} }


\seq_set_split:Nnn \l__listsEX_seq {#3} {#4}

% remove the first (empty) item:

\seq_pop_left:NN \l__listsEX_seq \l__listsEX_tmpa_tl

\tl_if_blank:VF \l__listsEX_tmpa_tl { \@noitemerr }

\int_gset:Nn \g__listsEX_total_items_int

{ \seq_count:N \l__listsEX_seq }

\UseInstance {listsEX} {#1}

{ \g__listsEX_total_items_int }

{#2}

{ \l__listsEX_custom_label_pattern_tl }

% just to be sure:

\seq_clear:N \l__listsEX_seq

\cs_generate_variant:Nn \__listsEX:nnnn { VnnV }

% #1: label

% #2: item format

% #3: item

\cs_new_protected:Npn \__listsEX_listEX:nnn #1#2#3

% start a new item line if \l__listsEX_item_full_line_bool

\bool_if:NT \l__listsEX_item_full_line_bool

% add skip if we were in the middle of a line, i.e., in horizontal

% mode:

\mode_if_horizontal:T

{ \skip_vertical:N \l__listsEX_after_item_skip }

\listsEX_new_row:
}

% step column position:

\int_gincr:N \g__listsEX_current_col_num_int

\dim_set:Nn \l__listsEX_item_width_dim

\bool_if:NTF \l__listsEX_item_full_line_bool

{ \linewidth }

\linewidth

-\fboxsep

- \l__listsEX_columns_int \l__listsEX_column_sep_dim

+ \l__listsEX_column_sep_dim

) / \l__listsEX_columns_int

- \l__listsEX_depth_int \l__listsEX_item_indent_dim

\bool_if:NT \l__listsEX_debug_bool { -2\fboxrule }

\__listsEX_gset_rows_num:NN

\g__listsEX_total_items_int

\l__listsEX_columns_int

% set \g__listsEX_current_col_num_int to 1 if at the start of a row,

% then also step \g__listsEX_current_row_num_int :

\int_compare:nNnT

{ \g__listsEX_current_col_num_int } > { \l__listsEX_columns_int }

\int_gset:Nn \g__listsEX_current_col_num_int { 1 }

\int_incr:N \g__listsEX_current_row_num_int
}

\bool_if:NT \l__listsEX_item_rest_of_line_bool

\int_set:Nn \l__listsEX_tmpa_int

{ \l__listsEX_columns_int - \g__listsEX_current_col_num_int + 1 }

\int_compare:nNnTF { \l__listsEX_item_columns_int } = { 0 }

\int_set:Nn \l__listsEX_tmpb_int { \l__listsEX_tmpa_int - 1 } % 8

\int_compare:nNnTF

{ \l__listsEX_tmpa_int } > { \l__listsEX_item_columns_int }

{ \int_set_eq:NN \l__listsEX_tmpa_int \l__listsEX_item_columns_int }

{ \int_zero:N \l__listsEX_item_columns_int }

\bool_if:nT

\l__listsEX_item_rest_of_line_bool &&

!\int_compare_p:nNn { \l__listsEX_item_columns_int} = { 0 }

\int_gadd:Nn \g__listsEX_current_col_num_int

{ \l__listsEX_item_columns_int -1 }

\int_gadd:Nn \g__listsEX_total_items_int

{ \l__listsEX_item_columns_int -1 }

\int_set:Nn \l__listsEX_tmpb_int { \l__listsEX_tmpa_int -1 }

\dim_set:Nn \l__listsEX_item_width_dim
{

\l__listsEX_tmpa_int \l__listsEX_item_width_dim

+ \l__listsEX_tmpb_int \l__listsEX_column_sep_dim

+ \l__listsEX_tmpb_int \l__listsEX_item_indent_dim

\bool_if:NT \l__listsEX_debug_bool

{ + \int_eval:n { \l__listsEX_tmpb_int * 2 } \fboxrule }

% set the item box:

\hcoffin_set:Nn \l__listsEX_item_coffin

\vcoffin_set:Nnn \l__listsEX_tmpa_coffin

{ \l__listsEX_item_width_dim }

{ \__listsEX_setup: #2 {#3} \strut }

\__listsEX_debug:n

\coffin_typeset:Nnnnn \l__listsEX_tmpa_coffin

{l} {T} {0pt} {0pt}

% set the label box:

\hcoffin_set:Nn \l__listsEX_label_coffin

\vcoffin_set:Nnn \l__listsEX_tmpa_coffin

\l__listsEX_label_width_dim

\bool_if:NT \l__listsEX_debug_bool {-2\fboxrule }

}
{

\noindent

\tl_use:N \l__listsEX_item_fill_left_tl

\strut #1

\tl_use:N \l__listsEX_item_fill_right_tl

\__listsEX_debug:n

\coffin_typeset:Nnnnn \l__listsEX_tmpa_coffin

{l} {T} {0pt} {0pt}

% attach the label box at the left of the item box, shifted by

% \l__listsEX_label_offset_dim :

\coffin_attach:NnnNnnnn

\l__listsEX_item_coffin {l} {T}

\l__listsEX_label_coffin {l} {T}

\dim_compare:nNnTF

{ \l__listsEX_item_indent_dim }

<

{ \l__listsEX_label_offset_dim + \l__listsEX_label_width_dim }

{0pt}

{ - \l__listsEX_label_width_dim - \l__listsEX_label_offset_dim }

} { 0pt }

% when a new row starts enter vertical mode:

\int_compare:nNnT { \g__listsEX_current_col_num_int } = { 1 }

{ \skip_vertical:N \c_zero_skip }
% skip horizontally by \l__listsEX_item_indent_dim

\noindent

\skip_horizontal:N \l__listsEX_item_indent_dim

% typeset the item (with the attached label protruding to the left):

\coffin_typeset:Nnnnn \l__listsEX_item_coffin

{l}

{T}

{0pt}

{0pt}

\bool_if:nT

\l__listsEX_item_full_line_bool ||

\l__listsEX_item_rest_of_line_bool &&

\int_compare_p:nNn { \l__listsEX_item_columns_int } = { 0 }

{ \listsEX_new_row: }

% are we between items in a row? The skip by \l__listsEX_column_sep_dim :

\int_compare:nNnT

{ \g__listsEX_current_col_num_int } < { \l__listsEX_columns_int }

{ \skip_horizontal:N \l__listsEX_column_sep_dim }

% if we ended a row and a new row is still to come skip vertically by

% \l__listsEX_after_item_skip :

\bool_if:nT

( \int_compare_p:nNn { \g__listsEX_current_col_num_int } = { \l__listsEX_columns_int } )

&&
( \int_compare_p:n { \g__listsEX_current_row_num_int != \l__listsEX_rows_int } )

{ \skip_vertical:N \l__listsEX_after_item_skip }

% clean up:

\coffin_clear:N \l__listsEX_item_coffin

\coffin_clear:N \l__listsEX_label_coffin

\coffin_clear:N \l__listsEX_tmpa_coffin

\bool_set_false:N \l__listsEX_item_full_line_bool

\bool_set_false:N \l__listsEX_item_rest_of_line_bool

\cs_generate_variant:Nn \__listsEX_listEX:nnn { VVV }

\cs_new_protected:Npn \__listsEX_setup:

\dim_set:Nn \parskip { 0pt }

\skip_set:Nn \parfillskip { 0pt plus 1fil }

\dim_set_eq:NN \parskip \parsep

\dim_set_eq:NN \parindent \listparindent

\noindent

\dim_compare:nNnT

{ \l__listsEX_item_indent_dim }

<

{ \l__listsEX_label_offset_dim + \l__listsEX_label_width_dim }

\skip_horizontal:n

\l__listsEX_label_offset_dim

+ \l__listsEX_label_width_dim
- \l__listsEX_item_indent_dim

\strut

\cs_new_protected:Npn \__listsEX_gset_rows_num:NN #1#2

\int_gset:Nn \l__listsEX_rows_int { \int_div_truncate:nn {#1} {#2} }

\int_compare:nNnT { \int_mod:nn {#1} {#2} } > { 0 }

{ \int_gincr:N \l__listsEX_rows_int }

\cs_new_protected:Npn \__listsEX_label_align:n #1

\str_case:nnF {#1}

{left}

\tl_clear:N \l__listsEX_item_fill_left_tl

\tl_set_eq:NN \l__listsEX_item_fill_right_tl \hfill

{right}

\tl_set_eq:NN \l__listsEX_item_fill_left_tl \hfill

\tl_clear:N \l__listsEX_item_fill_right_tl

{center}
{

\tl_set_eq:NN \l__listsEX_item_fill_left_tl \hfill

\tl_set_eq:NN \l__listsEX_item_fill_right_tl \hfill

\tl_clear:N \l__listsEX_item_fill_left_tl

\tl_set_eq:NN \l__listsEX_item_fill_right_tl \hfill

\cs_generate_variant:Nn \__listsEX_label_align:n { V }

\__listsEX_label_align:n {left}

% --------------------------------------------------------------------------

% the `listsEX' object:

% #1: number of items

% #2: number of columns

% #3: label-format

\DeclareObjectType {listsEX} {3}

% the `default' template interface:

\DeclareTemplateInterface {listsEX} {default} {3}

enumerate : boolean = true ,

label : tokenlist ,

indent : length = 2.5em ,

counter-format : tokenlist = tsk[a]) ,

label-format : tokenlist ,

label-width : length = 1em ,


label-offset : length = .3333em ,

item-format : tokenlist ,

after-item-skip : skip = 1ex plus 1ex minus 1ex

% in the next three commands we want a really unlikely to occur marker; for

% this we use $ with unusual catcode in ``$listsEX$default$label$'':

\cs_set:Nx \__listsEX_restore_dollar:

{ \char_set_catcode:nn {36} { \char_value_catcode:n {36} } }

\char_set_catcode_alignment:N \$

% the `default' template code:

\DeclareTemplateCode {listsEX} {default} {3}

enumerate = \l__listsEX_enumerate_bool ,

label = \l__listsEX_label_tl ,

indent = \l__listsEX_item_default_indent_dim ,

counter-format = \l__listsEX_label_pattern_tl ,

label-format = \l__listsEX_label_format_tl ,

label-width = \l__listsEX_label_default_width_dim ,

label-offset = \l__listsEX_label_default_offset_dim ,

item-format = \l__listsEX_item_format_tl ,

after-item-skip = \l__listsEX_after_item_skip

\AssignTemplateKeys

\bool_if:NF \l__listsEX_label_width_bool

{
\dim_set_eq:NN

\l__listsEX_label_width_dim

\l__listsEX_label_default_width_dim

\bool_if:NF \l__listsEX_item_indent_bool

\dim_set_eq:NN

\l__listsEX_item_indent_dim

\l__listsEX_item_default_indent_dim

\bool_if:NF \l__listsEX_label_offset_bool

\dim_set_eq:NN

\l__listsEX_label_offset_dim

\l__listsEX_label_default_offset_dim

\bool_if:NT \l__listsEX_custom_after_item_skip_bool

\skip_set_eq:NN

\l__listsEX_after_item_skip

\l__listsEX_custom_after_item_skip

\bool_if:NT \l__listsEX_custom_label_bool

\tl_set_eq:NN

\l__listsEX_label_tl

\l__listsEX_custom_label_tl

\bool_set_false:N \l__listsEX_enumerate_bool
}

\__listsEX_label_align:V \l__listsEX_label_align_tl

% need this for enumerate list:

\bool_if:nT { !\l__listsEX_resume_bool && \l__listsEX_enumerate_bool }

{ \int_gzero:N \g__listsEX_int }

\int_set:Nn \l__listsEX_columns_int {#2}

% set all the items in their own coffins and join with the ground:

\int_gzero:N \g__listsEX_current_col_num_int

\int_set:Nn \g__listsEX_current_row_num_int {1}

\tl_if_blank:VF \l__listsEX_custom_label_pattern_tl

\tl_set_eq:NN

\l__listsEX_label_pattern_tl

\l__listsEX_custom_label_pattern_tl

\tl_if_blank:VF \l__listsEX_custom_label_format_tl

\tl_set_eq:NN

\l__listsEX_label_format_tl

\l__listsEX_custom_label_format_tl

\tl_if_blank:VF \l__listsEX_custom_item_format_tl

\tl_set_eq:NN

\l__listsEX_item_format_tl

\l__listsEX_custom_item_format_tl

\seq_map_inline:Nn \l__listsEX_seq
{

\__listsEX_read_item:www ##1 \q_stop

\bool_if:NTF \l__listsEX_enumerate_bool

\tl_if_eq:VnT \l__listsEX_tmp_label_tl { $listsEX$default$label$ }

\int_gincr:N \g__listsEX_int

\SaveCounterPatternFrom [listsEX]

\l__listsEX_tmpa_tl

\l__listsEX_label_tl

\l__listsEX_label_pattern_tl

\tl_if_blank:VT \l__listsEX_label_tl

{ \tl_set_eq:NN \l__listsEX_label_tl \labelitemi }

\tl_put_left:NV \l__listsEX_label_tl \l__listsEX_label_format_tl

% \tl_put_left:NV \l__listsEX_item_tl \l__listsEX_item_format_tl

\tl_if_eq:VnTF \l__listsEX_tmp_label_tl { $listsEX$default$label$ }

\__listsEX_listEX:VVV

\l__listsEX_label_tl

\l__listsEX_item_format_tl

\l__listsEX_item_tl

\__listsEX_listEX:VVV
\l__listsEX_tmp_label_tl

\l__listsEX_item_format_tl

\l__listsEX_item_tl

\tl_clear:N \l__listsEX_tmp_label_tl

\cs_new_protected:Npn \__listsEX_read_item:www

\peek_meaning_remove:NTF !

\bool_set_true:N \l__listsEX_item_full_line_bool

\__listsEX_read_item_aux:ww

\peek_meaning_remove:NTF *

\bool_set_true:N \l__listsEX_item_rest_of_line_bool

\__listsEX_read_item_rest_of_line:ww

{ \__listsEX_read_item_aux:ww }

\cs_new_protected:Npn \__listsEX_read_item_rest_of_line:ww

\peek_meaning:NTF ( % )
{ \__listsEX_read_item_rest_of_line_aux:ww }

{ \__listsEX_read_item_rest_of_line_aux:ww (0) }

\cs_new_protected:Npn \__listsEX_read_item_rest_of_line_aux:ww (#1)

\int_set:Nn \l__listsEX_item_columns_int {#1}

\__listsEX_read_item_aux:ww

\cs_new_protected:Npn \__listsEX_read_item_aux:ww

\peek_meaning:NTF [ % ]

{ \__listsEX_read_item_aux_ii:ww }

{ \__listsEX_read_item_aux_ii:ww [$listsEX$default$label$] }

\cs_new_protected:Npn \__listsEX_read_item_aux_ii:ww [#1]#2 \q_stop

\tl_set:Nn \l__listsEX_tmp_label_tl {#1}

\tl_if_eq:nnF { #1 } { $listsEX$default$label$ }

{ \tl_put_left:NV \l__listsEX_tmp_label_tl \l__listsEX_label_format_tl }

\tl_set:Nx \l__listsEX_item_tl { \tl_trim_spaces:n {#2} }

\__listsEX_restore_dollar:

% --------------------------------------------------------------------------
% choice box:

\bool_new:N \l__listsEX_choice_checked_bool

\dim_new:N \l__listsEX_choice_width_dim

\dim_set:Nn \l__listsEX_choice_width_dim { 1.25ex }

\dim_new:N \l__listsEX_choice_linewidth_dim

\dim_set:Nn \l__listsEX_choice_linewidth_dim { .3pt }

\dim_new:N \l__listsEX_choice_checkwidth_dim

\dim_set:Nn \l__listsEX_choice_checkwidth_dim { .5pt }

\dim_new:N \l__listsEX_choice_raise_dim

\dim_set:Nn \l__listsEX_choice_raise_dim { .1ex }

\cs_new_protected:Npn \listsEX_choice:

\leavevmode

\group_begin:

\bool_set_false:N \l__listsEX_choice_checked_bool

\box_move_up:nn

{ \l__listsEX_choice_raise_dim }

{ \hbox:n { \__listsEX_choice: } }

\group_end:

\cs_new_protected:Npn \listsEX_choice_checked:

\leavevmode

\group_begin:

\bool_set_true:N \l__listsEX_choice_checked_bool

\box_move_up:nn
{ \l__listsEX_choice_raise_dim }

{ \hbox:n { \__listsEX_choice: } }

\group_end:

\cs_new_protected:Npn \__listsEX_choice:

{%

\dim_set:Nn \unitlength { .1\l__listsEX_choice_width_dim }

\begin{picture}(10,0)

\linethickness \l__listsEX_choice_linewidth_dim

\drawline(0,0)(0,10)(10,10)(10,0)(0,0)

\linethickness \l__listsEX_choice_checkwidth_dim

\bool_if:NT \l__listsEX_choice_checked_bool

\drawline(2,2)(8,8)

\drawline(2,8)(8,2)

\end{picture}%

\providecommand* \choicebox { \listsEX_choice: }

\providecommand* \checkedchoicebox { \listsEX_choice_checked: }

% --------------------------------------------------------------------------

% base instance:

% ALPHABETIZE: a) b) c)

\DeclareInstance {listsEX} {alphabetize} {default} { }


\keys_define:nn {listsEX/list}

debug .bool_set:N = \l__listsEX_debug_bool ,

style .tl_set:N = \l__listsEX_instance_tl ,

style .initial:n = alphabetize ,

counter-format .tl_set:N = \l__listsEX_custom_label_pattern_tl ,

label .code:n =

\bool_set_true:N \l__listsEX_custom_label_bool

\tl_set:Nn \l__listsEX_custom_label_tl {#1} ,

label-format .tl_set:N = \l__listsEX_custom_label_format_tl ,

label-width .code:n =

\dim_set:Nn \l__listsEX_label_width_dim {#1}

\bool_set_true:N \l__listsEX_label_width_bool ,

label-offset .code:n =

\dim_set:Nn \l__listsEX_label_offset_dim {#1}

\bool_set_true:N \l__listsEX_label_offset_bool ,

label-align .tl_set:N = \l__listsEX_label_align_tl ,

item-format .tl_set:N = \l__listsEX_custom_item_format_tl ,

item-indent .code:n =

\dim_set:Nn \l__listsEX_item_indent_dim {#1}

\bool_set_true:N \l__listsEX_item_indent_bool ,

column-sep .dim_set:N = \l__listsEX_column_sep_dim ,

before-skip .skip_set:N = \l__listsEX_before_list_skip ,

after-skip .skip_set:N = \l__listsEX_after_list_skip ,

after-item-skip .code:n =

\bool_set_true:N \l__listsEX_custom_after_item_skip_bool

\skip_set:Nn \l__listsEX_custom_after_item_skip {#1} ,

resume .bool_set:N = \l__listsEX_resume_bool


}

% --------------------------------------------------------------------------

% the generic environment:

\NewEnviron {__listsEX_env:} [3]

\if@inlabel

\noindent\par\nobreak\vskip-\parskip\vskip-\baselineskip\hrule\@height\z@

\fi

\dim_compare:nNnF { \l__listsEX_before_list_skip } = { 0pt }

{ \vspace {\l__listsEX_before_list_skip} }

\list {}

\keys_set:nn {listsEX/list} {#2}

\dim_set:Nn \leftmargin {0pt}

\dim_set:Nn \rightmargin {0pt}

\item \scan_stop:

\int_incr:N \l__listsEX_depth_int

\__listsEX:VnnV \l__listsEX_instance_tl {#3} {#1} \BODY

\endlist

\dim_compare:nNnF { \l__listsEX_after_list_skip } = { 0pt }

{ \vspace {\l__listsEX_after_list_skip} }

% --------------------------------------------------------------------------

% command to start a new row:

\cs_new_protected:Npn \listsEX_new_row:
{

\int_gset:Nn \g__listsEX_total_items_int

\g__listsEX_total_items_int +

\l__listsEX_columns_int -

\g__listsEX_current_col_num_int

\__listsEX_gset_rows_num:NN

\g__listsEX_total_items_int

\l__listsEX_columns_int

\int_gset_eq:NN \g__listsEX_current_col_num_int \l__listsEX_columns_int

\NewDocumentCommand \startnewitemlineEX {}

{ \listsEX_new_row: }

% --------------------------------------------------------------------------

% the user environment:

\NewDocumentCommand \NewListsEX { O{}mO{\listEX}D(){1} }

\NewDocumentEnvironment {#2} { O{}D(){#4} }

{ \__listsEX_env: {#3} { #1,##1 } {##2} }

{ \end__listsEX_env: }

% --------------------------------------------------------------------------

% default list:

\NewListsEX {listsEX}
\file_if_exist:nT {listsEX.cfg} { \file_input:n {listsEX.cfg} }

% --------------------------------------------------------------------------

% setup:

\cs_new_protected:Npn \listsEX_setup:n #1

{ \keys_set:nn {listsEX/list} {#1} }

\NewDocumentCommand \setlistsEX { m }

{ \listsEX_setup:n {#1} }

\newcommand{\StartNumber}[1]{

\int_gset:Nn \g__listsEX_int {#1}

%tasks

\NewListsEX{taskEX}[\item]

\NewEnviron{listEX}[1][]{%

\ifthenelse{\equal{#1}{}}{%

\begin{enumerate}[a)]%

\BODY%

\end{enumerate}%

}{%

\ifthenelse{\equal{#1}{1}}%

{%

\begin{enumerate}[a)]%

\BODY%

\end{enumerate}%

}%

{\def\tempbegin{\begin{taskEX}(#1)}%
\expandafter\tempbegin\BODY%

\end{taskEX}}%

}%

\NewEnviron{enumEX}[2][]{%

\ifthenelse{\equal{#2}{1}}

\ifthenelse{\equal{#1}{}}

\begin{enumerate}

\BODY

\end{enumerate}

\begin{enumerate}[#1]

\BODY

\end{enumerate}}

\ifthenelse{\equal{#1}{}}{%

\def\tempbegin{\begin{taskEX}[counter-format=tsk[a])](#2)}%

}{%

\ifthenelse{\equal{#1}{a.}}{%

\def\tempbegin{\begin{taskEX}[counter-format=tsk[a].](#2)}%

}{

\ifthenelse{\equal{#1}{(a)}}{%

\def\tempbegin{\begin{taskEX}[counter-format=(tsk[a]),label-width=1.3em](#2)}%

}{
\ifthenelse{\equal{#1}{a)}}{%

\def\tempbegin{\begin{taskEX}[counter-format=tsk[a])](#2)}%

}{

\ifthenelse{\equal{#1}{A.}}{%

\def\tempbegin{\begin{taskEX}[counter-format=tsk[A].](#2)}%

}{

\ifthenelse{\equal{#1}{(A)}}{%

\def\tempbegin{\begin{taskEX}[counter-format=(tsk[A]),label-width=1.3em](#2)}%

}{

\ifthenelse{\equal{#1}{A)}}{%

\def\tempbegin{\begin{taskEX}[counter-format=tsk[A])](#2)}%

}{

\ifthenelse{\equal{#1}{1.}}{%

\def\tempbegin{\begin{taskEX}[counter-format=tsk[1].](#2)}%

}{

\ifthenelse{\equal{#1}{(1)}}{%

\def\tempbegin{\begin{taskEX}[counter-format=(tsk[1]),label-width=1.3em](#2)}%

}{

\ifthenelse{\equal{#1}{1)}}{%

\def\tempbegin{\begin{taskEX}[counter-format=tsk[1])](#2)}%

}{

\ifthenelse{\equal{#1}{i.}}{%

\def\tempbegin{\begin{taskEX}[counter-format=tsk[r].](#2)}%

}{

\ifthenelse{\equal{#1}{(i)}}{%

\def\tempbegin{\begin{taskEX}[counter-format=(tsk[r]),label-width=1.4em](#2)}%

}{

\ifthenelse{\equal{#1}{i)}}{%
\def\tempbegin{\begin{taskEX}[counter-format=tsk[r])](#2)}%

}{

\ifthenelse{\equal{#1}{I.}}{%

\def\tempbegin{\begin{taskEX}[counter-format=tsk[R].,label-width=1.4em](#2)}%

}{

\ifthenelse{\equal{#1}{(I)}}{%

\def\tempbegin{\begin{taskEX}[counter-format=(tsk[R]),label-width=1.6em](#2)}%

}{

\ifthenelse{\equal{#1}{I)}}{%

\def\tempbegin{\begin{taskEX}[counter-format=tsk[R]),label-width=1.4em](#2)}%

}{

\def\tempbegin{\begin{taskEX}[label=#1](#2)}%

}}}}}}}}}}}}}}}

\expandafter\tempbegin\BODY

\end{taskEX}

\NewEnviron{enumEXV}[2][]{%

\ifthenelse{\equal{#1}{}}

\begin{multicols}{#2}

\begin{enumerate}

\BODY

\end{enumerate}

\end{multicols}

{
\begin{multicols}{#2}

\begin{enumerate}[#1]

\BODY

\end{enumerate}

\end{multicols}

}%

%End of file `ex_test.sty'.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy