How to have upside down text in body?

I have environments Question (described in To clearly separate block inside a chapter) and Answer blocks. I want the Answer block be the same as as Question block but the text upside down in it.

Minimal example

\documentclass{article}
\usepackage{rotating}

\usepackage[framemethod=tikz]{mdframed}
\newtheorem{question}{Question}
\mdfdefinestyle{que}{
linecolor=cyan,
backgroundcolor=cyan!20,
}
\surroundwithmdframed[style=que]{question}

\mdfdefinestyle{ans}{
linecolor=cyan,
backgroundcolor=yellow!20
% , rotatebox
}

\begin{document}
\begin{question}
\textbf{E.coli.}
Escherichia coli ...
\end{question}
Lorem
\end{document}


I get

How can you have upside down text in the Answer environment? I want that the text is difficult to read so the readers try to answer the question themselves before looking for the answer. Any other way to include answers is also accepted, since I am not sure which is the best way to do it. I however want personally that those answer are visible in the draw code just after the question.

-
you could use \rotatebox – Seamus Feb 22 '14 at 12:01
In the linked answer which is the answer part? The one inside block? Which is the question? – Harish Kumar Feb 22 '14 at 12:29
I suggest you to add clarification: as it stands, to me is not clear at all what How can you have upside down text in such environment? does mean. – Claudio Fiandrino Feb 22 '14 at 12:38
Thank you for the comments! I finally got the minimal thing done. – Masi Feb 22 '14 at 14:34
You don't need to load the mdframed package twice. – Gonzalo Medina Feb 22 '14 at 15:25

See the last edit for automatic toggling

You can define a new environment Answer based on your answer environment:

\usepackage{environ}
{%
\noindent
\rotatebox[origin=c]{180}{%
\noindent
\begin{minipage}[t]{\linewidth}
\BODY
\end{minipage}%
}%
}%


Full code:

\documentclass{article}
\usepackage{rotating}

\usepackage[framemethod=tikz]{mdframed}
\newtheorem{question}{Question}
\mdfdefinestyle{que}{
linecolor=cyan,
backgroundcolor=cyan!20,
}
\surroundwithmdframed[style=que]{question}

\mdfdefinestyle{ans}{
linecolor=cyan,
backgroundcolor=yellow!20
% , rotatebox
}

\usepackage{environ}
{%
\noindent
\rotatebox[origin=c]{180}{%
\noindent
\begin{minipage}[t]{\linewidth}
\BODY
\end{minipage}%
}%
}%

\begin{document}
\begin{question}
\textbf{E.coli.}
Escherichia coli ...
\end{question}
Lorem ipsum is not an answer to this question but this text will provide some dummy answer for two lines all together.
\end{document}


Making it to difficult to read?. Here we go:

\documentclass{article}
\usepackage{rotating}

\usepackage[framemethod=tikz]{mdframed}
\newtheorem{question}{Question}
\mdfdefinestyle{que}{
linecolor=cyan,
backgroundcolor=cyan!20,
}
\surroundwithmdframed[style=que]{question}

\mdfdefinestyle{ans}{
linecolor=cyan,
backgroundcolor=yellow!20
% , rotatebox
}

\usepackage{environ}
{%
\noindent
\reflectbox{\rotatebox[origin=c]{180}{%
\noindent
\begin{minipage}[t]{\linewidth}
\BODY
\end{minipage}%
}%
}}%

\begin{document}
\begin{question}
\textbf{E.coli.}
Escherichia coli ...
\end{question}
Lorem ipsum is not an answer to this question but this text will provide some dummy answer for two lines all together.
\end{document}


With

\NewEnviron{Answer}
{%
\noindent
\scalebox{1}[-1]{\rotatebox[origin=c]{180}{%
\noindent
\begin{minipage}[t]{\linewidth}
\BODY
\end{minipage}%
}%
}}%


one gets

but beware of those who bring mirrors ;)

In fact, with \scalebox alone, the former orientations can be achieved without using \rotatebox.

Last edit:

If you want to automatically show/hide answers here is a way. See the commented code lines

%\setboolean{answers}{true}  %%% uncomment to show answers properly


Full code:

\documentclass{article}
\usepackage{rotating}

\usepackage[framemethod=tikz]{mdframed}
\newtheorem{question}{Question}
\mdfdefinestyle{que}{
linecolor=cyan,
backgroundcolor=cyan!20,
}
\surroundwithmdframed[style=que]{question}

\mdfdefinestyle{ans}{
linecolor=cyan,
backgroundcolor=yellow!20
% , rotatebox
}

\usepackage{environ}
\usepackage{ifthen}

{%
{%
\noindent
\begin{minipage}[t]{\linewidth}
\BODY
\end{minipage}%  here put what the command has to do when outside
}%
}%
{%
\noindent
\scalebox{1}[-1]{%
\noindent
\begin{minipage}[t]{\linewidth}
\BODY
\end{minipage}%
}%
}%
}%

\begin{document}
\begin{question}
\textbf{E.coli.}
Escherichia coli ...
\end{question}
Lorem ipsum is not an answer to this question but this text will provide some dummy answer for two lines all together.
\end{document}


With

\setboolean{answers}{false}


we get:

With

\setboolean{answers}{true}


we get:

With optional argument

\documentclass{article}
\usepackage{rotating}

\usepackage[framemethod=tikz]{mdframed}
\newtheorem{question}{Question}
\mdfdefinestyle{que}{
linecolor=cyan,
backgroundcolor=cyan!20,
}
\surroundwithmdframed[style=que]{question}

\mdfdefinestyle{ans}{
linecolor=cyan,
backgroundcolor=yellow!20
% , rotatebox
}

\usepackage{environ}

\def\invert{-1}
{%
\noindent
\scalebox{1}[#1]{%
\noindent
\begin{minipage}[t]{\linewidth}%
\BODY
\end{minipage}%
}%
}%

\begin{document}
\begin{question}
\textbf{E.coli.}
Escherichia coli ...
\end{question}
Lorem ipsum is not an answer to this question but this text will provide some dummy answer for two lines all together.

\begin{question}
\textbf{E.coli.}
Escherichia coli ...
\end{question}
Lorem ipsum is not an answer to this question but this text will provide some dummy answer for two lines all together.
\end{document}

-
Why loading mdframed twice? – Gonzalo Medina Feb 22 '14 at 15:24
What is the benefit of using the minipage here, instead of tikzpicture -environment, described in Gonzalo's answer? – Masi Feb 22 '14 at 15:34
@GonzaloMedina Thank you. As usual remnant. Corrected :) – Harish Kumar Feb 22 '14 at 22:09
@Masi: minipage will allow breaking the lines, otherwise rotatebox will not. – Harish Kumar Feb 22 '14 at 22:12
@Masi: Though your question in comment is good: What is the benefit of making it bold? (In other words: Let it be, this is not necessary, some people feel even upset with such things.) – Speravir Feb 23 '14 at 2:33

One idea is to define a new environment which places the answer contents inside a TikZ \node and rotates it:

\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{environ}
\usepackage{lipsum}

\newtheorem{question}{Question}
\mdfdefinestyle{que}{
linecolor=cyan,
backgroundcolor=cyan!20,
}
\surroundwithmdframed[style=que]{question}

\mdfdefinestyle{ans}{
linecolor=cyan,
backgroundcolor=yellow!20
}

\begin{tikzpicture}
\node[rotate=180,inner sep=0pt] {\parbox{\linewidth}{%
\BODY
\end{tikzpicture}%
}

\begin{document}

\begin{question}
\textbf{E.coli.}
Escherichia coli ...
\end{question}
Lorem

\begin{question}
\textbf{E.coli.}
Escherichia coli ...
\end{question}
\lipsum[4]

\end{document}


you can make things even harder for someone who decides to read the answer ;-)

\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{environ}
\usepackage{lipsum}

\newtheorem{question}{Question}
\mdfdefinestyle{que}{
linecolor=cyan,
backgroundcolor=cyan!20,
}
\surroundwithmdframed[style=que]{question}

\mdfdefinestyle{ans}{
linecolor=cyan,
backgroundcolor=yellow!20
}

\begin{tikzpicture}
\node[rotate=180,inner sep=0pt,xscale=-1] {\parbox{\linewidth}{%
\BODY
\end{tikzpicture}%
}

\begin{document}

\begin{question}
\textbf{E.coli.}
Escherichia coli ...
\end{question}
Lorem

\begin{question}
\textbf{E.coli.}
Escherichia coli ...
\end{question}
\lipsum[4]

\end{document}


-
I ask your opinion about the answer which I accepted above because I think least packages used is the best way to go so code keeps simple. I know you understand this topic better than me. What are the possible drawbacks without the Environ package? – Masi Feb 23 '14 at 18:51
@Masi No drawbacks; the answer you accepted also does what you need. The only advantage of my answer compared to the others is that with TikZ, you can also apply some other effects (opacity, etc.) but if no such effects are desired, then any of the other answers is perfectly valid and does what you required, And you're right, if no "special effects" are needed, the accepted answer has economy in the use of packages. – Gonzalo Medina Feb 23 '14 at 19:45
I just noticed that I need the backgrounds with text Draft in some of my documents: tex.stackexchange.com/questions/162026/… It may come a day when your answer is best one soon again. – Masi Feb 23 '14 at 22:57

Here's another solution that doesn't need the environ package because it uses a newsavebox instead.

The different part compared to the other answers is

\makeatletter
\newsavebox{\@my@box}
{%
\noindent
\begin{lrbox}{\@my@box}%
\begin{minipage}[t]{\linewidth}
}%
{%
\end{minipage}%
\end{lrbox}%
\rotatebox{180}{\usebox{\@my@box}}
}%


which, as you can see, stores the content of the environment in \@my@box and then rotates it using rotatebox from the graphicx package, which is automatically loaded by mdframed and tikz.

The output is the same as in the other answers.

% arara: pdflatex
\documentclass{article}

\usepackage[framemethod=tikz]{mdframed}
\newtheorem{question}{Question}
\mdfdefinestyle{que}{
linecolor=cyan,
backgroundcolor=cyan!20,
}
\surroundwithmdframed[style=que]{question}

\mdfdefinestyle{ans}{
linecolor=cyan,
backgroundcolor=yellow!20
}

\makeatletter
\newsavebox{\@my@box}
{%
\noindent
\begin{lrbox}{\@my@box}%
\begin{minipage}[t]{\linewidth}
}%
{%
\end{minipage}%
\end{lrbox}%
\rotatebox{180}{\usebox{\@my@box}}
}%

\begin{document}
\begin{question}
\textbf{E.coli.}
Escherichia coli ...
\end{question}