2

Is it possible to make square brackets in the body of a theorem appear upright — when using the declaration bodyfont=\mdseries\itshape in the definition of a theoremstyle with thmtools?

The method of using the package embrac(Copy theoremfont option from newtxtext) does not work, because as the embrac documentation says, it affects only \emph, \textit, and textsl but not \itshape or \slshape.

In particular: is there a way to avoid using \itshape (or \slshape) yet still obtain italic (or slant, respectively) in the body of a theorem when the theoremstyle is defined using thmtools? (except for the desired upright brackets, of course).

Example:

\documentclass{article}

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

\makeatletter
\declaretheoremstyle[
  headfont= \sffamily\bfseries,
  headpunct={\sffamily\bfseries.},
  postheadspace=0.5em,
  notefont=\sffamily\bfseries,
  headformat=\NAME\NUMBER\let\thmt@space\@empty\NOTE,
  bodyfont=\mdseries\itshape,
  spaceabove=12pt,spacebelow=12pt,
]{thmstyle}
\makeatother

\theoremstyle{thmstyle}% default
\declaretheorem[name=Theorem,numberwithin=section]{theorem}

\begin{document}
\section{A section}

\begin{theorem}

Let $A$ and $B$ be subsets [see section 2] of a set $X$.Then
\[
X \setminus (A \cup B) = (X \setminus A) \cap (X \setminus B).
\]
\end{theorem}

\end{document}

Want upright brackets in theorem body text

I am aware of the answer to How to get upright parentheses in the whole document?, which, as it says, will break things.

6
  • It's probably necessary to attack them one by one. You can do this as \textup[ or \textup]. Braces around the square brackets aren't necessary, since \textup operates on only the next token, and a single character here is the token. (A long time ago, there was a discussion about creating a "theorem font", italic with upright punctuation. But it never happened, as the complications weren't easy to work around.) Dec 3, 2019 at 4:44
  • @barbarabeeton: I'm already aware of just using \textup, but I was hoping for something more high-level -- a way to do what the theoremfont option of newtxtext does automatically.
    – murray
    Dec 3, 2019 at 15:31
  • The crux of my question is the bolded sentence: is there a way to avoid using \itshape or slshape as value for option bodyfont in \declaretheoremstyle from thmtools (i.e., somehow use \textit or \textsl there), so that embrac would work.
    – murray
    Dec 3, 2019 at 18:16
  • The scholax package includes a style option theoremfont that does make text parentheses, brackets, and braces upright. The method seems to be simply: \DeclareRobustCommand\thfamily {\not@math@alphabet\thfamily\relax \fontfamily\thdefault\selectfont} \AtEndPreamble{\patchcmd{\th@plain}{\itshape}{\thfamily}{}{}} % \newcommand*{\thdefault}{\rmdefault}
    – murray
    Feb 6, 2020 at 18:19
  • However, the method quoted from scholax does not seem to work if I use thmtools and declare the theorem style body font to be \slshape.
    – murray
    Feb 9, 2020 at 17:43

2 Answers 2

2

Since version 0.8 (2019/10/01) embrac provides \embparen and \embbracket for cases like this:

\documentclass{article}

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

\makeatletter
\declaretheoremstyle[
  headfont= \sffamily\bfseries,
  headpunct={\sffamily\bfseries.},
  postheadspace=0.5em,
  notefont=\sffamily\bfseries,
  headformat=\NAME\NUMBER\let\thmt@space\@empty\NOTE,
  bodyfont=\mdseries\itshape,
  spaceabove=12pt,spacebelow=12pt,
]{thmstyle}
\makeatother

\theoremstyle{thmstyle}% default
\declaretheorem[name=Theorem,numberwithin=section]{theorem}

\begin{document}
\section{A section}

\begin{theorem}
  Let $A$ and $B$ be subsets \embbracket{see section 2} of a set $X$.Then
  \[ X \setminus (A \cup B) = (X \setminus A) \cap (X \setminus B). \]
\end{theorem}

\end{document}

enter image description here

5
  • According to the documentation, it should not be necessary to use \embracket explicilty: from its page 2, "embrac tries to redefine \emph, \textit and \textsl in a way that neither parentheses nor square brackets are sloped.". Moreover, having to type \embbracket{see section 2} defeats the purpose of embrac, namely, to avoid having to manually indicate that such brackets in emphasized, italicized, or slanted text are to be typeset upright.
    – murray
    Feb 21, 2021 at 18:24
  • @murray The theorem uses neither of \emph, \textit or \textsl. It uses \itshape. Please read the section in the embrac manual called “Watch out!“ again.
    – cgnieder
    Feb 21, 2021 at 18:31
  • \embbracket inserts the correct kerns so it is an compromise between having an automated solution and having to use \textup{[}.
    – cgnieder
    Feb 21, 2021 at 18:38
  • Related discussion tex.stackexchange.com/a/461592
    – cgnieder
    Feb 21, 2021 at 19:02
  • The compromise noted! Of course part of the difficulty is that thmtools demands use of the argument-free \itshape, \slshape, etc. commands instead of somehow employing the argument-using textit and \textsl.
    – murray
    Feb 21, 2021 at 21:23
1

If you're willing to forgo verbatim material in your theorems, you can process the body of the theorem with embrac's \embrac_replace_brackets:N command.

\documentclass{article}

\usepackage{embrac}
\usepackage{amsthm,thmtools}

\ExplSyntaxOn
\cs_new_protected:Npn \murray_embrac_text:n #1
  {
    \tl_set:Nn \l__embrac_tmpa_tl {#1}
    \embrac_replace_brackets:N \l__embrac_tmpa_tl
    \l__embrac_tmpa_tl
  }

\NewDocumentCommand { \embracifytheorem } { m }
  {
    \NewEnvironmentCopy { origenv_#1 } { #1 }
    \RenewDocumentEnvironment { #1 } { o +b }
      {
        \IfNoValueTF{##1}
          {\begin{origenv_#1}}
          {\begin{origenv_#1}[##1]}
        \murray_embrac_text:n { ##2 }
        \end{origenv_#1}
      }
      {}
  }
\ExplSyntaxOff

% you can adjust or remove these to your liking
\AddOpEmph{?}[0pt,1pt]
\AddOpEmph{!}[0pt,1pt]
\AddOpEmph{:}[0pt,1pt]

\makeatletter
\declaretheoremstyle[
  headfont= \sffamily\bfseries,
  headpunct={\sffamily\bfseries.},
  postheadspace=0.5em,
  notefont=\sffamily\bfseries,
  headformat=\NAME\NUMBER\let\thmt@space\@empty\NOTE,
  bodyfont=\mdseries\itshape,
  spaceabove=12pt,spacebelow=12pt,
]{thmstyle}
\makeatother

\theoremstyle{thmstyle}% default
\declaretheorem[name=Theorem,numberwithin=section]{theorem}
\embracifytheorem{theorem}

\begin{document}

\section{A section}

\begin{theorem}

Let $A$ and $B$ be subsets [see section 2] of a set $X$.Then
\[
X \setminus (A \cup B) = (X \setminus A) \cap (X \setminus B).
\]
\end{theorem}

\end{document}

thm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .