# Using environment argument inside a new environment doesn't work

I know it must be something trivial:

\documentclass{article}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}

\usepackage[svgnames]{xcolor}
\usepackage{framed} %http://www.latex-community.org/forum/viewtopic.php?f=44&t=5823
\renewenvironment{leftbar}{%
{\endMakeFramed}

\declaretheorem[name=Example]{exampleOri}
\newenvironment{example}[1]{\begin{leftbar}\begin{exampleOri}[#1]}{\end{exampleOri}\end{leftbar}}

\begin{document}

\begin{example}[This is a test]
Bla
\end{example}

\end{document}


Which results in Example 1 ([). This is a test] Bla. What is wrong here?

UPDATE: As it's not directly an answer to the question, but still useful, I wanted to post my final approach using the mdframed key in thmtools:

\documentclass{article}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage[framemethod=TikZ]{mdframed}

\usepackage[svgnames]{xcolor}

\declaretheorem[name=Example,
mdframed={
hidealllines=true,leftline=true,
rightmargin=0pt,innerrightmargin=0pt,
innerlinewidth=0pt,middlelinewidth=0pt,
skipabove=\topskip,skipbelow=\topskip}
]{example}

\begin{document}
\begin{example}[This is a test]
Bla
\end{example}
\end{document}

-
The argument to example is declared as mandatory, but you're using it with the syntax for optional arguments. – egreg Mar 1 '13 at 15:10
Ah! But if I use \newenvironment{example}[1][] then I get an error when I don't supply the argument. How does this work with \begin{exampleOri}[#1] then? – letmaik Mar 1 '13 at 15:15
I just figured a way out: \newenvironment{example}[1][ ], a white space. Is this the right way? – letmaik Mar 1 '13 at 15:16
No, it's wrong: you'll get parentheses anyway. – egreg Mar 1 '13 at 15:21

You're declaring the argument to example as mandatory, so it should be enclosed in braces.

\documentclass{article}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}

\usepackage[svgnames]{xcolor}

\usepackage{framed}
\renewenvironment{leftbar}{%
{\endMakeFramed}

\declaretheorem[name=Example]{exampleOri}
\newenvironment{example}[1][]
{\begin{leftbar}
\ifx\relax#1\relax
\begin{exampleOri}
\else
\begin{exampleOri}[#1]
\fi}
{\end{exampleOri}\end{leftbar}}

\begin{document}

\begin{example}[This is a test]
Bla
\end{example}

\begin{example}
Bla
\end{example}

\end{document}


However, I'd take an easier route.

\documentclass{article}

\usepackage{amsmath}
\usepackage{amsthm}

\usepackage[svgnames]{xcolor}

\usepackage[framemethod=TikZ]{mdframed}
\newmdtheoremenv[hidealllines=true,leftline=true,
innerlinewidth=0pt,middlelinewidth=0pt,
skipabove=\topsep,skipbelow=\topsep,
]{example}{Example}

\begin{document}

\begin{example}[This is a test]
Bla
\end{example}

\begin{example}
Bla
\end{example}

\end{document}


-
Thanks for the answer! :) I just wanted to mention that in my case using \leftbar is easier because then I can reuse my existing thmtools styles which I would have to recreate in mdframed. – letmaik Mar 1 '13 at 15:57
I discovered the mdframed key in thmtools. See the update I posted. Now I have the best of both worlds :) – letmaik Mar 2 '13 at 14:10