| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% enumsub.dtx |
| 4 |
% Copyright (C) 2025 by Srikanth Mohankumar <[email protected]> |
| 5 |
% |
| 6 |
% This work may be distributed and/or modified under the |
| 7 |
% conditions of the LaTeX Project Public License, either version 1.3c |
| 8 |
% of this license or (at your option) any later version. |
| 9 |
% The latest version of this license is in |
| 10 |
% http://www.latex-project.org/lppl.txt |
| 11 |
% and version 1.3c or later is part of all distributions of LaTeX |
| 12 |
% version 2008 or later. |
| 13 |
% |
| 14 |
% This work has the LPPL maintenance status `maintained'. |
| 15 |
% |
| 16 |
% The Current Maintainer of this work is Srikanth Mohankumar. |
| 17 |
% |
| 18 |
% This work consists of the files enumsub.dtx and enumsub.ins |
| 19 |
% and the derived file enumsub.sty. |
| 20 |
% |
| 21 |
% \fi |
| 22 |
% |
| 23 |
% \iffalse |
| 24 |
%<*driver> |
| 25 |
\ProvidesFile{enumsub.dtx} |
| 26 |
%</driver> |
| 27 |
%<package>\NeedsTeXFormat{LaTeX2e}[2020/10/01] |
| 28 |
%<package>\ProvidesPackage{enumsub} |
| 29 |
%<*package> |
| 30 |
[2025/08/04 v1.0 Aligned inline sublists for enumitem] |
| 31 |
%</package> |
| 32 |
% |
| 33 |
%<*driver> |
| 34 |
\documentclass{ltxdoc} |
| 35 |
\usepackage{enumsub} |
| 36 |
\usepackage[numbered]{hypdoc} |
| 37 |
\usepackage{xspace} |
| 38 |
\EnableCrossrefs |
| 39 |
\CodelineIndex |
| 40 |
\RecordChanges |
| 41 |
\begin{document} |
| 42 |
\DocInput{enumsub.dtx} |
| 43 |
\PrintChanges |
| 44 |
\PrintIndex |
| 45 |
\end{document} |
| 46 |
%</driver> |
| 47 |
% \fi |
| 48 |
% |
| 49 |
% \CheckSum{0} |
| 50 |
% |
| 51 |
% \CharacterTable |
| 52 |
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z |
| 53 |
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z |
| 54 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 55 |
% Exclamation \! Double quote \" Hash (number) \# |
| 56 |
% Dollar \$ Percent \% Ampersand \& |
| 57 |
% Acute accent \' Left paren \( Right paren \) |
| 58 |
% Asterisk \* Plus \+ Comma \, |
| 59 |
% Minus \- Point \. Solidus \/ |
| 60 |
% Colon \: Semicolon \; Less than \< |
| 61 |
% Equals \= Greater than \> Question mark \? |
| 62 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 63 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 64 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 65 |
% Right brace \} Tilde \~} |
| 66 |
% |
| 67 |
% |
| 68 |
% \changes{v1.0}{2025/08/04}{Initial version} |
| 69 |
% |
| 70 |
% \DoNotIndex{\newcommand,\newenvironment} |
| 71 |
% |
| 72 |
% |
| 73 |
% \providecommand*{\url}{\texttt} |
| 74 |
% \GetFileInfo{enumsub.dtx} |
| 75 |
% \title{The \textsf{enumsub} package} |
| 76 |
% \author{Srikanth Mohankumar \\ \url{[email protected]}} |
| 77 |
% \date{\fileversion~from \filedate} |
| 78 |
% |
| 79 |
% \maketitle |
| 80 |
% |
| 81 |
% \section{Introduction} |
| 82 |
% |
| 83 |
% The \textsf{enumsub} package provides seamless integration between |
| 84 |
% \textsf{enumitem} and inline sublists with perfect alignment and |
| 85 |
% automatic numbering. It solves the common alignment inconsistencies |
| 86 |
% that occur when trying to combine \textsf{enumitem} and \textsf{tasks} |
| 87 |
% packages. |
| 88 |
% |
| 89 |
% The package offers: |
| 90 |
% \begin{itemize} |
| 91 |
% \item Perfect alignment of inline sub-items with dynamic label styling |
| 92 |
% \item Multiple numbering schemes (Roman, alphabetic, Arabic) |
| 93 |
% \item Customizable spacing and dimensions |
| 94 |
% \item Easy-to-use semicolon-separated syntax |
| 95 |
% \item Non-breaking inline layout with consistent spacing |
| 96 |
% \end{itemize} |
| 97 |
% |
| 98 |
% \section{Usage} |
| 99 |
% |
| 100 |
% \subsection{Basic Usage} |
| 101 |
% |
| 102 |
% The main command is \cs{enumsub}, which takes semicolon-separated |
| 103 |
% items and displays them inline with automatic numbering: |
| 104 |
% |
| 105 |
% \begin{verbatim} |
| 106 |
% \begin{enumerate} |
| 107 |
% \item |
| 108 |
% \begin{enumerate} |
| 109 |
% \item \enumsub{yes; no; maybe} |
| 110 |
% \item \enumsub{option A; option B} |
| 111 |
% \end{enumerate} |
| 112 |
% \end{enumerate} |
| 113 |
% \end{verbatim} |
| 114 |
% |
| 115 |
% \subsection{Package Options} |
| 116 |
% |
| 117 |
% The package supports three numbering styles: |
| 118 |
% \begin{itemize} |
| 119 |
% \item \texttt{roman} (default): Uses Roman numerals (i), (ii), (iii) |
| 120 |
% \item \texttt{alpha}: Uses alphabetic numbering (a), (b), (c) |
| 121 |
% \item \texttt{arabic}: Uses Arabic numerals (1), (2), (3) |
| 122 |
% \end{itemize} |
| 123 |
% |
| 124 |
% Load the package with: \verb|\usepackage[roman]{enumsub}| |
| 125 |
% |
| 126 |
% \subsection{Customization} |
| 127 |
% |
| 128 |
% You can adjust the spacing using: |
| 129 |
% \begin{itemize} |
| 130 |
% \item \cs{setenumsublabelwidth}\marg{width} -- Width of the label column |
| 131 |
% \item \cs{setenumsubitemwidth}\marg{width} -- Width of each item column |
| 132 |
% \end{itemize} |
| 133 |
% |
| 134 |
% \section{Examples} |
| 135 |
% |
| 136 |
% \begin{enumerate}[label=\textbf{\arabic*.}] |
| 137 |
% \item This is a main question. |
| 138 |
% \begin{enumerate}[label=\textbf{(\alph*)}] |
| 139 |
% \item \enumsub{yes; no} |
| 140 |
% \item \enumsub{definitely; maybe; never} |
| 141 |
% \end{enumerate} |
| 142 |
% \end{enumerate} |
| 143 |
% |
| 144 |
% \section{Implementation} |
| 145 |
% |
| 146 |
% \StopEventually{} |
| 147 |
% |
| 148 |
% \section{Implementation} |
| 149 |
% |
| 150 |
% \begin{macrocode} |
| 151 |
%<*package> |
| 152 |
% \end{macrocode} |
| 153 |
% |
| 154 |
% Load required packages: |
| 155 |
% \begin{macrocode} |
| 156 |
\RequirePackage{enumitem} |
| 157 |
\RequirePackage{xparse} |
| 158 |
\RequirePackage{array} |
| 159 |
\RequirePackage{etoolbox} |
| 160 |
% \end{macrocode} |
| 161 |
% |
| 162 |
% \begin{macro}{\if@enumsub@roman} |
| 163 |
% \begin{macro}{\if@enumsub@alpha} |
| 164 |
% \begin{macro}{\if@enumsub@arabic} |
| 165 |
% Package options for numbering styles: |
| 166 |
% \begin{macrocode} |
| 167 |
\newif\if@enumsub@roman |
| 168 |
\newif\if@enumsub@alpha |
| 169 |
\newif\if@enumsub@arabic |
| 170 |
\@enumsub@romantrue |
| 171 |
% \end{macrocode} |
| 172 |
% \end{macro} |
| 173 |
% \end{macro} |
| 174 |
% \end{macro} |
| 175 |
% |
| 176 |
% Declare and process options: |
| 177 |
% \begin{macrocode} |
| 178 |
\DeclareOption{roman}{\@enumsub@romantrue\@enumsub@alphafalse\@enumsub@arabicfalse} |
| 179 |
\DeclareOption{alpha}{\@enumsub@alphatrue\@enumsub@romanfalse\@enumsub@arabicfalse} |
| 180 |
\DeclareOption{arabic}{\@enumsub@arabictrue\@enumsub@romanfalse\@enumsub@alphafalse} |
| 181 |
\ProcessOptions\relax |
| 182 |
% \end{macrocode} |
| 183 |
% |
| 184 |
% \begin{macro}{\enumsub@labelwidth} |
| 185 |
% \begin{macro}{\enumsub@itemwidth} |
| 186 |
% Customizable dimensions: |
| 187 |
% \begin{macrocode} |
| 188 |
\newdimen\enumsub@labelwidth |
| 189 |
\newdimen\enumsub@itemwidth |
| 190 |
\enumsub@labelwidth=2.2em |
| 191 |
\enumsub@itemwidth=1.5cm |
| 192 |
% \end{macrocode} |
| 193 |
% \end{macro} |
| 194 |
% \end{macro} |
| 195 |
% |
| 196 |
% \begin{macro}{\setenumsublabelwidth} |
| 197 |
% \begin{macro}{\setenumsubitemwidth} |
| 198 |
% User commands to adjust spacing: |
| 199 |
% \begin{macrocode} |
| 200 |
\newcommand{\setenumsublabelwidth}[1]{\enumsub@labelwidth=#1} |
| 201 |
\newcommand{\setenumsubitemwidth}[1]{\enumsub@itemwidth=#1} |
| 202 |
% \end{macrocode} |
| 203 |
% \end{macro} |
| 204 |
% \end{macro} |
| 205 |
% |
| 206 |
% \begin{macro}{\c@enumsub@counter} |
| 207 |
% Subpart counter that resets at each \cs{item}: |
| 208 |
% \begin{macrocode} |
| 209 |
\newcounter{enumsub@counter} |
| 210 |
\pretocmd{\item}{\setcounter{enumsub@counter}{0}}{}{} |
| 211 |
% \end{macrocode} |
| 212 |
% \end{macro} |
| 213 |
% |
| 214 |
% \begin{macro}{\enumsub@getlabel} |
| 215 |
% Determine label format based on options: |
| 216 |
% \begin{macrocode} |
| 217 |
\newcommand{\enumsub@getlabel}{% |
| 218 |
\if@enumsub@roman% |
| 219 |
\textbf{(\roman{enumsub@counter})}% |
| 220 |
\else\if@enumsub@alpha% |
| 221 |
\textbf{(\alph{enumsub@counter})}% |
| 222 |
\else\if@enumsub@arabic% |
| 223 |
\textbf{(\arabic{enumsub@counter})}% |
| 224 |
\fi\fi\fi% |
| 225 |
} |
| 226 |
% \end{macrocode} |
| 227 |
% \end{macro} |
| 228 |
% |
| 229 |
% \begin{macro}{\enumsub} |
| 230 |
% Core macro for aligned subparts: |
| 231 |
% \begin{macrocode} |
| 232 |
\NewDocumentCommand{\enumsub}{>{\SplitList{;}}m}{% |
| 233 |
\begin{tabular}{@{}*{10}{ll}@{}}% |
| 234 |
\ProcessList{#1}{\enumsub@renderitem}% |
| 235 |
\end{tabular}% |
| 236 |
} |
| 237 |
% \end{macrocode} |
| 238 |
% \end{macro} |
| 239 |
% |
| 240 |
% \begin{macro}{\enumsub@renderitem} |
| 241 |
% Render individual subpart: |
| 242 |
% \begin{macrocode} |
| 243 |
\newcommand{\enumsub@renderitem}[1]{% |
| 244 |
\stepcounter{enumsub@counter}% |
| 245 |
\makebox[\enumsub@labelwidth][l]{\enumsub@getlabel} & |
| 246 |
\makebox[\enumsub@itemwidth][l]{#1}% |
| 247 |
} |
| 248 |
% \end{macrocode} |
| 249 |
% \end{macro} |
| 250 |
% |
| 251 |
% Alternative command names for convenience: |
| 252 |
% \begin{macrocode} |
| 253 |
\let\AutoSubpartsAligned\enumsub |
| 254 |
\let\subparts\enumsub |
| 255 |
\let\inlineparts\enumsub |
| 256 |
% \end{macrocode} |
| 257 |
% |
| 258 |
% Predefined list styles: |
| 259 |
% \begin{macrocode} |
| 260 |
\SetEnumitemKey{mainq}{label=\textbf{\arabic*.},% |
| 261 |
leftmargin=2em,% |
| 262 |
itemsep=0.2em,% |
| 263 |
topsep=0.5em} |
| 264 |
\SetEnumitemKey{subq}{label=\textbf{(\alph*)},% |
| 265 |
leftmargin=2.8em,% |
| 266 |
itemsep=0.2em,% |
| 267 |
topsep=0.3em} |
| 268 |
% \end{macrocode} |
| 269 |
% |
| 270 |
% \begin{macrocode} |
| 271 |
%</package> |
| 272 |
% \end{macrocode} |
| 273 |
% |
| 274 |
% \Finale |
| 275 |
\endinput |