My aim in the last few questions was to define a very flexible command allowing the definition of theorems of various kinds. The reason for that was to have a single command basically for all kinds of theorems, both already used and never used before, to avoid both to have to define many kinds of theorems including some which I would use once in my life and never again, and to have to put the name of a special theorem in brackets as [name=foo]
, which yields (foo). Another useful thing about this command the way I've defined it is that it allows flexibility in the counter display, allowing theorems of the same "kind" (i.e. Theorems, Definitions, etc.) to be numbered sometimes as [section]
, sometimes as [subsection]
, sometimes as [chapter]
, depending on the subdivision of the theorem's location, thus avoiding zeroes in [subsection]
where there is no subsection division, and to have to define it as [section]
when sometimes I'd like it defined as [subsection]
because there IS such a subdivision. For the moment the command is as in the minimal code below:
\documentclass[a4paper]{report}
\usepackage{amsmath,amssymb,amsfonts,xparse,amsthm,mathptmx}
\makeatletter
\newtheorem*{@thmattr}{\theorem@attr}
\NewDocumentEnvironment{thmattr}{moO{x}oo}
{\IfNoValueTF{#2}
{\def\theorem@attr{#1}}
{\@ifundefined{c@#2}
{\newcounter{#2} \setcounter{#2}{1}}
{\addtocounter{#2}{+1}}
\def\counters{\if #3c
\arabic{chapter}.\arabic{#2}
\else{
\if #3s
\arabic{chapter}.\arabic{section}.\arabic{#2}
\else{
\if#3x
\arabic{chapter}.\arabic{section}.\arabic{subsection}.\arabic{#2}
\else
\errmessage{Illegal argument in counter definition}
\errhelp{The third argument must be either c, s or x, for chapter, section and subsection respectively}
\fi}
\fi}
\fi}\def\theorem@attr{#1\ \counters}}
\IfNoValueTF{#4}
{\begin{@thmattr}}
{\IfNoValueTF{#5}
{\begin{@thmattr}[\textbf{#4}]}
{\begin{@thmattr}[\textbf{#4}\label{#5}]}}}
{\end{@thmattr}}
\makeatother
\begin{document}
\begin{thmattr}{Teorema della Palla Pelosa}
\end{thmattr}
\begin{thmattr}{Teorema}[teor][x]
\end{thmattr}
\begin{thmattr}{Esercizio Imperiano}[eseese][c]
\end{thmattr}
\begin{thmattr}{Definizione}[defi][s][Estensione algebrica][thm:defi:EstAlg]
\end{thmattr}
\begin{thmattr}{Sorrata}[mu][c][Estensione algebrica]
\end{thmattr}
\end{document}
which typesets to:
My problems are:
1) If I use thmtools
, I get an error undefined control sequence: \thmt@thmname->\theorem@attr
(or the likes), but without it, as in the code above, the brackets around the name are not bold, and the name is forced to be bold, whereas with thmtools
I'd get both automatically bold; is there a way to get the bold without thmtools
or to solve the error thmtools
gives? And if the error of thmtools
can't be solved, is there a way to make a \listoftheorems
without that package?
2) Using \if
to compare the arguments causes trouble when the argument is a string; I'd like to send an error message if the argument is a string rather than a single character, so that if my hand slips on the keyboard and instead of c I type e.g. cv, I get an error and correct that; how do I do that? NB that was half of the question at https://tex.stackexchange.com/questions/167513/special-conditionals-tex.
3) A theorem with counter but without label (Esercizio Imperiano in the typesetted code) has a rather ugly space between the counter and the dot; how do I remove that? Alternately, how do I remove the dot, if possible? And why does the space between theorem name and counters, as well as that between counters and dot, seem to vary in length depending on the number of counters?
Update: As mentioned in a comment, problem one is solved. The solution, however, turns the dot into an even worse-looking colon, and creates the problem of brackets around the names in the List of Theorems. How do I solve those? The same set of theorems, plus something typed in the first one, with the following code:
\makeatletter
\declaretheoremstyle[
spaceabove=\topsep, spacebelow=\topsep,
headfont=\normalfont\bfseries,
notefont=\bfseries, notebraces={}{},
bodyfont=\normalfont\itshape,
postheadspace=0.5em,
name={\ignorespaces},
numbered=no,
headpunct=:]
{mystyle}
\declaretheorem[style=mystyle]{@thmattr}
\NewDocumentEnvironment{thmattr}{moO{x}oo}
{\IfNoValueTF{#2}
{\def\theorem@attr{#1}}
{\@ifundefined{c@#2}
{\newcounter{#2} \setcounter{#2}{1}}
{\addtocounter{#2}{+1}}
\def\counters{\if #3c
\arabic{chapter}.\arabic{#2}
\else{
\if #3s
\arabic{chapter}.\arabic{section}.\arabic{#2}
\else{
\if#3x
\arabic{chapter}.\arabic{section}.\arabic{subsection}.\arabic{#2}
\else
\errmessage{Illegal argument in counter definition}
\errhelp{The third argument must be either c, s or x, for chapter, section and subsection respectively}
\fi}
\fi}
\fi}\def\theorem@attr{#1\counters}}
\IfNoValueTF{#4}
{\begin{@thmattr}[\theorem@attr]}
{\IfNoValueTF{#5}
{\begin{@thmattr}[\theorem@attr (#4)]}
{\begin{@thmattr}[\theorem@attr (#4)\label{#5}]}}}
{\end{@thmattr}}
\renewcommand\thmt@listnumwidth{-1.5em}
\makeatother
produces:
\theorem@attr
and then changing it before opening@thmattr
results in the change being useless. It seemsthmtools
assigns a name to each defined theorem once and for all, leaving no space for subsequent changes. Is that right? If it is, is there another way to get the bold brackets and\listoftheorems
withoutthmtools
? And if it isn't, how do I solve this problem?\usepackage[amsthm]{ntheorem}
givesPackage ntheorem Error: Theorem style plain already defined. See the ntheorem package documentation for explanation. Type H <return> for immediate help. ... l.524 ...rfont ##1\ ##2\ (##3)\theorem@separator]}
, and withthmbox
it's the same as withoutthmtools
.\str_if_eq:nnTF{<string 1>}{<string 2>}
, requiring\ExplSyntaxOn
and\ExplSyntaxOff
around it, for which see tex.stackexchange.com/questions/108696/…. So I think I'm left only with "How do I remove the dot/colon after the theorem's name?" and "How do I remove the brackets around the theorem name in the List of Theorems?".