\usepackage{hypdoc}
\PassOptionsToPackage{writefile}{listings}
\usepackage[
	loadHyperref=false,
	createIndexEntries=false
]{doctools}

\PageIndex
\EnableCrossrefs

\usepackage{lstdoc}
\usepackage{textcomp} % needed for listings
\usepackage{xparse}
\usepackage{xkeyval}
\usepackage{changepage}
\usepackage{mdframed}

\usepackage[color]{changelog}

\errorcontextlines 10

\newcommand{\email}[1]{\href{mailto:#1}{\texttt{#1}}}
\newcommand{\https}[1]{\href{https://#1}{\texttt{#1}}}
\newcommand{\todo}[1]{\begin{itemize}\item[\textbf{To-do:}] #1 \end{itemize}}
\newcommand{\note}[1]{\begin{itemize}\item[\textbf{Note:}] #1 \end{itemize}}
\newcommand{\ctan}[1]{\href{https://ctan.org/pkg/#1}{\package{#1}}}
\NewExpandableDocumentCommand{\Th}{O{l} m}
	{\multicolumn{1}{#1}{\textbf{#2}}}
\newcommand{\ext}[1]{\texttt{.#1}}
\newcommand{\filename}[1]{\texttt{#1}}
\newcommand{\noterepo}[1]{\note{Browse the sources, contribute, or complain at \\
	\https{github.com/#1}}}

\newcommand{\cl}{\ctan{changelog}}
\newcommand{\keepachangelog}{\https{keepachangelog.com}}

% definition copied from doc package \DescribeMacro
\lstnewenvironment{latexfile}[1]
	{\lstset{style=lstDemoStyleLaTeXCode}%
	}
	{}

\NewDocumentEnvironment{ctandescription}{}
	{\NewDocumentCommand{\pkg}{m}{\item[\ctan{##1}]}
	\begin{description}}
	{\end{description}}

% a list of colors; use \color{colorname}
\newenvironment{colorlist}
	{\begin{itemize}
		\let\old@item\item
		\renewcommand{\item}[1]{%
			\old@item[\fcolorbox{black}{##1}{\vphantom{X}\hspace{1em}}]
			\texttt{##1}
		}
	}
	{\end{itemize}}

\newif\ifsidebyside@first
\newcommand{\sidebyside@maybehfill}{%
	\ifsidebyside@first
		\hfill
		\sidebyside@firstfalse
	\fi
}
\newenvironment{sidebyside}{%

	\lstnewenvironment{code}[1][]{%
		\lstset{style=lstDemoStyleLaTeXCode,
			basicstyle=\ttfamily\small,
			frame=single,
			linewidth=0.45\linewidth,
			##1}%
		}
		{%
		\sidebyside@maybehfill
		}%
	\newenvironment{example}{%
		\begin{mdframed}[userdefinedwidth=0.45\linewidth]
		}
		{%
		\end{mdframed}\sidebyside@maybehfill
		}%
	\sidebyside@firsttrue
	\medskip
	\noindent
	}
	{%
	}
