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 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
\colorlet{shadecolor}{gray!25}
\renewenvironment{leftbar}{%
  \def\FrameCommand{\textcolor{shadecolor}{\vrule width 3pt} \hspace{10pt}}%
  \MakeFramed {\advance\hsize-\width \FrameRestore}}%
{\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}
\colorlet{shadecolor}{gray!25}

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

\begin{document}
\begin{example}[This is a test]
   Bla
\end{example}    
\end{document}
share|improve this question
1  
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? –  neo Mar 1 '13 at 15:15
    
I just figured a way out: \newenvironment{example}[1][ ], a white space. Is this the right way? –  neo Mar 1 '13 at 15:16
    
No, it's wrong: you'll get parentheses anyway. –  egreg Mar 1 '13 at 15:21
add comment

1 Answer 1

up vote 8 down vote accepted

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}
\colorlet{shadecolor}{gray!25}

\usepackage{framed}
\renewenvironment{leftbar}{%
  \def\FrameCommand{\textcolor{shadecolor}{\vrule width 3pt} \hspace{10pt}}%
  \MakeFramed {\advance\hsize-\width \FrameRestore}}%
{\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}

enter image description here

However, I'd take an easier route.

\documentclass{article}

\usepackage{amsmath}
\usepackage{amsthm}

\usepackage[svgnames]{xcolor}
\colorlet{shadecolor}{gray!25}

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

\begin{document}

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

\begin{example}
Bla
\end{example}

\end{document}

enter image description here

share|improve this answer
    
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. –  neo 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 :) –  neo Mar 2 '13 at 14:10
add comment

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.