# Including different sections of text based on different configuration

I'm writing a document in which will eventually be broken into different versions of different length. Most of the differences will just be which material is included in different versions. Is there a way to construct a setting that could be changed in the preamble which would determine which sections of text are included in the build? For example, something like:

This sentence is always included.
\level[2]{This sentence is included in the medium and long versions
\level[3]{, while this section is only in the long version}.}


which would produce:

\setlevel{1}:

This sentence is always included.

\setlevel{2}:

This sentence is always included. This sentence is included in the medium and long versions.

\setlevel{3}:

This sentence is always included. This sentence is included in the medium and long versions, while this section is only in the long version.

If you're willing to include some punctuation or spacing adjustments, then the following would suit your needs:

\documentclass{article}

\makeatletter
\newcommand{\setlevel}[1]{\gdef\@level{#1}}
\newcommand{\level}[2][\relax]{%
\unskip
\ifx\relax#1\else
\ifnum\@level<#1\else
#2%
\fi
\fi
}
\makeatother

\begin{document}

\setlevel{1}

This sentence is always included.
\level[2]{\@ This sentence is included in the medium and long versions%
\level[3]{, while this section is only in the long version}.}

\setlevel{2}

This sentence is always included.
\level[2]{\@ This sentence is included in the medium and long versions%
\level[3]{, while this section is only in the long version}.}

\setlevel{3}

This sentence is always included.
\level[2]{\@ This sentence is included in the medium and long versions%
\level[3]{, while this section is only in the long version}.}

\end{document}


Of course, nesting \level[<a>] inside \level[<b>] where <a><<b> won't help.