From 1e90c2e6f453642528ed8049736556a5f79a4152 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sun, 12 Sep 2021 20:34:58 +0000 Subject: crumbs (12sep21) git-svn-id: svn://tug.org/texlive/trunk@60483 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/latex/crumbs/crumbs.sty | 83 ++++++++++++++++----------- 1 file changed, 51 insertions(+), 32 deletions(-) (limited to 'Master/texmf-dist/tex/latex/crumbs') diff --git a/Master/texmf-dist/tex/latex/crumbs/crumbs.sty b/Master/texmf-dist/tex/latex/crumbs/crumbs.sty index 2b497078da6..17194892c04 100644 --- a/Master/texmf-dist/tex/latex/crumbs/crumbs.sty +++ b/Master/texmf-dist/tex/latex/crumbs/crumbs.sty @@ -21,13 +21,19 @@ % SOFTWARE. \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{crumbs}[2021/09/09 0.2.2 Navigation Crumbs] +\ProvidesPackage{crumbs}[2021/09/12 0.3.0 Navigation Crumbs] + +\makeatletter\newif\ifcrumbs@dry\makeatother +\makeatletter\DeclareOption{dry}{\crumbs@drytrue}\makeatother +\makeatletter\newif\ifcrumbs@increment\makeatother +\makeatletter\DeclareOption{increment}{\crumbs@incrementtrue}\makeatother +\ProcessOptions\relax \RequirePackage{etoolbox} % see https://tex.stackexchange.com/a/12414/1449 -\makeatletter\newcommand\back{\@backslashchar}\makeatother -\makeatletter\newcommand\percent{\@percentchar}\makeatother +\makeatletter\newcommand\crumbs@back{\@backslashchar}\makeatother +% \makeatletter\newcommand\crumbs@percent{\@percentchar}\makeatother \RequirePackage{catchfile} \newwrite\appendwrite \newcommand*\appendtofile[2]{% @@ -49,46 +55,59 @@ \fi } -\NewCommandCopy\crumbsoldsection\section -\renewcommand\section[2][]{ - \def\temp{#1} - \ifx\crumbs\empty +\makeatletter\newcommand\crumbection[2][]{% + \def\temp{#1}% + \ifx\crumbs\empty% \appendtofile{\jobname.crumbs}{ - \back ifx \back crumbs \back empty - \back gappto \back crumbs{\back setcounter{crumbi}{0}} - \back fi - \back gappto\back crumbs{\back stepcounter{crumbi}\back crumb{\ifx\temp\empty #2\else #1\fi}{#2}} - } - \fi - \crumbsoldsection{#2} -} + \crumbs@back ifx \crumbs@back crumbs \crumbs@back empty + \crumbs@back gappto \crumbs@back crumbs{\crumbs@back setcounter{crumbi}{0}} + \crumbs@back fi + \crumbs@back gappto\crumbs@back crumbs{\crumbs@back stepcounter{crumbi}\crumbs@back crumb{\ifx\temp\empty #2\else #1\fi}{#2}} + }% + \fi% + \ifcrumbs@increment\stepcounter{section}\fi% +}\makeatother -\NewCommandCopy\crumbsoldsubsection\subsection -\renewcommand\subsection[2][]{ - \def\temp{#1} - \ifx\crumbs\empty +\makeatletter\newcommand\subcrumbection[2][]{% + \def\temp{#1}% + \ifx\crumbs\empty% \appendtofile{\jobname.crumbs}{ - \back ifcsname crumbs\romannumeral\the\value{section}\back endcsname\back else - \back expandafter\back newcommand\back csname crumbs\romannumeral\the\value{section}\back endcsname{% - \back setcounter{subcrumbi}{0} + \crumbs@back ifcsname crumbs\romannumeral\the\value{section}\crumbs@back endcsname\crumbs@back else + \crumbs@back expandafter\crumbs@back newcommand\crumbs@back csname crumbs\romannumeral\the\value{section}\crumbs@back endcsname{% + \crumbs@back setcounter{subcrumbi}{0} } - \back fi - \back expandafter\back gappto\back csname crumbs\romannumeral\the\value{section}\back endcsname{% - \back stepcounter{subcrumbi} - \back subcrumb{\ifx\temp\empty #2\else #1\fi}{#2} + \crumbs@back fi + \crumbs@back expandafter\crumbs@back gappto\crumbs@back csname crumbs\romannumeral\the\value{section}\crumbs@back endcsname{% + \crumbs@back stepcounter{subcrumbi} + \crumbs@back subcrumb{\ifx\temp\empty #2\else #1\fi}{#2} } - } - \fi - \crumbsoldsubsection{#2} -} + }% + \fi% + \ifcrumbs@increment\stepcounter{subsection}\fi% +}\makeatother + +\makeatletter\ifcrumbs@dry + \message{Since "dry" mode is ON we don't renew "section" and "subsection" commands} +\else + \NewCommandCopy\crumbs@oldsection\section + \renewcommand\section[2][]{% + \crumbection[#1]{#2}% + \crumbs@oldsection{#2}% + } + \NewCommandCopy\crumbs@oldsubsection\subsection + \renewcommand\subsection[2][]{% + \subcrumbection[#1]{#2}% + \crumbs@oldsubsection{#2}% + } +\fi\makeatletter \ifcsname crumb\endcsname - \message{The command "crumb" already defined} + \message{The command "crumb" is already defined} \else \newcommand\crumb[2]{#1} \fi \ifcsname subcrumb\endcsname - \message{The command "crumb" already defined} + \message{The command "subcrumb" is already defined} \else \newcommand\subcrumb[2]{#1} \fi -- cgit v1.2.3