発言者: トノ
発言日: 2019 06/21 17:50
ちょっと時間を持て余していたので、パッケージに仕立ててみました。
スクラッチ用途のスイッチは何だっけ、\@cons の引数ってどう
指定するんだっけ…てな感じで、随分と知識が欠落しているのを感じて
しまいました。久しぶりのマクロいじりだというのもあるでしょうが、
やはり年齢的なものでしょうねぇ…。
【次行から】
%==== ctrinitval.sty ===================================================
%
% カウンターの初期値を設定する
%
%=======================================================================
\@temptokena={2019/06/21 }% <-- file date
% '^^^^^^^^^^'
\begingroup
\@ifundefined{documentclass}{%
\@ifundefined{SetCtrInitVal}{%
\def\reserved@a{\wlog{==== ctrinitval.sty == \the\@temptokena ====}}%
}{%
\def\reserved@a{\endinput}%
}%
}{%
\def\reserved@a{%
\NeedsTeXFormat{LaTeX2e}\relax
\ProvidesPackage{ctrinitval}[\the\@temptokena
\space Configuration of initial value of counter%
]%
}%
}%
\expandafter
\endgroup\reserved@a
\def\SetCtrInitVal#1#2{%
\@cons\CtrInitVal@{{#1}}%
\@tempcnta=#2\relax
\advance\@tempcnta by\m@ne
\expandafter\global\expandafter\mathchardef\csname
CtrInitVal@#1%
\endcsname=\@tempcnta
}
\let\CtrInitVal@\@empty
\def\@stpelt#1{%
\@tempswafalse
\let\@elt=\CtrInitVal@elt
\def\reserved@a{#1}%
\CtrInitVal@
\if@tempswa
\global\csname c@#1\endcsname=\csname CtrInitVal@#1\endcsname
\else
\global \csname c@#1\endcsname \z@
\fi
}
\def\CtrInitVal@elt#1{%
\def\reserved@b{#1}%
\ifx \reserved@a \reserved@b
\@tempswatrue
\fi
}
%=======================================================================
\endinput %===========================================================
%=======================================================================
==== USAGE ===========================================================
\SetCtrInitVal{NAME}{VALUE}
VALUE : 整数(1 以上 32768 以下)
NAME という名称のカウンターが、親カウンターの繰り上がりにより
リセットされる際に、その値が VALUE になるようにする。
==== HISTORY =========================================================
2019/06/21 initial version
========================================================================
【前行まで】
以下、使用例。
\documentclass{article}\relax
\usepackage{ctrinitval}\relax
\SetCtrInitVal{subsection}{3}
\begin{document}
\section{SECTION 1}
\subsection{The firsrt subsection}
\subsection{The second subsection}
\subsection{The third subsection}
\subsection{The fourth subsection}
\section{SECTION 2}
\subsection{The first subsection}
\end{document}
▼関連発言
│
└◆1465:親子カウンタについて [hashizume] 06/20 22:01
├◆1466:--- [---] 06/21 13:41
│└◆1468:Re[2]:親子カウンタについて [hashizume] 06/21 14:03
└◆1467:Re:親子カウンタについて [トノ] 06/21 13:56
└◆1469:Re[2]:親子カウンタについて [hashizume] 06/21 14:04
├◆1470:--- [---] 06/21 15:59
└◆1471:Re[3]:親子カウンタについて [トノ] 06/21 17:50<-last