\RequirePackage{paralist}
\documentclass[full,kernel]{l3doc}
\usepackage[dvipsnames]{xcolor}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\RequirePackage{morewrites}
\RequirePackage{tikzinput}
\usetikzlibrary{fit}

\usepackage[debug=all,lang=en, mathhub=./tests]{stex}
\usepackage{url,array,float,textcomp}
\usepackage[show]{ed}
\usepackage[hyperref=auto,style=alphabetic]{biblatex}
\addbibresource{\bibfolder/kwarcpubs.bib}
\addbibresource{\bibfolder/extpubs.bib}
\addbibresource{\bibfolder/kwarccrossrefs.bib}
\addbibresource{\bibfolder/extcrossrefs.bib}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{xspace}
\usepackage{hyperref}

\makeindex
\floatstyle{boxed}
\newfloat{exfig}{thp}{lop}
\floatname{exfig}{Example}

\usepackage{listings}

\ExplSyntaxOn

\keys_define:nn { stex-tests } {
	do	.bool_set:N   = \stex_dtx_tests_bool
}

\ProcessKeysOptions { stex-tests }

\prg_new_conditional:Nnn \stex_indtx: { T } {
  \bool_if:NTF \stex_dtx_tests_bool
  	\prg_return_true: \prg_return_false:
}

\ExplSyntaxOff

\lstdefinestyle{mylatex}{	
	keywordstyle=\color{BurntOrange}
}
\lstdefinelanguage{mylatex}{
	emphstyle=\underbar,
	alsodigit={:},
	%alsoletter={_},
	alsoletter={\\}
	sensitive=true,
	classoffset=0,keywordstyle=\bfseries,
	morekeywords={\\begin,\\end,\\ExplSyntaxOn,\\ExplSyntaxOff},	
	classoffset=1,keywordstyle=\color{blue},
	morekeywords={
		\\symdecl,
		\\symdef,
		\\notation,
		\\abbrdef,
		\\importmodule,
		\\usemodule,
		\\STEXwithbrackets,
		\\symref
	},
	classoffset=2,keywordstyle=\color{Purple},
	morekeywords={
		\\stex_path_from_string:Nn,
		\\stex_path_to_string:NN,
		\\stex_path_to_string:N,
		\\stex_require_repository:n,
		\\stex_modules_current_namespace:,
		\\stex_debug:n,
		\\stex_set_current_repository:n,
		\\stex_file_in_smsmode:nn,
		\\stex_get_symbol:n,
	},
	classoffset=3,keywordstyle=\color{SkyBlue},
	morekeywords={
		\\l_stex_modules_ns_str,
		\\g_stex_currentfile_seq,
		\\l_stex_current_module_prop,
		\\l_stex_get_symbol_uri_str,
	}
	classoffset=0,
%^^A	morecomment=[l][\color{Gray}]{//},
%^^A	morecomment=[s][\color{Gray}]{/*}{*/},
	morecomment=[s][\color{Green}]{$}{$},,
	morecomment=[s][\color{OliveGreen}]{\\[}{\\]},
%^^A  morestring=[b][\color{Purple}]\$,
}
\lstnewenvironment{latexcode}[1][language=mylatex]{\lstset{language=mylatex,basicstyle=\tiny,inputencoding=utf8,#1,alsoletter={\\,*},alsoother={\$}}}{}



\usepackage{mdframed,realboxes}
\usepackage[most]{tcolorbox}
\usepackage{caption}

\newenvironment{framed}{\begin{mdframed}\begin{center}}{\end{center}\end{mdframed}}
\newcommand{\scaled}[2][0.9\hsize]{\begin{center}\resizebox{#1}{!}{\begin{minipage}{\textwidth} #2 \end{minipage}}\end{center}}

\newenvironment{stextest@output}
{
  \begin{mdframed}[linewidth=1pt,backgroundcolor=white]\tiny
}
{\end{mdframed}}

\newenvironment{stextest@input}
{
  \begin{mdframed}[linewidth=1pt,backgroundcolor=lightgray]\tiny
}
{\end{mdframed}}

\makeatletter

\newcount\test@counter\test@counter=0
\newcount\example@counter\example@counter=0

\newenvironment{stextest@border}
{
  \global\advance\test@counter by 1
  \newtcolorbox{stextestborderbox}{
    empty,
    title={Test \the\test@counter},
    attach boxed title to top left,
       minipage boxed title,
    boxed title style={empty,size=minimal,toprule=0pt,top=4pt,left=3mm,overlay={}},
    coltitle=red,fonttitle=\bfseries,
    before=\par\medskip\noindent,parbox=false,boxsep=0pt,left=3mm,right=0mm,top=2pt,breakable,pad at break=0mm,
       before upper=\csname @totalleftmargin\endcsname0pt, 
    overlay unbroken={\draw[red,line width=2pt] ([xshift=-0pt]title.north west) -- ([xshift=-0pt]frame.south west); },
    overlay first={\draw[red,line width=2pt] ([xshift=-0pt]title.north west) -- ([xshift=-0pt]frame.south west); },
    overlay middle={\draw[red,line width=2pt] ([xshift=-0pt]frame.north west) -- ([xshift=-0pt]frame.south west); },
    overlay last={\draw[red,line width=2pt] ([xshift=-0pt]frame.north west) -- ([xshift=-0pt]frame.south west); },
    }
%^^A\refstepcounter{remark}
\begin{stextestborderbox}\small
}
{\end{stextestborderbox}}

\newenvironment{example@border}
{
  \global\advance\example@counter by 1
  \newtcolorbox{exampleborderbox}{
    empty,
    title={Example \the\example@counter},
    attach boxed title to top left,
       minipage boxed title,
    boxed title style={empty,size=minimal,toprule=0pt,top=1pt,left=3mm,overlay={}},
    coltitle=blue,fonttitle=\bfseries,
    parbox=false,boxsep=0pt,left=3mm,right=0mm,top=2pt,breakable,pad at break=0mm,
       before upper=\csname @totalleftmargin\endcsname0pt, 
    overlay unbroken={\draw[blue,line width=2pt] ([xshift=-0pt]title.north west) -- ([xshift=-0pt]frame.south west); },
    overlay first={\draw[blue,line width=2pt] ([xshift=-0pt]title.north west) -- ([xshift=-0pt]frame.south west); },
    overlay middle={\draw[blue,line width=2pt] ([xshift=-0pt]frame.north west) -- ([xshift=-0pt]frame.south west); },
    overlay last={\draw[blue,line width=2pt] ([xshift=-0pt]frame.north west) -- ([xshift=-0pt]frame.south west); },
    }
%^^A\refstepcounter{remark}
\begin{exampleborderbox}\small
}
{\end{exampleborderbox}}

 \makeatother
 
\def\present#1{\texttt{>>\meaning#1<<}}
\def\printltx#1{\texttt{\detokenize{#1}}}

\newwrite\testoutfile
\def\testfile{0}

\ExplSyntaxOn

\AddToHook{begindocument}{
  \stex_indtx:T {
	\newwrite\alltestsoutfile
	\immediate\openout\alltestsoutfile=alltests.tst
  }
}

  \def\stextest{
    \begingroup 
    \catcode`\\=12\relax
    \catcode`\#=12\relax
    \catcode`\&=12\relax
    \catcode`\$=12\relax
    \catcode`\^=12\relax
    \catcode`\_=12\relax
    \catcode`^^J=12\relax
    \endlinechar=`^^J
    \newlinechar=-1
%^^A    \everyeof{\noexpand}
    \test_a:n
  }
  \long\def \test_a:n #1 {
    \endgroup
    \stex_indtx:T {
    	\immediate\write\alltestsoutfile{%
    		^^J\c_backslash_str stextest{\detokenize{^^J^^J#1^^J}}^^J
    	}
    }
    \begin{stextest@border}
      \immediate\openout\testoutfile=stextest.tst
      \immediate\write\testoutfile{
        \c_backslash_str begin{latexcode}
        \detokenize{^^J^^J#1^^J}
        \c_backslash_str end{latexcode}
      }
      \immediate\closeout\testoutfile
      \begin{stextest@input}
        \catcode`\#=12\relax
        \input{stextest.tst}
      \end{stextest@input}
      \immediate\openout\testoutfile=stextest.tst
      \immediate\write\testoutfile{\detokenize{#1}}
      \immediate\closeout\testoutfile
      \stex_indtx:T {
        \begin{stextest@output}
          \input{stextest.tst}
        \end{stextest@output}
      }
    \end{stextest@border}
  }

  \def\stexexample{
    \begingroup 
    \catcode`\\=12\relax
    \catcode`\#=12\relax
    \catcode`\&=12\relax
    \catcode`\$=12\relax
    \catcode`\^=12\relax
    \catcode`\_=12\relax
    \catcode`^^J=12\relax
    \endlinechar=`^^J
    \newlinechar=-1
%^^A    \everyeof{\noexpand}
    \example_a:n
  }
  \long\def \example_a:n #1 {
    \endgroup
    \begin{example@border}
      \immediate\openout\testoutfile=stextest.tst
      \immediate\write\testoutfile{
        \c_backslash_str begin{latexcode}
        \detokenize{^^J}#1
        \c_backslash_str end{latexcode}
      }
      \immediate\closeout\testoutfile
      \begin{stextest@input}
        \catcode`\#=12\relax
        \input{stextest.tst}
      \end{stextest@input}
      \immediate\openout\testoutfile=stextest.tst
      \immediate\write\testoutfile{#1}
      \immediate\closeout\testoutfile
      \begin{stextest@output}
        \input{stextest.tst}
      \end{stextest@output}
    \end{example@border}
  }

  \long\def\test#1{}

\ExplSyntaxOff


\MakeShortVerb{\|}

\def\scsys#1{{{\sc #1}}\index{#1@{\sc #1}}\xspace}
\def\mmt{\textsc{Mmt}\xspace}
\def\xml{\scsys{Xml}}
\def\mathml{\scsys{MathML}}
\def\omdoc{\scsys{OMDoc}}
\def\openmath{\scsys{OpenMath}}
\def\latexml{\scsys{LaTeXML}}
\def\perl{\scsys{Perl}}
\def\cmathml{Content-{\sc MathML}\index{Content {\sc MathML}}\index{MathML@{\sc MathML}!content}}
\def\activemath{\scsys{ActiveMath}}
\def\twin#1#2{\index{#1!#2}\index{#2!#1}}
\def\twintoo#1#2{{#1 #2}\twin{#1}{#2}}
\def\atwin#1#2#3{\index{#1!#2!#3}\index{#3!#2 (#1)}}
\def\atwintoo#1#2#3{{#1 #2 #3}\atwin{#1}{#2}{#3}}
\def\cT{\mathcal{T}}\def\cD{\mathcal{D}}

\def\fileversion{3.0}
\def\filedate{\today}

\RequirePackage{pdfcomment}

\ExplSyntaxOn\makeatletter
\cs_set_protected:Npn \@comp #1 #2 {
  \pdftooltip {
    \textcolor{blue}{#1}
  } { #2 }
}

\cs_set_protected:Npn \@defemph #1 #2 {
  \pdftooltip { 
    \textbf{\textcolor{magenta}{#1}}
  } { #2 }
}

\def\__omtext_lec#1{#1}
\cs_new_protected:Npn \lec #1 {
  \strut\hfil\strut\null\hfill\__omtext_lec{#1}
}
\makeatother\ExplSyntaxOff

\makeatletter
\let\@stex@oldcomment\comment
\let\@stex@oldendcomment\endcomment

%\RequirePackage{comment}
\RequirePackage{document-structure}
\RequirePackage[hints,solutions,notes]{problem}
\RequirePackage{hwexam}

\let\comment\@stex@oldcomment
\let\endcomment\@stex@oldendcomment

\newif\ifinfulldoc\infulldocfalse
\makeatother

\def\basedocurl{https://github.com/slatex/sTeX/blob/latex3/doc}
\newcounter{module}

\NewDocumentEnvironment {module}{}{
  \stepcounter{module}
  \textbf{Module \themodule: \smoduletitle}
}{

}
\stexpatchmodule{\begin{module}}{\end{module}}

\def\compemph#1{\textcolor{blue}{#1}}
\def\symrefemph#1{\textcolor{green}{#1}}

\RequirePackage{pdfcomment}
\makeatletter
\protected\def\compemph@uri#1#2{%
  \pdftooltip{%
    \srefsymuri{#2}{\compemph{#1}}%
  }{%
    URI: \detokenize{#2}%
  }%
}
\protected\def\symrefemph@uri#1#2{%
  \pdftooltip{%
    \srefsymuri{#2}{\symrefemph{#1}}%
  }{%
    URI: \detokenize{#2}%
  }%
}
\makeatother