0

When defining a new theorem style in the amsthm package, you can specify what's called (according to http://web.mat.bham.ac.uk/R.W.Kaye/latex/thm.pdf) a custom head specification. In there, you can use "#3" to print to screen something specified by the argument. In my case I want to use the argument as a switch. More specifically, I'm writing a document with a series of Math problems and want an easy way to see which have already been done by my students. I want to implement it using newthmstyle so that it would work like this:

\begin{problem}
 blah blah
\end{problem} %prints a regular problem

\begin{problem}[done]
 blah blah
\end{problem} %prints a problem, which colors the "problem 5:" part green

I know how to do the coloring, it's been tested and it works. I can't figure out how to get the switch to work. If it's considerably easier, it may be a number, instead of "done" that does the switching.

I suppose there needs to be a way to do this, but I'm not proficient enough in Latex's semantics to get it working. I tried some things with the if statements but to no avail. Any ideas?

  • 3
    Welcome to TeX.SE! Could you add a complete but minimal working example (MWE) of what you tried so far. It makes it much more easier to help you! – CarLaTeX Dec 16 '18 at 15:43
  • the reference you link looks good, but you may want to also check out the "official" amsthm documentation (amsthdoc.pdf, on ctan), which was thoroughly revamped last year. (although it doesn't answer this particular question.) – barbara beeton Dec 23 '18 at 2:06
4

With \ifstrequal from etoolbox you can test #3 to get the desired problem head color.

\documentclass{article}
\usepackage{amsmath, amsthm}
\usepackage{etoolbox}
\usepackage{xcolor}

\newtheoremstyle{mystyle}% Name of the style
  {\topsep}% Space above
  {\topsep}% Space below
  {}% Body font
  {0pt}% Indent amount
  {\bfseries}% Theorem head font
  {}% Punctuation after theorem head (in this case empty because defined in the head spec)
  {.5em}% Space after theorem head
  {\ifstrequal{#3}{done}{\color{green}}{}\thmname{#1}\thmnumber{ #2:}}% Theorem head spec
\theoremstyle{mystyle}
\newtheorem{problem}{Problem}

\begin{document}
\begin{problem}
  blah blah
\end{problem} %prints a regular problem

\begin{problem}[done]
  blah blah
\end{problem} %prints a problem, which colors the "problem 5:" part green    

\begin{problem}
  blah blah
\end{problem} %prints a regular problem

\begin{problem}[done]
  blah blah
\end{problem} %prints a problem, which colors the "problem 5:" part green    
\end{document}

enter image description here

  • Why \parsep at the top and \topsep at the bottom? I believe it should be \topsep for both. – egreg Dec 21 '18 at 22:34
  • @egreg Corrected! – CarLaTeX Dec 22 '18 at 6:00

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.