Created
August 6, 2024 16:44
-
-
Save yangzhixuan/5d3deed9f609bda3f309f2bc328117d9 to your computer and use it in GitHub Desktop.
Fine-grain numbered elements/theorems
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\usepackage{amsthm} | |
\usepackage{cleveref} | |
\usepackage{etoolbox} | |
\newcounter{everythingcnt} | |
\newcounter{Heverythingcnt} % the corresponding counter for hyperref | |
\providecommand{\lfstyle}[1]{#1} % \lfstyle is the command for lining figures in many font packages. If there's none, we use an empty one | |
\makeatletter | |
% Assuming that we will never skip levels (e.g. opening a subsection before opening | |
% a section of a chapter, we can infer the current level of structures by looking | |
% at which level counter is 0. | |
\newcommand{\currentLevel}{% | |
\ifnum\c@section=0 % | |
\thechapter | |
\else | |
\ifnum\c@subsection=0 % | |
\thesection | |
\else | |
\ifnum\c@subsubsection=0 % | |
\thesubsection | |
\else | |
\thesubsubsection | |
\fi | |
\fi | |
\fi | |
} | |
\newcommand{\currentLevelH}{% | |
\ifnum\c@section=0 % | |
\theHchapter | |
\else | |
\ifnum\c@subsection=0 % | |
\theHsection | |
\else | |
\ifnum\c@subsubsection=0 % | |
\theHsubsection | |
\else | |
\theHsubsubsection | |
\fi | |
\fi | |
\fi | |
} | |
\newcommand{\setupeverythingcnt}{% | |
\setcounter{everythingcnt}{0}% | |
\renewcommand*{\theeverythingcnt}{\currentLevel\textasteriskcentered\arabic{everythingcnt}}% | |
\renewcommand*{\theHeverythingcnt}{\currentLevelH.\arabic{everythingcnt}}% | |
} | |
% Whenever enters a new leve, the element counter is reset and its format is updated. | |
\apptocmd{\@sect}{\setupeverythingcnt}{}{}% | |
\setupeverythingcnt | |
\makeatother | |
\newlength{\elementspace} | |
%\setlength{\elementspace}{10pt plus 6pt minus 4pt} | |
\setlength{\elementspace}{10pt plus 6.675pt} | |
\newtheoremstyle{mytheorem}% 〈name〉 | |
{\elementspace}% 〈Space above〉 | |
{\elementspace}% 〈Space below〉 | |
{\thfamily}% 〈Body font〉 | |
{}% 〈Indent amount〉 | |
{\bfseries}% 〈Theorem head font〉 | |
{.}% 〈Punctuation after theorem head〉 | |
{.5em}% 〈Space after theorem head | |
{{\normalfont\bfseries\lfstyle\thmnumber{#2} \thmname{#1}}\thmnote{\normalfont \ (#3)}}% 〈Theorem head spec (can be left empty, meaning ‘normal’) | |
% {\llap{\thmname{#1}\hspace{2em}}\thmnumber{#2}\thmnote{ \normalfont(#3)}}% 〈Theorem head spec (can be left empty, meaning ‘normal’) | |
\newtheoremstyle{mydefinition}% 〈name〉 | |
{\elementspace}% 〈Space above〉 | |
{\elementspace}% 〈Space below〉 | |
{}% 〈Body font〉 | |
{}% 〈Indent amount〉 | |
{\bfseries}% 〈Theorem head font〉 | |
{.}% 〈Punctuation after theorem head〉 | |
{.5em}% 〈Space after theorem head | |
% {(\thmnumber{#2}) \thmname{#1}\thmnote{ \normalfont(#3)}}% 〈Theorem head spec (can be left empty, meaning ‘normal’) | |
{{\normalfont\bfseries\lfstyle\thmnumber{#2} \thmname{#1}}\thmnote{\normalfont \ (#3)}}% 〈Theorem head spec (can be left empty, meaning ‘normal’) | |
\newtheoremstyle{basic}% 〈name〉 | |
{\elementspace}% 〈Space above〉 | |
{\elementspace}% 〈Space below〉 | |
{}% 〈Body font〉 | |
{}% 〈Indent amount〉 | |
{\bfseries}% 〈Theorem head font〉 | |
{.}% 〈Punctuation after theorem head〉 | |
{.5em}% 〈Space after theorem head | |
{{\normalfont\bfseries\lfstyle\thmnumber{#2}}\thmnote{\normalfont \ ({#3})}}% 〈Theorem head spec (can be left empty, meaning ‘normal’) | |
%{{\normalfont\bfseries\lfstyle\thmnumber{#2}}}% 〈Theorem head spec (can be left empty, meaning ‘normal’) | |
\theoremstyle{mytheorem} | |
\newtheorem{theorem}[everythingcnt]{Theorem} | |
\theoremstyle{mydefinition} | |
\newtheorem{definition}[everythingcnt]{Definition} | |
\newtheorem{example}[everythingcnt]{Example} | |
\newtheorem{axiom}[everythingcnt]{Axiom} | |
\newtheorem{remark}[everythingcnt]{Remark} | |
\newtheorem{notation}[everythingcnt]{Notation} | |
\newtheorem{convention}[everythingcnt]{Convention} | |
\newtheorem{terminology}[everythingcnt]{Terminology} | |
\newtheorem{corollary}[everythingcnt]{Corollary} | |
\newtheorem{lemma}[everythingcnt]{Lemma} | |
\newtheorem{conjecture}[everythingcnt]{Conjecture} | |
\newtheorem{proposition}[everythingcnt]{Proposition} | |
\theoremstyle{basic} | |
\newtheorem{element}[everythingcnt]{Element} | |
\crefname{element}{}{} | |
\Crefname{element}{}{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass{article} | |
\input{numbering.tex} | |
\begin{document} | |
\section{Introduction} | |
\begin{element} | |
Hello | |
\end{element} | |
\subsection{World} | |
\begin{element} | |
Hello | |
\end{element} | |
\begin{element} | |
Again | |
\end{element} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment