I would like to define an environment which "parses" its content and changes it before displaying it.
An additional difficulty comes because I also need to replace whitespaces. The more flexibility in the replacement tools (regex would be ideal) the better.
I'm aware or xstring's StrSubstitute and this solution here: How to replace text. Yet they do not help so far.
Example:
\begin{changecontent}
some text
some text
some text
\end{changecontent}
Simplified, what I would like to get from that is something like:
\command\\
~\command\\
~~\command\\
which then would compile into something where \command would be expanded to whatever it defined to before. This is an arbitrary example. It is not really crucial what this command is. It could be defined in the preamble, e.g. it could draw a tikz square or just expand to simple text.
The crucial steps are:
- keep spaces and newlines until the content is parsed, so that they can be used for the replacing part
do replacements: in regex that would be in this example:
- ^.* => \command\\
- ^\s.* => ~\command\\
- ^\s\s.* => ~~\command\\
expand the result and output
There are no restrictions in terms of how this should be implemented.
Is this asking to much of *TeX?

\commandxand\commandybe defined? – egreg Sep 05 '15 at 10:29