1

I have

\documentclass[11pt]{article}
\usepackage{amsthm}
\usepackage{etoolbox}
\newtoggle{sol}
\toggletrue{sol}
\newtheorem{theorem}{Theorem}
\begin{document}
\begin{theorem}
    Text
    \iftoggle{sol}{Text}
\end{theorem}
\end{document}

and I am getting and error sayin that \begin{theorem} was ended by \end{document}.

What might I be doing wrong?

  • Welcome to TeX.SX! Can you please expand the code snippets that you have posted to a full minimal working example. It is much easier to help you you if we can start with some code that illustrates your problem. A MWE should start with a \documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. It's really hard to trouble shoot an error if you are not given enough code to reproduce it. – Andrew Dec 5 '17 at 13:43
  • @Andrew: Done ... – Thomas Dec 5 '17 at 13:46
  • 1
    If should be \iftoggle{sol}{true code}{false code}. As you haven't given the false code the \end{theorem} is being eaten up and used as this instead, causing your error. – Andrew Dec 5 '17 at 13:48
3

\iftoggle expects three arguments. One for the toggle, one for the true-branch and one for false. You should use it like this:

\documentclass[11pt]{article}
\usepackage{amsthm}
\usepackage{etoolbox}
\newtoggle{sol}
\toggletrue{sol}
\newtheorem{theorem}{Theorem}
\begin{document}
\begin{theorem}
    Text
    \iftoggle{sol}{Text}{}
\end{theorem}
\end{document}

Without the additional {} \end gets eaten by \iftoggle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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