I have defined a custom environment with an option to either display a title or not (using the \xifthen package, I am not sure if that is the best approach but works so far).
\documentclass{report}
\usepackage{xifthen}
\newcounter{mycnt}[chapter]%
\renewcommand{\themycnt}{\thechapter.\arabic{mycnt}}
\newenvironment{myenv}[1][]{%
\ifthenelse{\equal{#1}{notitle}}
{\par\medskip\noindent}
{
\refstepcounter{mycnt}%
\par\medskip\noindent\textbf{Test\ \themycnt}%
\par\medskip\noindent}
}{%
\par\medskip\ignorespacesafterend\noindent%
}
\begin{document}
\chapter{Introduction}
\section{A Section}
Some text
\begin{myenv} \label{test:one}
Some text within environment (why does it begin with that weird space?)
\end{myenv}
As Test~\ref{test:one} demonstrates ...
\begin{myenv}[notitle]
Some text within environment with no title
\end{myenv}
\begin{myenv} \label{test:two}
Some text within environment
\end{myenv}
As Test~\ref{test:two} demonstrates ...
\section{Another Section}
Now let us look again at Test~\ref{test:one} already shown in the previous section:
\begin{myenv} % maybe another option, such as [repeated] ?
Some text within environment (how to get this to be repeated as Test 1.1?)
\end{myenv}
\end{document}
Now, aside from the option to not show the title (and thus also not step the counter), in my document I would also like to be able to have a second option to repeat the contents of an environment already printed earlier, so that I can refer to Test 1.1, for example, in a subsequent section or chapter again, but still reflecting the number from where it first occurred, i.e., 1.1.
BTW, there seems to be also a weird space in the first line of the environment, where I have no clue where it's coming from. Anyone able to spot the error?
Note: In the end I plan to include the individual parts using the environment by using \input{filename.tex}. Ideally I'd like to have the \begin{myenv} label{somelabel} line in that filename.tex, so if there was a way to let it repeat the numbering automatically when it finds a label that is repeated that'd be wonderful. Or is that too much to ask for? If this is too complicated I could also \begin my environment before \inputting the file.
EDIT: Maybe for the latter scenario it would in fact better not to \begin, \label, and \end the environment within the file to \input but rather to define a command that would take as argument the {filename} and execute
\begin{myenv}\label{#1}\input{#1}\end{myenv}
Nonetheless I would first need help figuring out how to implement the option that would let me repeat environments. Any suggestions highly appreciated.
EDIT2: Clarification: Ideally I'd want to have three options of repeating an environment.
(1) The contents without a title (this works fine as I've implemented it but maybe there's a better way):
\begin{myenv}[notitle]\input{file1}\end{myenv}
(2) Repeat the same contents and also repeat the same title.
\begin{myenv}[repeatedtitle]\input{file1}\end{myenv}
(3) Repeat only part of the content (i.e., \input a different file) but repeat the title.
\begin{myenv}[repeatedtitle]\input{partoffile1}\end{myenv}


myenv? Do you want the entire contents to be repeated? Or do you want just the\labelto reference something previously mentioned. – Werner Oct 17 '16 at 03:39\inputthe same external file a second time, but now I'm thinking it could also be useful to be able to repeat the label number and in the content only put, let's say, lines 1-2 of a "test" that has a total of 5 lines. – jan Oct 17 '16 at 06:20\begin{myenv}[label=X] ... \end{myenv},\begin{myenv}[title=false] ... \end{myenv},\begin{myenv}[repeat=X] ... \end{myenv}... – Werner Oct 17 '16 at 06:24