# Special theorem command

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}}
\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,
notefont=\bfseries, notebraces={}{},
bodyfont=\normalfont\itshape,
name={\ignorespaces},
numbered=no,
{mystyle}
\declaretheorem[style=mystyle]{@thmattr}
\NewDocumentEnvironment{thmattr}{moO{x}oo}
{\IfNoValueTF{#2}
{\def\theorem@attr{#1}}
{\@ifundefined{c@#2}
{\newcounter{#2} \setcounter{#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:

• Has anybody seen this? – MickG Mar 28 '14 at 16:33
• Apparently trying to assign a value to \theorem@attr and then changing it before opening @thmattr results in the change being useless. It seems thmtools 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 without thmtools? And if it isn't, how do I solve this problem? – MickG Mar 29 '14 at 20:04
• P.S. Trying the same with \usepackage[amsthm]{ntheorem} gives Package 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 with thmbox it's the same as without thmtools. – MickG Mar 29 '14 at 20:33
• Problem 1 is solved by tex.stackexchange.com/questions/65951/…. That, though, generates a different problem: in the List of Theorems the names are in brackets. How do I remove those brackets? Also, the dot of problem 3 is turned into a colon. I preferred the dot, and anyway prefer nothing at all. What do I do? – MickG Mar 30 '14 at 11:41
• Problem 2 is answered in a comment at tex.stackexchange.com/questions/168434/…, with \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?". – MickG Mar 30 '14 at 14:42

Problem 1 has a solution at Theorem style with name as argument, noting that one should use [headpunct=] to remove the dot/colon/whatever after the theorem name.
Problem 2 has an answer in the \str_if_eq:nnTF in a comment at Problem with abbreviation of \multirow and \multicolumn (LaTeX).
The only trouble is, besides a way to choose which theorems to show and to ignore in the \listoftheorems, which can easily be solved by duplicating the command with another name, or in fact adding another argument to decide which type of mystyle theorem to use, the \listoftheorems shows brackets around the names of the theorems, and of course has the counters in the middle of the name. I wonder if it is possible to remove the brackets (major problem) and to define a different label for the list in this mess (minor problem). In fact, the "minor problem" has an easy solution: just use [{name=[<list name>]<page name>}] (opportunely implemented in the complex thmattr environment), though thinking on it I might not want that.