5

I want to create the following exercise environment, for exercises:

exercise

That is, insert a black triangle right symbol, ▸, before the header of the exercise.

To accomplish this, I would prefer to use the two packages amsthm together with thmtools and its declaretheoremstyle command.

In the thmtools manual, subsection 1.3.1, they say that

There is one important thing you cannot see in this example: there are more keys you can pass to \declaretheoremstyle[.]

(other than

  • spaceabove, spacebelow
  • headfont
  • notefont, notebraces
  • bodyfont
  • postheadspace
  • qed )

So, is there such a key that prepends a glyph to the header?

I am not familiar with plain TeX, and therefore can't answer my own question just by looking at the dtx and sty files of the package repository.

So that a MWE would be

\documentclass{book}
\usepackage{fontspec}

\usepackage{amsthm,amssymb,thmtools}
\declaretheoremstyle[
⟨insert glyph before head key = value is ▸⟩
]{mystyle}
\declaretheorem[style=mystyle]{exercise}

\begin{document}

\chapter{Prime numbers}
Lorem ipsum
\section{Dolor sit amet}
Consectetur adipiscing elit.

\begin{exercise}[Euclid]
Prove that for every prime $p$, there is a prime $p^\prime > p$. In particular, the list of primes, $2, 3, 5, 7, \ldots$ , is infinite.
\end{exercise}

\end{document}
4

You can use headformat:

\documentclass{book}
\usepackage{fontspec}
\usepackage{amsmath,amsthm,amssymb,thmtools}

\newfontfamily{\miscsymbols}{Symbola}[
  UprightFont=*,
  BoldFont=*,
]

\declaretheoremstyle[
  headformat={\miscsymbols▸} \NAME\ \NUMBER\NOTE,
]{mystyle}

\declaretheorem[
  style=mystyle,
]{exercise}

\begin{document}

\chapter{Prime numbers}
Lorem ipsum
\section{Dolor sit amet}
Consectetur adipiscing elit.

\begin{exercise}[Euclid]\label{euclid}
Prove that for every prime $p$, there is a prime $p' > p$.
In particular, the list of primes, $2, 3, 5, 7, \dotsc$ is infinite.
\end{exercise}

\end{document}

I defined a special font because Latin Modern hasn't that particular glyph. Of course you can also use $\blacktriangleright$ instead of a glyph from another text font.

enter image description here

\NOTE is smart and will print nothing if the optional argument is missing in a statement.

Unrelated, but typing p' is easier than p^{\prime} and yields the same result. Use \dotsc from amsmath instead of \ldots in that context.

3
  • The dot after \NOTE is bold. Is it OK? Is it not better to put also \NOTE in bold?
    – CarLaTeX
    Nov 28 '21 at 16:19
  • @CarLaTeX That's standard amsthm
    – egreg
    Nov 28 '21 at 16:22
  • OK, if it is the standard I don't say nothing :D
    – CarLaTeX
    Nov 28 '21 at 16:28
3

This is possible directly with amsthm:

\documentclass{book}
\usepackage{amssymb}
\usepackage{amsthm}
\theoremstyle{definition}
\newtheorem{exer}{$\blacktriangleright$ Exercise}

\begin{document}

\section{A section}
Some text
\begin{exer}
 Content of exercise.
\end{exer}

\end{document}

Output of example code

1
  • Silly me. Certainly a way to do that.
    – tush
    Nov 28 '21 at 18:05

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.