Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to define an environment having two parts, i.e.

 \begin{myenv}
     some text
 \nextpart{myenv}
     some more
 \end{myenv}

I think I could do this by exploring the definition of \begin, \end, and \newenvironment, but I wonder if somebody has already done so.

share|improve this question
    
We will need to know a bit more about what you want to achieve: I don't really see what the 'two parts' mean here. –  Joseph Wright Feb 27 '13 at 9:03
    
Maybe you could define you environment, and inside the definition, add a switch (\nextpart) that will change stuff in your environment (IMO, you do not need to repeat "myenv"). I think that the command \appendix work like that in the environment "document"... –  Lionel MANSUY Feb 27 '13 at 9:07
    
what type of features you would like the "\nextpart{} some more" have.eg bold,italic etc.. What is the differentiating feature between the two parts ? –  texenthusiast Feb 27 '13 at 9:13
    
Thank you all for your comments and suggestions. I was asking the question in general, but it arose when trying to do a "side-to-side text" environment. Concretely, I am typesetting a draft revision of the articles of association of some organisation, and in some parts, I want to present two versions side-to-side (people in the organisation have submitted contradictory amendments and we need to vote on this). So the two parts are the two conflicting versions, and they contain complex things (\par, \label, \ref, etc.) –  YS1 Mar 2 '13 at 19:18

1 Answer 1

I have done something similar; in my experience, it was an environment that has

  1. a question
  2. a proof / answer

Here's an example:

\documentclass{article}
\usepackage{amsthm}

\newenvironment{questionanswer}{
  \newcommand{\nextpart}{\end{quote}\begin{proof}}
  \begin{quote}%
  }{%
  \end{proof}%
}

\begin{document}
\begin{questionanswer}
  Something to be quoted.
  \nextpart
  Something to be proven.
\end{questionanswer}
\end{document}

To my understanding, this is expanded to exactly

\begin{document}
\begin{quote}
  Something to be quoted.
  \end{quote}\begin{proof}
  Something to be proven.
\end{proof}
\end{document}

Note that by using \renewcommand, this can be arbitrarily complex:

\documentclass{article}
\usepackage{amsthm}
\usepackage{amsmath}

\newenvironment{questionanswer}{%
  \newcommand{\nextpart}{\end{quote}\begin{proof}%
    \renewcommand{\nextpart}{\end{proof}\begin{itemize}%
    \renewcommand{\nextpart}{\end{itemize}\begin{enumerate}%
    \renewcommand{\nextpart}{\end{enumerate}\begin{equation}%
  }}}}% As you can see, this can be arbitrarily complex
  % (just be careful of your braces!)
  \begin{quote}%
}{%
  \end{equation}%
}

\begin{document}
Some normal text.
\begin{questionanswer}
  Something to be quoted.
  \nextpart
  Something to be proven.
  \nextpart
  \item one
  \item two
  \nextpart
  \item enum a
  \item enum b
  \nextpart
  \sum_0^\infty a_n := \lim_{n\to\infty}\sum_0^n a_n
\end{questionanswer}
\end{document}

Complex output

share|improve this answer
    
Thanks for your suggestion ; this is what I am doing currently, except the two sub-environments are of the same kind right now. What I am wondering is: does this nest nicely ? –  YS1 Mar 2 '13 at 19:23
    
@YS1 It's certainly extensible (see edit), but I'm not sure what you mean by 'nesting' -- could you edit your question with an ideal use-case and what it should do? It's probably possible, I just don't really know what you'd use it for (and it might be quite awkward because of recursion, if I understand you correctly). –  Sean Allred Mar 2 '13 at 21:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.