\ProvidesPackage{rustex}[2025/11/11]
\RequirePackage{xspace}

\ifcsname if@rustex\endcsname\else
	\expandafter\newif\csname if@rustex\endcsname
	\@rustexfalse
\fi

\if@rustex\else
	% usage: plain HTML as argument, e.g.
	% \rustex@HTMLLiteral{<div>foo</div>}
	\def\rustex@HTMLLiteral#1{}
	
	% usage: First argument: attributes and styles
	% attribute names may contain URL prefixes
	% styles should be prefixed with style:
	% second argument: The stuff that gets annotated
	% e.g.
	%\rustex@annotateHTML{rustex:mycolor="grey" style:fontsize="150\%"}hello\rustex@annotateHTMLEnd
	\def\rustex@annotateHTML#1{}
	\def\rustex@annotateHTMLEnd{}

	%similar, but additionally takes a tag name, e.g.
	%\rustex@HTMLNode{h3}{rustex:mycolor="grey" style:fontsize="150\%"}hello\rustex@annotateHTMLEnd
	\def\rustex@HTMLNode#1#2{}

	%adds a CSS link node to the header of the document, e.g.
	%\rustex@cssLink{rustex.css}
	% inserts <link rel="stylesheet" href="rustex.css"/>
	\def\rustex@cssLink#1{}

	% adds a CSS literal node to the header of the document, e.g.
	%\rustex@cssLiteral{body { color: red; }}
	% inserts <style>body { color: red; }</style>
	\def\rustex@cssLiteral#1{}

	% e.g. \rustex@addNamespaceAbbrev{stex}{http://kwarc.info/ns/sTeX}
	\def\rustex@addNamespaceAbbrev#1#2{}


	\def\rustexBREAK{}
\fi

\ifcsname ExplSyntaxOn\endcsname
	\ExplSyntaxOn
		\prg_new_conditional:Nnn \rustex_if: {p, T, F, TF} {
			\if@rustex
				\prg_return_true:
			\else:
				\prg_return_false:
			\fi:
		}
		\rustex_if:TF {
			\cs_new_protected:Nn\rustex_HTML_literal:n {
				\cs:w rustex@HTMLLiteral\cs_end:{#1}
			}
			\cs_set_eq:Nc\rustex_annotate_HTML_begin:n {rustex@annotateHTML}
			\cs_set_eq:Nc\rustex_HTML_node_begin:nn {rustex@HTMLNode}
			\cs_set_eq:Nc\rustex_annotate_HTML_end: {rustex@annotateHTMLEnd}
			\cs_set_eq:Nc\rustex_css_link:n {rustex@cssLink}
			\cs_set_eq:Nc\rustex_css_literal:n {rustex@cssLiteral}

			\cs_new_protected:Nn\rustex_annotate_HTML:nn {
				\rustex_annotate_HTML_begin:n{#1}
					#2
				\rustex_annotate_HTML_end:
			}
			\cs_new_protected:Nn\rustex_HTML_node:nnn {
				\rustex_HTML_node_begin:nn{#1}{#2}
					#3
				\rustex_annotate_HTML_end:
			}
			\cs_set_eq:Nc\rustex_add_Namespace:nn{rustex@addNamespaceAbbrev}
		}{
			\cs_new_protected:Nn\rustex_HTML_literal:n {}
			\cs_new_protected:Nn\rustex_annotate_HTML_begin:n {}
			\cs_new_protected:Nn\rustex_HTML_node_begin:nn {}
			\cs_new_protected:Nn\rustex_annotate_HTML_end: {}
			\cs_new_protected:Nn\rustex_css_link:n {}
			\cs_new_protected:Nn\rustex_css_literal:n {}
			\cs_new_protected:Nn\rustex_annotate_HTML:nn {#2}
			\cs_new_protected:Nn\rustex_HTML_node:nnn {#3}
			\cs_new_protected:Nn\rustex_add_Namespace:nn {}
		}
	\ExplSyntaxOff
\fi

\protected\def\RusTeX{%
  \@ifundefined{texorpdfstring}%
  {\let\texorpdfstring\@firstoftwo}%
  {}%
  \texorpdfstring{R\kern-0.1em\raise-0.1em\hbox{\scriptsize US}\kern-0.2em\TeX}{RusTeX}\xspace%
}
\let\rustex\RusTeX