% EVERYBODY IS FREE TO BORROW THE FILE AND CHANGE IT
% UNDER ONE CONDITION OF NEVER ASKING ME WHY THE THING WORKS
% OR DOES NOT WORK
%
% If I write a book,
%
% I use this file TheGOST3.tex when I wish to number thms and such and 
% formulas by one number like 25 put on the left in the case of thms
% and such and to refer to say Thm 25 in the same section as Thm 25, 
% otherwise in the same chapter as Sec.Thm 25, where Sec is the number
% of the section in which Thm 25 appears, and otherwise in the book
% as Ch.Sec.Thm 25, where Ch is the ...The same for formulas.
%
% To use the file some work is to be done.
% Type \swapnumbers righ after \documentclass{amsbook}.
% Type \input{TheGOST3} (this-file name) after all definitions in preamble
% where \newcommand{\mysection} (or mychapter or
% mysubsection) should not be present (otherwise
% change below \newcommand{\mysection} by \renewcommand{\mysection})....
% In addition, all \section{ , \subsection{ and \chapter{ commands
% in the tex file
% should be replaced with \mysection{ , \mysubsection{ , and \mychapter{ 
% (but not those like \section*{  which
% should be addressed in a different way).
%
% To see what an ugly thing I have only using the standard Latex2e,
% in preamble comment out \input{TheGOST3} and \swapnumbers,
% type \newcommand{\mysection}{\section}, the same
% with \mychapter and \mysubsection, and change
% \def\thechapter{-1A} (see later)
% with \def\thechapter{A}
%
\makeatletter
%
\renewcommand{\thechapter}{\arabic{chapter}}
\renewcommand{\thesection}{\arabic{section}}% In section titles
% only one number appears but \mysection (see later) allows using labels
% different from \thesection
\renewcommand{\thesubsection}{\arabic{section}:\arabic{subsection}}
\renewcommand{\theequation}{.\thechapter.\arabic{section}.\arabic{equation}}
\renewcommand{\thetheorem}{.\thechapter.\arabic{section}.\arabic{theorem}}%
%
\newcommand{\mychapter}[2][1]{\chapter{#2}
\setcounter{equation}{0}
 \edef\@currentlabel{.\arabic{chapter}}% As far as I remember
                                       % without this command \label{...} 
                                       % after \mychapter does not produce
                                       % any newlabel in aux file
\markboth{\sc{Chapter \arabic{chapter}. {#1}}, 
Sec \arabic{section}}{}}% To have special headings
%
\newcommand{\mysection}[2][1]{% 
\section{#2}\setcounter{equation}{0}
 \edef\@currentlabel{.\thechapter.\arabic{section}}
\markright{\sc{Ch \arabic{chapter} Section \arabic{section}. {#1}}}}
%
\newcommand{\mysubsection}[1]{\subsection{#1}
\edef\@currentlabel{.\arabic{chapter}.\arabic{section}:\arabic{subsection}}}
%
%
% To number equations in the printout by one number like 25 
% but get in aux file
% the info .Ch.Sec.25 which through \ref (defined below)
% allows to extract different versions of ref numbers 
% on different occasions
\def\mojtag#1{\hbox{\m@th\normalfont#1}}
\def\tagform@#1{\mojtag{(\ignorespaces\arabic{equation}\unskip)}}
%
%%\def\swappedhead#1#2#3{%        % This worked fine with Latex 2.09 
%%\kern-\parindent                % and didn't do anything (!) for Latex 2e
%%{\bf\arabic{theorem}}%          % in Textures 1.8 or 2.0 because there
%%\thmname{. #1}\thmnote{ {\the\theoremnotefont(#3)}}}
                                  % \swappedhead does not exist
% (only \swappedhead@plain). Still I commented it out because 
% in some implementations of Latex 2e (Windows?) the command \swappedhead 
% exists and then what followed contradicted something.
% Luckily then the following does not do any harm for Latex 2e
% with Textures 1.8 or 2.0 and does work with Windows implementation.
% The command is found in amsart.cls on Windows Latex 2e
\def\swappedhead#1#2#3{%
\kern-\parindent
{\bf\arabic{theorem}}\thmname{\@ifnotempty{#2}{. }#1}%
  \thmnote{ \textmd{\upshape(#3)}}}
% The following  is found in amsart.cls in Textures 1.8 Latex 2e.
\def\swappedhead@plain#1#2#3{%
\kern-\parindent{\bf\arabic{theorem}}\thmname{\@ifnotempty{#2}{. }#1}%
  \thmnote{ \textmd{\upshape(#3)}}}
%
% Next found by \meaning\ref  Probably very old.
\def\granddadref#1{\expandafter\@setref\csname r@#1\endcsname\@firstoftwo{#1}}
%
\renewcommand{\ref}[1]{% good to know that \if...\else whatever\fi
                       % produces . and \if11something\else whatever\fi 
                       % yields this something. Therefore 
                       % the command \if.\dadref{#1} and so on below
                       % chops off . (one point) from \dadref{#1}
                       % if there is anything to chop from. 
$\def\aref{\if.\granddadref{#1}\else-1{\bf??}%
\protect\G@refundefinedtrue % without this there is no warning
                            % in the end of .log that there were 
                            % undefined refs
\@warning{Reference `#1' on page \thepage \space is not defined}
\fi}%
%
% Next was found after many tries to accomodate all the above
% wishes and also to cope with the case of \chapter*{Appendix}
% to results of which I wanted to refer to like...Lemma A.1.1..
% "A" is not any \arabic{chapter}. This is why right after
% \chapter*{Appendix} I typed 
% \renewcommand{\thechapter}{-1A}
% \setcounter{chapter}{-1}
% \setcounter{section}{0}
% (-1 disappears in the very end,
% -1 is to make \aref look as a number)
%  
\def\refa{\ifnum\arabic{chapter}=\aref\else\aref\fi}%
% Chops off chapter # in the same chapter apart from Appndxes
% Refs to them are still say -1A.3.2 everywhere apart from Appndxes
%
\def\refaa{\if A\refa\else\refa\fi}
% Chops off A if in Appendix A
\def\refb{\if.\refaa\else-1.\aref\fi}
% -1. to push irrelevant to unwinding the label
%  aside, disappears
% in the very end
\def\refc{\ifnum\arabic{section}=\refb\else\refb\fi}
\def\refd{\if.\refc\else\refb\fi}
\def\refe{\ifnum-1=\refd\else\refd\fi}
 \def\reff{\if.\refe\else\refe\fi}
 \textup{\ifnum-1=\reff\else\reff\fi}$}
% $'s eliminate extra space (of which there is plenty) and \text
% is for right appearance of references in texts of thms.
% It is also perfect for run-in headings in 10pt.
%
 
\makeatother
%% END of file TheMAINGOST2024.tex