Skip to content

Instantly share code, notes, and snippets.

Created January 3, 2015 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6ff1be172846725c516f to your computer and use it in GitHub Desktop.
Save anonymous/6ff1be172846725c516f to your computer and use it in GitHub Desktop.
part of mworkxb connected with langs and thms
\NeedsTeXFormat{LaTeX2e}[1996/06/01]
\typeout{Package 'mworkxb' (version \fileversion, saved on \filedate).}
\ProvidesPackage{mworkxb}
%Require kvoptions for key-value options.
\RequirePackage{kvoptions}
\DeclareBoolOption[true]{thm}
\DeclareStringOption[]{babel}
\DeclareStringOption[]{poly}
\DeclareStringOption[italian]{lang}
\DeclareBoolOption[false]{polyuse}
\ProcessKeyvalOptions*\relax
\RequirePackage{xparse}
\ExplSyntaxOn
\ifmw@polyuse
\RequirePackage{polyglossia}
\edef\mw@langselect{\noexpand\setmainlanguage[\mw@poly]{\mw@lang}}
\else
\edef\mw@langselect{\noexpand\RequirePackage[\mw@lang\str_if_eq:nnTF{\mw@babel}{}{}{,\mw@babel}]{babel}}
\fi
\mw@langselect
\ExplSyntaxOff
\newif\if@labeling\@labelingfalse
\ExplSyntaxOn
\msg_new:nnnn{mworkx}{too-few-args}{Too ~ few ~ arguments.}{The ~ macro ~ \string#1 ~ requires ~ at ~ least ~ one ~ of ~ its ~ arguments ~ to ~ have ~ a ~ value. ~ Please ~ supply ~ it.}
\msg_new:nnn{mworkx}{save-no-inpenc}{You\ are\ using\ inputenc\ with\ the\ save\ option\ from\ this\ package.\ Be\ careful\ with\ characters\ with\ tilde\ or\ double\ acute\ accent\ above,\ as\ this\ package\ may\ render\ them\ impossible\ to\ typeset,\ or\ else\ fix\ the\ issue\ by\ the\ inpenc\ option\ of\ this\ package.\ Note\ also\ that\ the\ command\ \string\ss\ is\ redefined\ to\ be\ the\ spadesuit\ but\ to\ switch\ back\ to\ the\ German\ Scharfeses\ (ß)\ if\ starred.\ If\ there\ is\ any\ other\ trouble,\ which\ vanishes\ if\ you\ remove\ the\ loading\ of\ mworkx,\ contact\ me\ at\ michelegor@hotmail.com.\ Also,\ the\ utf8x\ option\ doesn't\ interact\ well\ with\ mworkx,\ so\ I\ suggest\ you\ do\ NOT\ use\ it\ with\ this\ package.\ Thanks\ for\ your\ attention\ and\ I\ hope\ this\ package\ serves\ you\ well\ :).}
\msg_new:nnnn{mworkx}{invalid}{What~exactly~did~you~mean?}{
I~don't~get~what~delimiter~size~you~mean~with~this.~Please~review~your~#1~specifications.}
\msg_new:nnnn{mworkx}{not-read}{You\ haven't\ read\ the\ documentation\ yet!}{This\ used\ to\ be\ an\ error.\ With\ the\ new\ version\ of\ the\ package,\ new\ warnings\ make\ it,\ in\ my\ opinion,\ not\ strictly\ necessary\ to\ read\ it.\ However,\ I\ strongly\ recommend\ that\ you\ read\ it,\ both\ to\ familiarize\ with\ the\ commands\ and\ to\ know\ the\ reason\ for\ this\ warning.\ Thanks\ for\ using\ mworkx.}
\msg_new:nnnn{mworkx}{unknown-lang}{Unknown~language~option~for~something~in~this~package.}{Couldn't~interpret~given~language~options.~#1~left~empty.}
\msg_new:nnnn{mworkx}{invalid-ctr}{Illegal\ argument\ in\ counter\ definition.}{The\ third\ argument\ must\ be\ either\ c,\ s\ or\ x,\ for\ chapter,\ section\ and\ subsection\ respectively,\ or\ n\ for\ none\ of\ those\ which\ means\ just\ the\ counter\ in\ parameter\ 2,\ or\ a\ to\ let\ me\ choose\ the\ counters\ automatically,\ or\ @@\ for\ no\ counters\ at\ all.}
\msg_new:nnn{mworkx}{warn-strange-error}{If ~ you ~ get ~ the ~ mysterious ~ error ~ `Argument ~ of ~ \string\@fourthofseven ~ has ~ an ~ extra ~ \}' ~ or ~ similar, ~ don't ~ worry: ~ just ~ search ~ your ~ files ~ for ~ any ~ instance ~ of ~ \string\getmwref, ~\string\getmwrefb, ~ \string\getmwrefc\ ~ or ~ their ~ \string\lc- ~ counterparts, ~ temporarily ~ remove ~ them ~ and ~ compile, ~ so ~ the ~ .aux ~ file ~ gets ~ properly ~ written, ~ then ~ put ~ them ~ back ~ in ~ and, ~ provided ~ you ~ have ~ no ~ errors ~ in ~ your ~ code, ~ everything ~ should ~ be ~ fine. ~ If ~ it ~ isn't, ~ contact ~ the ~ author ~ of ~ this ~ package ~:).\ A\ quicker\ way\ to\ switch\ those\ commands\ off\ is\ \string\stoprefs,\ which\ turns\ them\ to\ \string\relax.\ To\ turn\ them\ on,\ remove\ that\ command.}
\msg_new:nnn{mworkx}{label-undefined}{The ~ label ~ #2 ~ is ~ not ~ defined ~ or ~ cannot ~ be ~ found.}
\ExplSyntaxOff
%Option "thm"
\ifmw@thm
\ExplSyntaxOn
\msg_warning:nn{mworkx}{warn-strange-error}
\ExplSyntaxOff
%For changing the listnumwidth, i.e. the space left for the numbers of theorems in \listoftheorems. Default: 4em.
\newcommand{\setlistwidth}[1][4em]{\renewcommand\thmt@listnumwidth{#1}}
%Gives \listoftheorem an abbreviation.
\newcommand{\thlist}{\listoftheorems}
%Default list of various kinds of theorems.
\newcommand{\deflist}{\renewcommand\listtheoremname{Definizioni,~Teoremi,~Proposizioni,~ecc.}
\@ifstar{\listoftheorems[ignoreall,show={defi,teor,oss,propo,coro,fatto,lemma,pt,riass,es}]}{\listoftheorems[ignoreall,show=@thmattr]}}
%List of exercises.
\newcommand{\eselist}{\renewcommand\listtheoremname{Esercizi~assegnati~a~lezione}
\@ifstar{\listoftheorems[ignoreall,show={ese}]}{\listoftheorems[ignoreall,show=@thmattr2]}}
%List of what's left
\newcommand{\gunglist}{\renewcommand\listtheoremname{Punti,~Riassunti,~Esercizi~da~esercitazione,~Esercizi~svolti~da~me}
\listoftheorems[ignoreall,show=@thmattr3]}
%Changes title of \listoftheorems. Takes a pseudo-argument which is actually the redefinition of \listtheoremname.
\newcommand{\changename}{\renewcommand\listtheoremname}
%Redefines \thmtformatoptarg.
\newcommand{\listformat}[1]{\renewcommand\thmtformatoptarg[1]{#1}}
%A length for theorem style mystyle.
\newlength\mw@mystyleposthead
%Initialize to 0.5em
\mw@mystyleposthead=0.5em
%Commands to set it from document.
\newcommand{\growposthead}[1]{\advance\mw@mystyleposthead by #1}
\newcommand{\saveposthead}{\setlength{\mw@saveph}{\mw@mystyleposthead}}
\newcommand{\resetposthead}{\setlength{\mw@mystyleposthead}{\mw@saveph}}
\newcommand{\setposthead}[1]{\setlength{\mw@mystyleposthead}{#1}}
%Length for saving.
\newlength\mw@saveph
%Declares theorem style mystyle. Requires amsthm.
\declaretheoremstyle[
spaceabove=\topsep, spacebelow=\topsep,
headfont=\normalfont\bfseries,
notefont=\bfseries, notebraces={}{},
bodyfont=\normalfont\itshape,
postheadspace=\mw@mystyleposthead,
name={\ignorespaces},
numbered=no,
headpunct=.]
{mystyle}
%Declares theorem @thmattr with style mystyle. Now this is a class of theorems which is instanced by the xtheor environment, which is a big mess of coding and which I will comment inside the code, also to make it more readable to myself.
\declaretheorem[style=mystyle]{@thmattr}
%Some helper macros clarified in xtheor. One macro's default depends on TikZ, so I check it is loaded.
\def\@firstofseven#1#2#3#4#5#6#7{#1}
\def\@secondofseven#1#2#3#4#5#6#7{#2}
\def\@thirdofseven#1#2#3#4#5#6#7{#3}
\def\@fourthofseven#1#2#3#4#5#6#7{#4}
\def\@fifthofseven#1#2#3#4#5#6#7{#5}
\def\@sixthofseven#1#2#3#4#5#6#7{#6}
\def\@seventhofseven#1#2#3#4#5#6#7{#7}
\def\@get@label@one#1{
\expandafter\ifx\csname r@#1\endcsname\relax
\msg_warning:nnn{mworkx}{label-undefined}{#1}
\else
\expandafter\expandafter\expandafter\@firstofseven\csname r@#1\endcsname
\fi
}
\def\@get@label@two#1{
\expandafter\ifx\csname r@#1\endcsname\relax
\msg_warning:nnn{mworkx}{label-undefined}{#1}
\else
\expandafter\expandafter\expandafter\@secondofseven\csname r@#1\endcsname
\fi
}
\def\@get@label@three#1{
\expandafter\ifx\csname r@#1\endcsname\relax
\msg_warning:nnn{mworkx}{label-undefined}{#1}
\else
\expandafter\expandafter\expandafter\@thirdofseven\csname r@#1\endcsname
\fi
}
\def\@get@label@four#1{
\expandafter\ifx\csname r@#1\endcsname\relax
\msg_warning:nnn{mworkx}{label-undefined}{#1}
\else
\expandafter\expandafter\expandafter\@fourthofseven\csname r@#1\endcsname
\fi
}
\def\@get@label@five#1{
\expandafter\ifx\csname r@#1\endcsname\relax
\msg_warning:nnn{mworkx}{label-undefined}{#1}
\else
\expandafter\expandafter\expandafter\@fifthofseven\csname r@#1\endcsname
\fi
}
\def\@get@label@six#1{
\expandafter\ifx\csname r@#1\endcsname\relax
\msg_warning:nnn{mworkx}{label-undefined}{#1}
\else
\expandafter\expandafter\expandafter\@sixthofseven\csname r@#1\endcsname
\fi
}
\def\@get@label@seven#1{
\expandafter\ifx\csname r@#1\endcsname\relax
\msg_warning:nnn{mworkx}{label-undefined}{#1}
\else
\expandafter\expandafter\expandafter\@seventhofseven\csname r@#1\endcsname
\fi
}
\@ifpackageloaded{tikz}
{\newcommand{\refstyle}[1]{{\bfseries\color{purple!60!black}#1}}}
{\newcommand{\refstyle}[1]{{\bfseries\color{blue}#1}}}
\newcommand{\setrefstyle}{\renewcommand\refstyle[1]}
\newcommand{\resetrefstyle}{\renewcommand{\refstyle}[1]{{\bfseries\color{purple!60!black}##1}}}
\newcommand{\stoprefs}{
\let\getmwref\relax
\let\getmwrefb\relax
\let\getmwrefc\relax
\let\lcgetmwref\relax
\let\lcgetmwrefb\relax
\let\lcgetmwrefc\relax
}
\newlength{\mw@sp}
\settowidth{\mw@sp}{\hbox{\ }}
\newcommand{\no}[1][1]{\hspace{-#1\mw@sp}}
\ExplSyntaxOn
\newcommand{\getmwref}[1]{
\edef\thkind@label{\@get@label@seven{#1}}
\edef\ctr@label{\@get@label@one{#1}}
\edef\thk@label{\@get@label@six{#1}}
\hyperlink{#1}{\refstyle{\thk@label\ \ctr@label}}
}
\newcommand{\getmwrefb}[1]{
\edef\thname@label{\@get@label@three{#1}}
\edef\thk@label{\@get@label@six{#1}}
\hyperlink
{#1}
{\refstyle{
\thk@label\ \refprep\ \thname@label{#1}
}
}
}
\newcommand{\getmwrefc}[1]{
\edef\thname@label{\@get@label@three{#1}}
\edef\thk@label{\@get@label@six{#1}}
\hyperlink
{#1}
{\refstyle{
\thk@label:\ \thname@label
}
}
}
\newcommand{\lcgetmwref}[1]{
\edef\thkind@label{\@get@label@seven{#1}}
\edef\ctr@label{\@get@label@one{#1}}
\edef\thk@label{\@get@label@six{#1}}
\edef\full@reftext{\thk@label\ \ctr@label}
\hyperlink
{#1}
{\refstyle{
\lowercase\expandafter{
\full@reftext
}
}
}
}
\newcommand{\lcgetmwrefb}[1]{
\edef\thname@label{\@get@label@three{#1}}
\edef\thk@label{\@get@label@six{#1}}
\edef\full@reftext{\thk@label\ \refprep\ \thname@label}
\hyperlink
{#1}
{\refstyle{
\lowercase\expandafter{
\full@reftext
}
}
}
}
\newcommand{\lcgetmwrefc}[1]{
\edef\thname@label{\@get@label@three{#1}}
\edef\thk@label{\@get@label@six{#1}}
\edef\full@reftext{\thk@label:\ \thname@label}
\hyperlink
{#1}
{\refstyle{
\lowercase\expandafter{
\full@reftext
}
}
}
}
\newcommand{\refprep}{di}
\newcommand{\setprep}{\renewcommand\refprep}
\newcommand{\@rel}[1]{\ (#1)}
\newcommand{\setrel}{\renewcommand\@rel[1]}
\newcommand{\resetrel}{\renewcommand{\@rel}[1]{\ (##1)}}
\newcommand{\@lrel}[1]{:\ #1}
\newcommand{\setlrel}{\renewcommand\@lrel[1]}
\newcommand{\resetlrel}{\renewcommand{\@lrel}[1]{:\ ##1}}
\newcommand{\contrel}[2]{\ (#1\ --\ \mw@contname\ #2)}
\newcommand{\setcontrel}{\renewcommand\contrel[1]}
\newcommand{\resetcontrel}{\renewcommand{\contrel}[2]{\ (##1\ --\ \mw@contname\ ##2)}}
\newcommand{\thm}[1]{\if@labeling\else\protect\hyperlink{thm:#1}\fi}
\newcommand{\savectr}[2]{\expandafter\def\csname mw@#1ctrseq\endcsname{#2}}
\ExplSyntaxOn
\@ifpackageloaded{chngcntr}{}{\RequirePackage{chngcntr}}
\@ifpackageloaded{hyperref}{}{\RequirePackage{hyperref}}
\NewDocumentCommand{\cntset}{ooo}
{\IfNoValueTF{#1}
{\PackageWarning{mworkx}{Hey\ man!\ Ya\ sure\ wanna\ set\ at\ least\ one\ counter,\ doncha?\ :)}}
{\c@chapter=#1
\IfNoValueTF{#2}
{}
{\c@section=#2
\IfNoValueTF{#3}
{}
{\c@subsection=#3}
}
}
}
\newcommand{\xlabel}[8]{\@bsphack
{\@labelingtrue\Hy@pdfstringtrue
\edef\mw@reserved@a{\noexpand\protected@write\noexpand\@auxout{}
{\noexpand\string\noexpand\newlabel{#1}{{#2}{#3}{#4}{#5}{#6}{#7}{#8}}}}
\mw@reserved@a}
\@labelingfalse
\@esphack
\hypertarget{#1}
}
\newcommand{\setcnt}[2]{\expandafter\xdef\csname #1@savedcnt\endcsname{#2}}
\newcommand{\getcnt}[1]{\csname #1@savedcnt\endcsname}
%Necessary packages for xtheor below.
%Here we are: xtheor.
\NewDocumentEnvironment{xtheor}{moO{a}oood()}%Many arguments, one mandatory and 5 optional, with default only for the second optional, set to x.
{\IfValueTF{#5}{\setcnt{#5}{\@ifundefined{c@#2}{0}{\arabic{#2}}}}{}
\IfNoValueTF{#2}%Is there a 2?
{\def\theorem@attr{#1}}%No? Then \theorem@attr, which will probably become the theorem's name, is #1.
{\expandafter
\@ifundefined{c@#2}%There IS a 2? OK then it's a mess. Because it means we have a counter sequence to create. So is there a counter named like 2?
{\newcounter{#2} \setcounter{#2}{1}
\global\newcounter{mw@old#2chapter}
\global\newcounter{mw@old#2section}
\global\newcounter{mw@old#2subsection}
}%No? Make it. And set it to 1. Obvously it's the first theorem of that kind.
{\IfNoValueTF{#7}{\addtocounter{#2}{+1}}{}}%Yes? Then just increase it by +1.
\IfValueTF{#7}
{\@ifundefined{c@mw@#2cont}
{\newcounter{mw@#2cont}
\csname c@mw@#2cont\endcsname=\csname c@#2\endcsname
\csname c@#2\endcsname=\getcnt{#5}
\stepcounter{#2}}
{\csname c@mw@#2cont\endcsname=\csname c@#2\endcsname
\csname c@#2\endcsname=\getcnt{#5}
\stepcounter{#2}}
}
{}
\str_if_eq:nnTF{#3}{\csname mw@#2ctrseq\endcsname}
{}
{\savectr{#2}{#3}
\counterwithout{#2}{chapter}
\str_case:nnF{#3}
{{a}
{\ifnum\c@chapter>0
\ifnum\c@section>0
\ifnum\c@subsection>0
\counterwithin{#2}{subsection}
\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2chapter\endcsname=\c@chapter
\else
\setcounter{#2}{1}
\fi}
\@ifundefined{c@mw@old#2section}{}
{\expandafter\ifnum\csname c@mw@old#2section\endcsname=\c@section
\else
\setcounter{#2}{1}
\fi}
\@ifundefined{c@mw@old#2subsection}{}
{\expandafter\ifnum\csname c@mw@old#2subsection\endcsname=\c@subsection
\else
\setcounter{#2}{1}
\fi}
\else
\counterwithin{#2}{section}
\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2chapter\endcsname=\c@chapter
\else
\setcounter{#2}{1}
\fi}
\@ifundefined{c@mw@old#2section}{}
{\expandafter\ifnum\csname c@mw@old#2section\endcsname=\c@section
\else
\setcounter{#2}{1}
\fi}
\fi
\else
\counterwithin{#2}{chapter}
\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2chapter\endcsname=\c@chapter
\else
\setcounter{#2}{1}
\fi}
\fi
\else
{}
\fi
}
%This whole bunch of conditionals creates \acounters, the sequence for #3 = a. This is because putting them inside the definition of \counters directly for some reason didn't work. So if chapter is positive you start with chapter, then if section is positive you add section, then if subsection is positive you ad that too, and in any case \acounters ends with #2, if #7 isn't present, and with the saved counter if #7 is present. %Finally, a stands for automatic, which means if any of chapter, section or subsection is positive (i.e. not 0 and not negative), they are put in this order with separating dots, then we have, of course, #2. This is actually dealt with by the nested \ifs in the definition of \acounters, for if those \ifs were placed in here, it wouldn't work. I tried that. Trust me :).
{c}{\counterwithin{#2}{chapter}\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2chapter\endcsname=\c@chapter
\else
\setcounter{#2}{1}
\fi}
}%c stands for chapter numbering, so if #3 is c the counters are chapter, separating dot, #2, all in arabic representation.
{s}{\counterwithin{#2}{section}\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2chapter\endcsname=\c@chapter
\else
\setcounter{#2}{1}
\fi}
\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2section\endcsname=\c@section
\else
\setcounter{#2}{1}
\fi}
}%s stands for section, so if #3 is s we have chapter, dot, section, dot #2.
{x}{\counterwithin{#2}{subsection}\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2chapter\endcsname=\c@chapter
\else
\setcounter{#2}{1}
\fi}
\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2section\endcsname=\c@section
\else
\setcounter{#2}{1}
\fi}
\@ifundefined{c@mw@old#2subsection}{}
{\expandafter\ifnum\csname c@mw@old#2subsection\endcsname=\c@subsection
\else
\setcounter{#2}{1}
\fi}
}%x is subsection, so to those above we add the subsection counter.
{n}{\counterwithout{#2}{chapter}
}%n stands for none, so just #2.
%Wherever there is #2, if #7 is present we recover the saved counter.
{@@}{\expandafter\def\csname the#2\endcsname{@@}}%If it is @@, no counters at all, not even #2. That is to be able to use #5 (the label) when we have a special theorem which needs no number.
}
{\msg_fatal:nn{mworkx}{invalid-ctr}}
}%So now we have the counter sequence.
\IfValueTF{#5}{
\IfNoValueTF{#7}{
\xlabel{#5}{\str_if_eq:nnTF{#3}{@@}{}{\csname the#2\endcsname}}{\thepage}{#4}{#3}{\@ifundefined{c@#2}{1}{\arabic{#2}}}{#1}{\str_if_eq:nnTF{#3}{@@}{spec}{#2}}
\setcnt{#5}}{}
}{}%Label handling: if there is a 5 and no 7, you set a \hypertarget to here with no text and label #5, then you save the value of the page and the counter – no need to check it is there, since we are in the hypothesis #5 is present, which forces #2 to also be present. If #5 and #7 are both present, or if #7 is and #5 isn't, we have a continuing theorem, so no label handling. I forgot to say there is a check as to whether the label is already used, in which case a warning is issued from the package.
\global\csname c@mw@old#2chapter\endcsname=\csname c@chapter\endcsname
\global\csname c@mw@old#2section\endcsname=\csname c@section\endcsname
\global\csname c@mw@old#2subsection\endcsname=\csname c@subsection\endcsname
\def\theorem@attr{
#1
\str_if_eq:nnTF{#3}{@@}
{}
{\ \csname the#2\endcsname}
}}%At this point, we define \theorem@attr, which is the theorem's name, to be #1, which is the theorem kind or full theorem name when it's counterless, and #1 plus two \,s plus #4 when #3 is neither nothing nor @@. The spacing between the counters and #4 and company if present is handled by \@rel.
\def\name@thmlist{
#1\IfNoValueTF{#2}
{}
{
\str_if_eq:nnTF{#3}{@@}
{.}
{\ \csname the#2\endcsname
\IfValueTF{#4}
{\IfValueTF{#6}
{\@lrel{#6}}
{\@lrel{#4}}
}
{}
}}}%And we define \name@thmlist, which, as the name says, is the theorem's name in the \listoftheorems. This is #1, plus \ \counters, when #2 is present, plus #4 if present without #6, and plus #6 if #4 and #6 are present, in any case separated from \counters as specified by \@lrel if \counters doesn't end \name@thmlist. Requesting both presences is not restrictive, as no #4 implies no #6.
\IfValueTF{#7}{\global\csname c@#2\endcsname=\csname c@mw@#2cont\endcsname}{}
\IfNoValueTF{#7}
{\IfNoValueTF{#4}%Now we wonder: is #4 present?
{\begin{@thmattr}[{name=[\name@thmlist]\theorem@attr}]}%No? Then we finally start a @thmattr with name \theorem@attr and name in the list \name@thmlist.
{\str_if_eq:nnTF{#4}{\ }
{\begin{@thmattr}[{name=[\name@thmlist]\theorem@attr}]}
{\begin{@thmattr}[{name=[\name@thmlist]\theorem@attr\@rel{#4}}]}
}}%Since the label in #5 is dealt with before, we don't need to do anything about it now, so we only ask if #4 is \ , in which case we ignore it, otherwise we put it next to \theorem@attr as specified by \@rel.
{\begin{@thmattr}[name=\theorem@attr\IfValueTF{#7}{\protect\contrel{#4}{\protect\hyperlink{#5}{#7}}}{}]}
%Finally, if a #7 is present, a \hyperlink is produced from the label in #5, with the text in #5, as specified by \contrel. \contrel basically defines what is between \theorem@attr and #7, and what follows it. In its base form, it is \ (continua da #7), because I write in Italian. If I wrote in English, it would be \ (continues from #7), or maybe "continued". There may be, in \contrel, a style setting, if you wish, but I discourage that.
}
{\end{@thmattr}}%And in the \end part, just end the @thmattr.
%From this analysis, we see that:
%1: #1 is the theorem kind (Theorem, Remark, Proposition, Lemma, etc) or the full theorem name in case of a theorem with a special name like the Hairy Ball Theorem, which has no counter. That's why it's the only mandatory argument;
%2: #2 is the name of the counter associated with that theorem kind;
%3: #3 is a parameter to decide the counter style: c corresponding to [chapter] in plain theorem declarations (\newtheorem{foo}[chapter]), s corresponding to [section], x corresponding to [subsection], and n for a lone counter, probably for exercises;
%4: #4 is the theorem's name in the page where it is started; if #6 is given, this corresponds to foo in {name=[bar]foo}, otherwise it is the foo in name=foo;
%5: #5 is the label, so label=foo corresponds to foo in #5;
%6: #6 is the name in the \listoftheorems, thus corresponds to the bar in {name=[bar]foo}.
%7: #7, finally, delimited by (), is the text given to \contrel for the \hyperlink in the case of continued theorems. It should not include "continues from" or such, as that should be set to a default and handled precisely by \contrel.
\ExplSyntaxOff
\declaretheorem[style=mystyle]{@thmattr2}
\ExplSyntaxOn
%To keep some xtheors out of the list, a duplicated environment xtheor2 with a duplicated theorem kind @thmattr2.
\NewDocumentEnvironment{xtheor2}{moO{a}oood()}%Many arguments, one mandatory and 5 optional, with default only for the second optional, set to x.
{\IfValueTF{#5}{\setcnt{#5}{\@ifundefined{c@#2}{0}{\arabic{#2}}}}{}
\IfNoValueTF{#2}%Is there a 2?
{\def\theorem@attr{#1}}%No? Then \theorem@attr, which will probably become the theorem's name, is #1.
{\expandafter
\@ifundefined{c@#2}%There IS a 2? OK then it's a mess. Because it means we have a counter sequence to create. So is there a counter named like 2?
{\newcounter{#2} \setcounter{#2}{1}
\global\newcounter{mw@old#2chapter}
\global\newcounter{mw@old#2section}
\global\newcounter{mw@old#2subsection}
}%No? Make it. And set it to 1. Obvously it's the first theorem of that kind.
{\IfNoValueTF{#7}{\addtocounter{#2}{+1}}{}}%Yes? Then just increase it by +1.
\IfValueTF{#7}
{\@ifundefined{c@mw@#2cont}
{\newcounter{mw@#2cont}
\csname c@mw@#2cont\endcsname=\csname c@#2\endcsname
\csname c@#2\endcsname=\getcnt{#5}
\stepcounter{#2}}
{\csname c@mw@#2cont\endcsname=\csname c@#2\endcsname
\csname c@#2\endcsname=\getcnt{#5}
\stepcounter{#2}}
}
{}
\str_if_eq:nnTF{#3}{\csname mw@#2ctrseq\endcsname}
{}
{\savectr{#2}{#3}
\counterwithout{#2}{chapter}
\str_case:nnF{#3}
{{a}
{\ifnum\c@chapter>0
\ifnum\c@section>0
\ifnum\c@subsection>0
\counterwithin{#2}{subsection}
\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2chapter\endcsname=\c@chapter
\else
\setcounter{#2}{1}
\fi}
\@ifundefined{c@mw@old#2section}{}
{\expandafter\ifnum\csname c@mw@old#2section\endcsname=\c@section
\else
\setcounter{#2}{1}
\fi}
\@ifundefined{c@mw@old#2subsection}{}
{\expandafter\ifnum\csname c@mw@old#2subsection\endcsname=\c@subsection
\else
\setcounter{#2}{1}
\fi}
\else
\counterwithin{#2}{section}
\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2chapter\endcsname=\c@chapter
\else
\setcounter{#2}{1}
\fi}
\@ifundefined{c@mw@old#2section}{}
{\expandafter\ifnum\csname c@mw@old#2section\endcsname=\c@section
\else
\setcounter{#2}{1}
\fi}
\fi
\else
\counterwithin{#2}{chapter}
\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2chapter\endcsname=\c@chapter
\else
\setcounter{#2}{1}
\fi}
\fi
\else
{}
\fi
}
%This whole bunch of conditionals creates \acounters, the sequence for #3 = a. This is because putting them inside the definition of \counters directly for some reason didn't work. So if chapter is positive you start with chapter, then if section is positive you add section, then if subsection is positive you ad that too, and in any case \acounters ends with #2, if #7 isn't present, and with the saved counter if #7 is present. %Finally, a stands for automatic, which means if any of chapter, section or subsection is positive (i.e. not 0 and not negative), they are put in this order with separating dots, then we have, of course, #2. This is actually dealt with by the nested \ifs in the definition of \acounters, for if those \ifs were placed in here, it wouldn't work. I tried that. Trust me :).
{c}{\counterwithin{#2}{chapter}\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2chapter\endcsname=\c@chapter
\else
\setcounter{#2}{1}
\fi}
}%c stands for chapter numbering, so if #3 is c the counters are chapter, separating dot, #2, all in arabic representation.
{s}{\counterwithin{#2}{section}\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2chapter\endcsname=\c@chapter
\else
\setcounter{#2}{1}
\fi}
\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2section\endcsname=\c@section
\else
\setcounter{#2}{1}
\fi}
}%s stands for section, so if #3 is s we have chapter, dot, section, dot #2.
{x}{\counterwithin{#2}{subsection}\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2chapter\endcsname=\c@chapter
\else
\setcounter{#2}{1}
\fi}
\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2section\endcsname=\c@section
\else
\setcounter{#2}{1}
\fi}
\@ifundefined{c@mw@old#2subsection}{}
{\expandafter\ifnum\csname c@mw@old#2subsection\endcsname=\c@subsection
\else
\setcounter{#2}{1}
\fi}
}%x is subsection, so to those above we add the subsection counter.
{n}{\counterwithout{#2}{chapter}
}%n stands for none, so just #2.
%Wherever there is #2, if #7 is present we recover the saved counter.
{@@}{\expandafter\def\csname the#2\endcsname{@@}}%If it is @@, no counters at all, not even #2. That is to be able to use #5 (the label) when we have a special theorem which needs no number.
}
{\msg_fatal:nn{mworkx}{invalid-ctr}}
}%So now we have the counter sequence.
\IfValueTF{#5}{
\IfNoValueTF{#7}{
\xlabel{#5}{\str_if_eq:nnTF{#3}{@@}{}{\csname the#2\endcsname}}{\thepage}{#4}{#3}{\@ifundefined{c@#2}{1}{\arabic{#2}}}{#1}{\str_if_eq:nnTF{#3}{@@}{spec}{#2}}
}{}
}{}%Label handling: if there is a 5 and no 7, you set a \hypertarget to here with no text and label #5, then you save the value of the page and the counter – no need to check it is there, since we are in the hypothesis #5 is present, which forces #2 to also be present. If #5 and #7 are both present, or if #7 is and #5 isn't, we have a continuing theorem, so no label handling. I forgot to say there is a check as to whether the label is already used, in which case a warning is issued from the package.
\global\csname c@mw@old#2chapter\endcsname=\csname c@chapter\endcsname
\global\csname c@mw@old#2section\endcsname=\csname c@section\endcsname
\global\csname c@mw@old#2subsection\endcsname=\csname c@subsection\endcsname
\def\theorem@attr{
#1
\str_if_eq:nnTF{#3}{@@}
{}
{\ \csname the#2\endcsname}
}}%At this point, we define \theorem@attr, which is the theorem's name, to be #1, which is the theorem kind or full theorem name when it's counterless, and #1 plus two \,s plus #4 when #3 is neither nothing nor @@. The spacing between the counters and #4 and company if present is handled by \@rel.
\def\name@thmlist{
#1\IfNoValueTF{#2}
{}
{
\str_if_eq:nnTF{#3}{@@}
{.}
{\ \csname the#2\endcsname
\IfValueTF{#4}
{\IfValueTF{#6}
{\@lrel{#6}}
{\@lrel{#4}}
}
{}
}}}%And we define \name@thmlist, which, as the name says, is the theorem's name in the \listoftheorems. This is #1, plus \ \counters, when #2 is present, plus #4 if present without #6, and plus #6 if #4 and #6 are present, in any case separated from \counters as specified by \@lrel if \counters doesn't end \name@thmlist. Requesting both presences is not restrictive, as no #4 implies no #6.
\IfValueTF{#7}{\global\csname c@#2\endcsname=\csname c@mw@#2cont\endcsname}{}
\IfNoValueTF{#7}
{\IfNoValueTF{#4}%Now we wonder: is #4 present?
{\begin{@thmattr2}[{name=[\name@thmlist]\theorem@attr}]}%No? Then we finally start a @thmattr2 with name \theorem@attr and name in the list \name@thmlist.
{\str_if_eq:nnTF{#4}{\ }
{\begin{@thmattr2}[{name=[\name@thmlist]\theorem@attr}]}
{\begin{@thmattr2}[{name=[\name@thmlist]\theorem@attr\@rel{#4}}]}
}}%Since the label in #5 is dealt with before, we don't need to do anything about it now, so we only ask if #4 is \ , in which case we ignore it, otherwise we put it next to \theorem@attr as specified by \@rel.
{\begin{@thmattr2}[name=\theorem@attr\IfValueTF{#7}{\protect\contrel{#4}{\protect\hyperlink{#5}{#7}}}{}]}
%Finally, if a #7 is present, a \hyperlink is produced from the label in #5, with the text in #5, as specified by \contrel. \contrel basically defines what is between \theorem@attr and #7, and what follows it. In its base form, it is \ (continua da #7), because I write in Italian. If I wrote in English, it would be \ (continues from #7), or maybe "continued". There may be, in \contrel, a style setting, if you wish, but I discourage that.
}
{\end{@thmattr2}}%And in the \end part, just end the @thmattr2.
%From this analysis, we see that:
%1: #1 is the theorem kind (Theorem, Remark, Proposition, Lemma, etc) or the full theorem name in case of a theorem with a special name like the Hairy Ball Theorem, which has no counter. That's why it's the only mandatory argument;
%2: #2 is the name of the counter associated with that theorem kind;
%3: #3 is a parameter to decide the counter style: c corresponding to [chapter] in plain theorem declarations (\newtheorem{foo}[chapter]), s corresponding to [section], x corresponding to [subsection], and n for a lone counter, probably for exercises;
%4: #4 is the theorem's name in the page where it is started; if #6 is given, this corresponds to foo in {name=[bar]foo}, otherwise it is the foo in name=foo;
%6: #6 is the name in the \listoftheorems, thus corresponds to the bar in {name=[bar]foo}.
%7: #7, finally, delimited by (), is the text given to \contrel for the \hyperlink in the case of continued theorems. It should not include "continues from" or such, as that should be set to a default and handled precisely by \contrel.
\declaretheorem[style=mystyle]{@thmattr3}
\ExplSyntaxOn
%To make two different lists of theorems with xtheor-like environments, an xtheor3 environment using @thmattr3 theorems.
\NewDocumentEnvironment{xtheor3}{moO{a}oood()}%Many arguments, one mandatory and 5 optional, with default only for the second optional, set to x.
{\IfValueTF{#5}{\setcnt{#5}{\@ifundefined{c@#2}{0}{\arabic{#2}}}}{}\IfNoValueTF{#2}%Is there a 2?
{\def\theorem@attr{#1}}%No? Then \theorem@attr, which will probably become the theorem's name, is #1.
{\expandafter
\@ifundefined{c@#2}%There IS a 2? OK then it's a mess. Because it means we have a counter sequence to create. So is there a counter named like 2?
{\newcounter{#2} \setcounter{#2}{1}
\global\newcounter{mw@old#2chapter}
\global\newcounter{mw@old#2section}
\global\newcounter{mw@old#2subsection}
}%No? Make it. And set it to 1. Obvously it's the first theorem of that kind.
{\IfNoValueTF{#7}{\addtocounter{#2}{+1}}{}}%Yes? Then just increase it by +1.
\IfValueTF{#7}
{\@ifundefined{c@mw@#2cont}
{\newcounter{mw@#2cont}
\csname c@mw@#2cont\endcsname=\csname c@#2\endcsname
\csname c@#2\endcsname=\getcnt{#5}
\stepcounter{#2}}
{\csname c@mw@#2cont\endcsname=\csname c@#2\endcsname
\csname c@#2\endcsname=\getcnt{#5}
\stepcounter{#2}}
}
{}
\str_if_eq:nnTF{#3}{\csname mw@#2ctrseq\endcsname}
{}
{\savectr{#2}{#3}
\counterwithout{#2}{chapter}
\str_case:nnF{#3}
{{a}
{\ifnum\c@chapter>0
\ifnum\c@section>0
\ifnum\c@subsection>0
\counterwithin{#2}{subsection}
\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2chapter\endcsname=\c@chapter
\else
\setcounter{#2}{1}
\fi}
\@ifundefined{c@mw@old#2section}{}
{\expandafter\ifnum\csname c@mw@old#2section\endcsname=\c@section
\else
\setcounter{#2}{1}
\fi}
\@ifundefined{c@mw@old#2subsection}{}
{\expandafter\ifnum\csname c@mw@old#2subsection\endcsname=\c@subsection
\else
\setcounter{#2}{1}
\fi}
\else
\counterwithin{#2}{section}
\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2chapter\endcsname=\c@chapter
\else
\setcounter{#2}{1}
\fi}
\@ifundefined{c@mw@old#2section}{}
{\expandafter\ifnum\csname c@mw@old#2section\endcsname=\c@section
\else
\setcounter{#2}{1}
\fi}
\fi
\else
\counterwithin{#2}{chapter}
\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2chapter\endcsname=\c@chapter
\else
\setcounter{#2}{1}
\fi}
\fi
\else
{}
\fi
}
%This whole bunch of conditionals creates \acounters, the sequence for #3 = a. This is because putting them inside the definition of \counters directly for some reason didn't work. So if chapter is positive you start with chapter, then if section is positive you add section, then if subsection is positive you ad that too, and in any case \acounters ends with #2, if #7 isn't present, and with the saved counter if #7 is present. %Finally, a stands for automatic, which means if any of chapter, section or subsection is positive (i.e. not 0 and not negative), they are put in this order with separating dots, then we have, of course, #2. This is actually dealt with by the nested \ifs in the definition of \acounters, for if those \ifs were placed in here, it wouldn't work. I tried that. Trust me :).
{c}{\counterwithin{#2}{chapter}\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2chapter\endcsname=\c@chapter
\else
\setcounter{#2}{1}
\fi}
}%c stands for chapter numbering, so if #3 is c the counters are chapter, separating dot, #2, all in arabic representation.
{s}{\counterwithin{#2}{section}\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2chapter\endcsname=\c@chapter
\else
\setcounter{#2}{1}
\fi}
\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2section\endcsname=\c@section
\else
\setcounter{#2}{1}
\fi}
}%s stands for section, so if #3 is s we have chapter, dot, section, dot #2.
{x}{\counterwithin{#2}{subsection}\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2chapter\endcsname=\c@chapter
\else
\setcounter{#2}{1}
\fi}
\@ifundefined{c@mw@old#2chapter}{}
{\expandafter\ifnum\csname c@mw@old#2section\endcsname=\c@section
\else
\setcounter{#2}{1}
\fi}
\@ifundefined{c@mw@old#2subsection}{}
{\expandafter\ifnum\csname c@mw@old#2subsection\endcsname=\c@subsection
\else
\setcounter{#2}{1}
\fi}
}%x is subsection, so to those above we add the subsection counter.
{n}{\counterwithout{#2}{chapter}
}%n stands for none, so just #2.
%Wherever there is #2, if #7 is present we recover the saved counter.
{@@}{\expandafter\def\csname the#2\endcsname{@@}}%If it is @@, no counters at all, not even #2. That is to be able to use #5 (the label) when we have a special theorem which needs no number.
}
{\msg_fatal:nn{mworkx}{invalid-ctr}}
}%So now we have the counter sequence.
\IfValueTF{#5}{
\IfNoValueTF{#7}{
\xlabel{#5}{\str_if_eq:nnTF{#3}{@@}{}{\csname the#2\endcsname}}{\thepage}{#4}{#3}{\@ifundefined{c@#2}{1}{\arabic{#2}}}{#1}{\str_if_eq:nnTF{#3}{@@}{spec}{#2}}}{}
}{}%Label handling: if there is a 5 and no 7, you set a \hypertarget to here with no text and label #5, then you save the value of the page and the counter – no need to check it is there, since we are in the hypothesis #5 is present, which forces #2 to also be present. If #5 and #7 are both present, or if #7 is and #5 isn't, we have a continuing theorem, so no label handling. I forgot to say there is a check as to whether the label is already used, in which case a warning is issued from the package.
\global\csname c@mw@old#2chapter\endcsname=\csname c@chapter\endcsname
\global\csname c@mw@old#2section\endcsname=\csname c@section\endcsname
\global\csname c@mw@old#2subsection\endcsname=\csname c@subsection\endcsname
\def\theorem@attr{
#1
\str_if_eq:nnTF{#3}{@@}
{}
{\ \csname the#2\endcsname}
}}%At this point, we define \theorem@attr, which is the theorem's name, to be #1, which is the theorem kind or full theorem name when it's counterless, and #1 plus two \,s plus #4 when #3 is neither nothing nor @@. The spacing between the counters and #4 and company if present is handled by \@rel.
\def\name@thmlist{
#1\IfNoValueTF{#2}
{}
{
\str_if_eq:nnTF{#3}{@@}
{.}
{\ \csname the#2\endcsname
\IfValueTF{#4}
{\IfValueTF{#6}
{\@lrel{#6}}
{\@lrel{#4}}
}
{}
}}}%And we define \name@thmlist, which, as the name says, is the theorem's name in the \listoftheorems. This is #1, plus \ \counters, when #2 is present, plus #4 if present without #6, and plus #6 if #4 and #6 are present, in any case separated from \counters as specified by \@lrel if \counters doesn't end \name@thmlist. Requesting both presences is not restrictive, as no #4 implies no #6.
\IfValueTF{#7}{\global\csname c@#2\endcsname=\csname c@mw@#2cont\endcsname}{}
\IfNoValueTF{#7}
{\IfNoValueTF{#4}%Now we wonder: is #4 present?
{\begin{@thmattr3}[{name=[\name@thmlist]\theorem@attr}]}%No? Then we finally start a @thmattr3 with name \theorem@attr and name in the list \name@thmlist.
{\str_if_eq:nnTF{#4}{\ }
{\begin{@thmattr3}[{name=[\name@thmlist]\theorem@attr}]}
{\begin{@thmattr3}[{name=[\name@thmlist]\theorem@attr\@rel{#4}}]}
}}%Since the label in #5 is dealt with before, we don't need to do anything about it now, so we only ask if #4 is \ , in which case we ignore it, otherwise we put it next to \theorem@attr as specified by \@rel.
{\begin{@thmattr3}[name=\theorem@attr\IfValueTF{#7}{\protect\contrel{#4}{\protect\hyperlink{#5}{#7}}}{}]}
%Finally, if a #7 is present, a \hyperlink is produced from the label in #5, with the text in #5, as specified by \contrel. \contrel basically defines what is between \theorem@attr and #7, and what follows it. In its base form, it is \ (continua da #7), because I write in Italian. If I wrote in English, it would be \ (continues from #7), or maybe "continued". There may be, in \contrel, a style setting, if you wish, but I discourage that.
}
{\end{@thmattr3}}%And in the \end part, just end the @thmattr3.
%From this analysis, we see that:
%1: #1 is the theorem kind (Theorem, Remark, Proposition, Lemma, etc) or the full theorem name in case of a theorem with a special name like the Hairy Ball Theorem, which has no counter. That's why it's the only mandatory argument;
%2: #2 is the name of the counter associated with that theorem kind;
%3: #3 is a parameter to decide the counter style: c corresponding to [chapter] in plain theorem declarations (\newtheorem{foo}[chapter]), s corresponding to [section], x corresponding to [subsection], and n for a lone counter, probably for exercises;
%4: #4 is the theorem's name in the page where it is started; if #6 is given, this corresponds to foo in {name=[bar]foo}, otherwise it is the foo in name=foo;
%5: #5 is the label, so label=foo corresponds to foo in #5;
%6: #6, finally, is the name in the \listoftheorems, thus corresponds to the bar in {name=[bar]foo}.
%7: #7, finally, delimited by (), is the text given to \contrel for the \hyperlink in the case of continued theorems. It should not include "continues from" or such, as that should be set to a default and handled precisely by \contrel.
\newcommand{\xtheorsetlist}{\renewcommand\thmt@listnumwidth{-1.5em}}%This is sort of forced by the use of xtheor, so to speed it up I've made it into a command.
%Suppress indentation after xtheor environments, then create defaults for parameters.
\NoIndentAfterEnv{xtheor}
\NoIndentAfterEnv{xtheor2}
\NoIndentAfterEnv{xtheor3}
\ExplSyntaxOn
\expandafter\str_case:nnF\expandafter{\mw@lang}
{{italian}{
\newcommand{\mw@contname}{continua~da}
\newcommand{\mw@defname}{Definizione}
\newcommand{\mw@thname}{Teorema}
\newcommand{\mw@esname}{Esempio}
\newcommand{\mw@esename}{Esercizio}
\newcommand{\mw@ptname}{Punto}
\newcommand{\mw@riassname}{Riassunto}
\newcommand{\mw@propname}{Proposizione}
\newcommand{\mw@ossname}{Osservazione}
\newcommand{\mw@corname}{Corollario}
\newcommand{\mw@esecasaname}{Esercizio~svolto~da~me}
\newcommand{\mw@lemmaname}{Lemma}
\newcommand{\mw@fattoname}{Fatto}
\newcommand{\mw@eseese}{Esercizio~\eseesename}
\newcommand{\mw@eseeseb}{Esercizio~\eseesebname}
\newcommand{\mw@proofstring}{Dim.}
}
{english}{
\newcommand{\mw@contname}{continues~from}
\newcommand{\mw@defname}{Definition}
\newcommand{\mw@thname}{Theorem}
\newcommand{\mw@esname}{Example}
\newcommand{\mw@esename}{Exercise}
\newcommand{\mw@ptname}{Point}
\newcommand{\mw@riassname}{Sum-up}
\newcommand{\mw@propname}{Proposition}
\newcommand{\mw@ossname}{Remark}
\newcommand{\mw@corname}{Corollary}
\newcommand{\mw@esecasaname}{Exercise~done~by~me}
\newcommand{\mw@lemmaname}{Lemma}
\newcommand{\mw@fattoname}{Fact}
\newcommand{\mw@eseese}{\eseesename~exercise}
\newcommand{\mw@eseeseb}{\eseesebname~exercise}
\newcommand{\mw@proofstring}{Proof.}
\setprep{of}
}
{french}{
\newcommand{\mw@contname}{continue~de}
\newcommand{\mw@defname}{Définition}
\newcommand{\mw@thname}{Théorème}
\newcommand{\mw@esname}{Exemple}
\newcommand{\mw@esename}{Exercice}
\newcommand{\mw@ptname}{Point}
\newcommand{\mw@riassname}{Résumé}
\newcommand{\mw@propname}{Proposition}
\newcommand{\mw@ossname}{Observation}
\newcommand{\mw@corname}{Corollaire}
\newcommand{\mw@esecasaname}{Exercice~fait~par~moi}
\newcommand{\mw@lemmaname}{Lemma}
\newcommand{\mw@fattoname}{Fait}
\newcommand{\mw@eseese}{Exercice~\eseesename}
\newcommand{\mw@eseeseb}{Exercice~\eseesebname}
\newcommand{\mw@proofstring}{Dém.}
\setprep{de}
}
{german}{
\newcommand{\mw@contname}{fortfahrt~aus}
\newcommand{\mw@defname}{Definition}
\newcommand{\mw@thname}{Satz}
\newcommand{\mw@esname}{Beispiel}
\newcommand{\mw@esename}{Übung}
\newcommand{\mw@ptname}{Punkt}
\newcommand{\mw@riassname}{Zusammenfassung}
\newcommand{\mw@propname}{Proposition}
\newcommand{\mw@ossname}{Bemerkung}
\newcommand{\mw@corname}{Korollar}
\newcommand{\mw@esecasaname}{Von~mir~gemachte~Übung}
\newcommand{\mw@lemmaname}{Lemma}
\newcommand{\mw@fattoname}{Tatsache}
\newcommand{\mw@eseese}{\eseesename~Übung}
\newcommand{\mw@eseeseb}{\eseesebname~Übung}
\newcommand{\mw@proofstring}{Beweis.}
\setprep{von}
}
{spanish}{
\newcommand{\mw@contname}{continua~desde}
\newcommand{\mw@defname}{Definición}
\newcommand{\mw@thname}{Teorema}
\newcommand{\mw@esname}{Ejemplo}
\newcommand{\mw@esename}{Ejercicio}
\newcommand{\mw@ptname}{Punto}
\newcommand{\mw@riassname}{Resumen}
\newcommand{\mw@propname}{Proposición}
\newcommand{\mw@ossname}{Observación}
\newcommand{\mw@corname}{Corolario}
\newcommand{\mw@esecasaname}{Ejercicio~hecho~por~mí}
\newcommand{\mw@lemmaname}{Lema}
\newcommand{\mw@fattoname}{Hecho}
\newcommand{\mw@eseese}{Ejercicio~\eseesename}
\newcommand{\mw@eseeseb}{Ejercicio~\eseesebname}
\newcommand{\mw@proofstring}{Dem.}
\setprep{de}
}
{portuguese}{
\newcommand{\mw@contname}{continua~de}
\newcommand{\mw@defname}{Definição}
\newcommand{\mw@thname}{Teorema}
\newcommand{\mw@esname}{Exemplo}
\newcommand{\mw@esename}{Exercício}
\newcommand{\mw@ptname}{Ponto}
\newcommand{\mw@riassname}{Resumo}
\newcommand{\mw@propname}{Proposiçäo}
\newcommand{\mw@ossname}{Observaçäo}
\newcommand{\mw@corname}{Corolário}
\newcommand{\mw@esecasaname}{Exercício~feito~por~mim}
\newcommand{\mw@lemmaname}{Lema}
\newcommand{\mw@fattoname}{Fato}
\newcommand{\mw@eseese}{Exercício~\eseesename}
\newcommand{\mw@eseeseb}{Exercício~\eseesebname}
\newcommand{\mw@proofstring}{Prova.}
\setprep{de}
}
{polish}{
\newcommand{\mw@contname}{Ciągły~od}
\newcommand{\mw@defname}{Definicja}
\newcommand{\mw@thname}{Twierdzenie}
\newcommand{\mw@esname}{Przykład}
\newcommand{\mw@esename}{Ćwiczenie}
\newcommand{\mw@ptname}{Wynik}
\newcommand{\mw@riassname}{Streszczenie}
\newcommand{\mw@propname}{Propozycja}
\newcommand{\mw@ossname}{Obserwacja}
\newcommand{\mw@corname}{Następstwo}
\newcommand{\mw@esecasaname}{Ćwiczenie~zrobione~przeze~mnie}
\newcommand{\mw@lemmaname}{Lemat}
\newcommand{\mw@fattoname}{Fakt}
\newcommand{\mw@eseese}{Ćwiczenie~\eseesename}
\newcommand{\mw@eseeseb}{Ćwiczenie~\eseesebname}
\newcommand{\mw@proofstring}{Dowód.}
}
{chinese}{
\newcommand{\mw@contname}{继续}
\newcommand{\mw@contnameb}{从}
\renewcommand{\contrel}[2]{\ (#1\ --\ \mw@contnameb #2\mw@contname)}
\renewcommand{\resetcontrel}{\renewcommand{\contrel}[2]{\ (##1\ --\ \mw@contnameb ##2\mw@contname)}}
\newcommand{\mw@defname}{定义}
\newcommand{\mw@thname}{定理}
\newcommand{\mw@esname}{例子}
\newcommand{\mw@esename}{练习}
\newcommand{\mw@ptname}{短句}
\newcommand{\mw@riassname}{总结}
\newcommand{\mw@propname}{命题}
\newcommand{\mw@ossname}{备注}
\newcommand{\mw@corname}{推论}
\newcommand{\mw@esecasaname}{被我做的练习}
\newcommand{\mw@lemmaname}{引理}
\newcommand{\mw@fattoname}{事实}
\newcommand{\mw@eseese}{\eseesename~练习}
\newcommand{\mw@eseeseb}{\eseesebname~练习}
\newcommand{\mw@proofstring}{证明。}
}
}{\msg_warning:nnn{mworkx}{unknown-lang}{Theorem~names}}
\newenvironment{defi}
{\begin{xtheor}{\mw@defname}[defi][a]}
{\end{xtheor}\noindent}
\newenvironment{teor}
{\begin{xtheor}{\mw@thname}[teor][a]}
{\end{xtheor}}
\newenvironment{teorspec}[2][\mw@thname]
{\begin{xtheor}{#1\str_if_eq:nnTF{#2}{}{}{\ #2}}[spec][@@][\ ]}
{\end{xtheor}}
\newenvironment{es}
{\begin{xtheor}{\mw@esname}[es][a]}
{\end{xtheor}}
\newenvironment{ese}
{\begin{xtheor2}{\mw@esename}[ese][a]}
{\end{xtheor2}}
\newenvironment{pt}
{\begin{xtheor3}{\mw@ptname}[pt][n]}
{\end{xtheor3}}
\newenvironment{riass}
{\begin{xtheor3}{\mw@riassname}[riass][n]}
{\end{xtheor3}}
\newenvironment{propo}
{\begin{xtheor}{\mw@propname}[propo][a]}
{\end{xtheor}}
\newenvironment{oss}
{\begin{xtheor}{\mw@ossname}[oss][a]}
{\end{xtheor}}
\newenvironment{cor}
{\begin{xtheor}{\mw@corname}[cor][a]}
{\end{xtheor}}
\newenvironment{esecasa}
{\begin{xtheor3}{\mw@esecasaname}[esecasa][a]}
{\end{xtheor3}}
\newenvironment{lemma}
{\begin{xtheor}{\mw@lemmaname}[lemma][a]}
{\end{xtheor}}
\newenvironment{fatto}
{\begin{xtheor}{\mw@fattoname}[fatto][a]}
{\end{xtheor}}
\NewDocumentEnvironment{eseese}{D(){a}}
{\begin{xtheor3}{\mw@eseese}[eseese][#1]}
{\end{xtheor3}}
\NewDocumentEnvironment{eseeseb}{D(){a}}
{\begin{xtheor3}{\mw@eseeseb}[eseeseb][#1]}
{\end{xtheor3}}
\newcommand{\seteseese}{\def\eseesename}
\newcommand{\seteseeseb}{\def\eseesebname}
%Now xtheor as is sometimes causes awkward vertical spaces. The following commands, in one of their two versions, can always solve the problem, AFAIK at least.
\newcommand{\fixspace}{\@ifstar{\NoIndentAfterThis}{\@doendpe}}
\newcommand{\spacefix}{\@ifstar{\vsp{5pt}}{\vsp{\topsep}}}
%Environments for proofs in my style, with and without qed symbol.
\NewDocumentEnvironment{demo}{o}%
{\noindent
\IfValueTF{#1}
{#1 \\}
{}
\mw@proofstring\ \par}
{\\}
\NewDocumentEnvironment{qeddim}{o}%
{\noindent
\IfValueTF{#1}
{#1 \\}
{}
\mw@proofstring\ \par}
{\hfil\qedsym\linebreak}
%Definition of default \qedsym plus command to set it
\DeclareSymbolFont{lasy}{U}{lasy}{m}{n}
\SetSymbolFont{lasy}{bold}{U}{lasy}{b}{n}
\DeclareMathSymbol\Diamondx{\mathord}{lasy}{"33}
\newcommand{\qedsym}{$\Diamondx$}
\newcommand{\setqedsym}[1]{\renewcommand{\qedsym}{#1}}
\ExplSyntaxOff
\fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment