2

I'm writing a package. Here is a part of it which should be enough for people to try reproducing my problem:

%[…]
\ProvidesPackage{mworks}
%[…]
\RequirePackage{amsmath,amssymb,amsfonts,nicefrac}
\RequirePackage{multirow}
\RequirePackage{xparse}
\RequirePackage{thmtools,mathtools}
%[…]
\newif\ifmworks@thm\mworks@thmfalse
\DeclareOption{thm}{\mworks@thmtrue}
%[…]
\ProcessOptions\relax
%[…]
%Option "thm"
\ifmworks@thm
\newcommand{\setlistwidth}[1][4em]{\renewcommand\thmt@listnumwidth{#1}}
\newcommand{\thlist}{\listoftheorems}
\newcommand{\deflist}{\renewcommand\listtheoremname{Definizioni, Teoremi, Proposizioni, ecc.}
\listoftheorems[ignoreall,show={defi,teor,oss,propo,coro,fatto,lemma,pt,riass,es}]
\renewcommand\listtheoremname{Esercizi assegnati a lezione}
\listoftheorems[ignoreall,show={ese}]}
\newcommand{\changename}{\renewcommand\listtheoremname}
\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}
\ExplSyntaxOn
\NewDocumentEnvironment{xtheor}{moO{x}ooo}
{\renewcommand{\thmtformatoptarg}[1]{ #1}\IfNoValueTF{#2}
      {\def\theorem@attr{#1}}
      {\@ifundefined{c@#2}
            {\newcounter{#2} \setcounter{#2}{1}}
            {\addtocounter{#2}{+1}}
      \def\counters{
      \str_if_eq:nnTF{#3}{c}
      {
            \arabic{chapter}.\arabic{#2}
      }
      {
                  \str_if_eq:nnTF{#3}{s}
                  {
                        \arabic{chapter}.\arabic{section}.\arabic{#2}
                  }
                  {
                        \str_if_eq:nnTF{#3}{x}
                        {
                              \arabic{chapter}.\arabic{section}.\arabic{subsection}.\arabic{#2}
                        }
                        {
                              \str_if_eq:nnTF{#3}{n}
                              {
                              \arabic{#2}
                              }
                              {
                              \errmessage{Illegal argument in counter definition}
                              \errhelp{The third argument must be either c, s or x, for chapter, section and subsection respectively}
                              }
                        }
                 }}}\def\theorem@attr{#1\,\,\counters\IfValueTF{#4}{\,\,}{}}}
                 \def\name@thmlist{\IfValueTF{#2}{\counters\,\,}{}#1\IfValueTF{#4}{\IfValueTF{#6}{\,\,#6}{\,\,#4}}{}}
\IfNoValueTF{#4}
      {\begin{@thmattr}[{name=[\name@thmlist]\theorem@attr}]}
      {\IfNoValueTF{#5}
            {\begin{@thmattr}[{name=[\name@thmlist]\theorem@attr (#4)}]}
            {\begin{@thmattr}[{name=[\name@thmlist]\theorem@attr (#4)},label=#5]}}}
{\end{@thmattr}}
\renewcommand\thmt@listnumwidth{-1.5em}
\ExplSyntaxOff
\newcommand{\e}[1][1]{
\qwerty=#1
\ifnum\qwerty>0
    {\loop\!\advance\qwerty by -1\ifnum\qwerty>0\repeat}
\else
    {\loop\,\advance\qwerty by 1\ifnum\qwerty<0\repeat}
\fi}
\fi
%[…]
\endinput

where the lines of %[…] are bits of package code I've believed to be useless for the purpose of this question and therefore left out. With the following code:

\documentclass[a4paper]{report}
\usepackage{amsmath,amssymb,amsfonts,mathtools,mathptmx}
\usepackage{xparse}
\usepackage[all]{mworks}

\begin{document}

\end{document}

run through XeTeX, I get:

This is XeTeX, Version 3.1415926-2.5-0.9999.3 (TeX Live 2013)
 restricted \write18 enabled.
entering extended mode
(./MworksGreek.tex
LaTeX2e <2011/06/27>
Babel <3.9f> and hyphenation patterns for 78 languages loaded.
(/usr/local/texlive/2013/texmf-dist/tex/latex/base/report.cls
Document Class: report 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2013/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2013/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2013/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2013/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2013/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/amsmath/amsopn.sty))
(/usr/local/texlive/2013/texmf-dist/tex/latex/amsfonts/amssymb.sty
(/usr/local/texlive/2013/texmf-dist/tex/latex/amsfonts/amsfonts.sty))
(/usr/local/texlive/2013/texmf-dist/tex/latex/mh/mathtools.sty
(/usr/local/texlive/2013/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/tools/calc.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/mh/mhsetup.sty))
(/usr/local/texlive/2013/texmf-dist/tex/latex/psnfss/mathptmx.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3packages/xparse/xparse.sty
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3kernel/l3names.sty
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3kernel/l3bootstrap.sty))
(/usr/local/texlive/2013/texmf-dist/tex/latex/etex-pkg/etex.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3kernel/l3basics.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3kernel/l3expan.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3kernel/l3tl.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3kernel/l3seq.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3kernel/l3int.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3kernel/l3quark.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3kernel/l3prg.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3kernel/l3clist.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3kernel/l3token.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3kernel/l3prop.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3kernel/l3msg.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3kernel/l3file.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3kernel/l3skip.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3kernel/l3keys.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3kernel/l3fp.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3kernel/l3box.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3kernel/l3coffins.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3kernel/l3color.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3kernel/l3luatex.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/l3kernel/l3candidates.sty)
(/usr/local/texlive/2013/texmf-dist/tex/generic/oberdiek/ifpdf.sty)))
(./mworks.sty
Package `Mworks' <Mon 2014-04-01 >.
(/usr/local/texlive/2013/texmf-dist/tex/latex/units/nicefrac.sty
(/usr/local/texlive/2013/texmf-dist/tex/latex/base/ifthen.sty))
(/usr/local/texlive/2013/texmf-dist/tex/latex/multirow/multirow.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/thmtools/thmtools.sty
(/usr/local/texlive/2013/texmf-dist/tex/latex/thmtools/thm-patch.sty
(/usr/local/texlive/2013/texmf-dist/tex/latex/thmtools/parseargs.sty))
(/usr/local/texlive/2013/texmf-dist/tex/latex/thmtools/thm-kv.sty
(/usr/local/texlive/2013/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
(/usr/local/texlive/2013/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(/usr/local/texlive/2013/texmf-dist/tex/generic/oberdiek/etexcmds.sty
(/usr/local/texlive/2013/texmf-dist/tex/generic/oberdiek/ifluatex.sty))))
(/usr/local/texlive/2013/texmf-dist/tex/latex/thmtools/thm-autoref.sty
(/usr/local/texlive/2013/texmf-dist/tex/latex/thmtools/aliasctr.sty
(/usr/local/texlive/2013/texmf-dist/tex/latex/carlisle/remreset.sty)))
(/usr/local/texlive/2013/texmf-dist/tex/latex/thmtools/thm-listof.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/thmtools/thm-restate.sty))
(/usr/local/texlive/2013/texmf-dist/tex/generic/mathdots/mathdots.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/tools/multicol.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/fontspec/fontspec.sty
(/usr/local/texlive/2013/texmf-dist/tex/latex/fontspec/fontspec-patches.sty
(/usr/local/texlive/2013/texmf-dist/tex/latex/base/fixltx2e.sty)
*************************************************
* LaTeX warning: "xparse/redefine-command"
* 
* Redefining document command \oldstylenums with arg. spec. 'm' on line 128.
*************************************************
) (/usr/local/texlive/2013/texmf-dist/tex/latex/fontspec/fontspec-xetex.sty
(/usr/local/texlive/2013/texmf-dist/tex/latex/base/fontenc.sty
(/usr/local/texlive/2013/texmf-dist/tex/latex/euenc/eu1enc.def)
(/usr/local/texlive/2013/texmf-dist/tex/latex/euenc/eu1lmr.fd))
(/usr/local/texlive/2013/texmf-dist/tex/xelatex/xunicode/xunicode.sty
(/usr/local/texlive/2013/texmf-dist/tex/latex/tipa/t3enc.def
(/usr/local/texlive/2013/texmf-dist/tex/latex/euenc/eu1lmss.fd))
(/usr/local/texlive/2013/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/local/texlive/2013/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/local/texlive/2013/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/latexconfig/graphics.cfg)
(/usr/local/texlive/2013/texmf-dist/tex/xelatex/xetex-def/xetex.def))))
(/usr/local/texlive/2013/texmf-dist/tex/latex/fontspec/fontspec.cfg)))
(/usr/local/texlive/2013/texmf-dist/tex/latex/xltxtra/xltxtra.sty
(/usr/local/texlive/2013/texmf-dist/tex/generic/ifxetex/ifxetex.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/realscripts/realscripts.sty
*************************************************
* LaTeX warning: "xparse/redefine-command"
* 
* Redefining document command \textsubscript with arg. spec. 's' on line 25.
*************************************************
*************************************************
* LaTeX warning: "xparse/redefine-command"
* 
* Redefining document command \textsuperscript with arg. spec. 's' on line 28.
*************************************************
) (/usr/local/texlive/2013/texmf-dist/tex/latex/metalogo/metalogo.sty))
(/usr/local/texlive/2013/texmf-dist/tex/latex/graphics/color.sty
(/usr/local/texlive/2013/texmf-dist/tex/latex/latexconfig/color.cfg))
(/usr/local/texlive/2013/texmf-dist/tex/latex/base/textcomp.sty
(/usr/local/texlive/2013/texmf-dist/tex/latex/base/ts1enc.def))
(/usr/local/texlive/2013/texmf-dist/tex/latex/hyperref/hyperref.sty
(/usr/local/texlive/2013/texmf-dist/tex/generic/oberdiek/hobsub-hyperref.sty
(/usr/local/texlive/2013/texmf-dist/tex/generic/oberdiek/hobsub-generic.sty))
(/usr/local/texlive/2013/texmf-dist/tex/latex/oberdiek/auxhook.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/oberdiek/kvoptions.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/hyperref/pd1enc.def)
(/usr/local/texlive/2013/texmf-dist/tex/latex/latexconfig/hyperref.cfg)
(/usr/local/texlive/2013/texmf-dist/tex/latex/url/url.sty))

Package hyperref Message: Driver (autodetected): hxetex.

(/usr/local/texlive/2013/texmf-dist/tex/latex/hyperref/hxetex.def
(/usr/local/texlive/2013/texmf-dist/tex/latex/hyperref/puenc.def)
(/usr/local/texlive/2013/texmf-dist/tex/generic/oberdiek/stringenc.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/oberdiek/rerunfilecheck.sty))
(/usr/local/texlive/2013/texmf-dist/tex/latex/enumitem/enumitem.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/marginnote/marginnote.sty)

Package thmtools Warning: Your backend doesn't allow styling theorems on input 
line 1142.


./mworks.sty:1143: Package thmtools Error: \declaretheorem key `spaceabove' not
 known.

See the thmtools package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.1143 \declaretheorem[style=mystyle]{@thmattr}

What does that mean and how can I fix it?

5
  • 1
    Please make your code into a document that people can run to reproduce the error. Apr 5, 2014 at 13:49
  • @David Carlisle question updated.
    – MickG
    Apr 5, 2014 at 15:42
  • This is “I have written some complicated and completely uncommented code, please tell me what it does”: sorry, but this won't work. Two things I can clearly see: redefining locally \counters will not do what you think, because it will change meaning at each call of xtheor; second: where is thmtools loaded in the code you show?
    – egreg
    Apr 5, 2014 at 15:50
  • @egreg xtheor WORKS when OUTSIDE that package, that is when in the preamble of a document, as does mystyle. The strange thing I'm inquiring about is why transferring it to a package causes this strange error. As for thmtools, sorry, I forgot about it. See the updated question. And I know what it does, except in the package it does something more. The aim of \counters is to change the counter set at every call of xtheor, defining it depending on the arguments, and is that not what it does?
    – MickG
    Apr 5, 2014 at 15:56
  • 1
    You should also load amsthm or ntheorem for spaceabove to be valid.
    – egreg
    Apr 5, 2014 at 16:03

1 Answer 1

6

Your example is far from minimal. If I remove all the code unrelated to the error I get

\documentclass{report}
\usepackage{thmtools}

\declaretheoremstyle[
spaceabove=\topsep
]{mystyle}
\declaretheorem[style=mystyle]{@thmattr}
\begin{document}

\end{document}

which produces the error shown.

 ! Package thmtools Error: \declaretheorem key `spaceabove' not known.

Commenting out the spaceabove line makes the error go away. Or as noted by egreg you can add

\usepackage{amsthm}

before loading thmtools so the key is defined.

2
  • But loading amsthm before thmtools (as recommended by the package) solves the issue.
    – egreg
    Apr 5, 2014 at 17:24
  • @egreg sure. Either not using the key or causing it to be defined fix the problem but either way the problem is unrelated to any of the code in the question apart from the line that used the undefined key. Apr 5, 2014 at 17:26

You must log in to answer this question.

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