From efa3a013f699c533896b44e4fcb74c730e94ad34 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Thu, 23 Dec 2021 03:00:54 +0000 Subject: CTAN sync 202112230300 --- macros/luatex/generic/autopuncitems/README.md | 28 --- .../luatex/generic/autopuncitems/autopuncitems.lua | 106 ----------- .../luatex/generic/autopuncitems/autopuncitems.pdf | Bin 35326 -> 0 bytes .../luatex/generic/autopuncitems/autopuncitems.sty | 56 ------ .../luatex/generic/autopuncitems/autopuncitems.tex | 201 --------------------- macros/luatex/latex/autopuncitems/README.md | 28 +++ .../luatex/latex/autopuncitems/autopuncitems.lua | 106 +++++++++++ .../luatex/latex/autopuncitems/autopuncitems.pdf | Bin 0 -> 35326 bytes .../luatex/latex/autopuncitems/autopuncitems.sty | 56 ++++++ .../luatex/latex/autopuncitems/autopuncitems.tex | 201 +++++++++++++++++++++ 10 files changed, 391 insertions(+), 391 deletions(-) delete mode 100644 macros/luatex/generic/autopuncitems/README.md delete mode 100644 macros/luatex/generic/autopuncitems/autopuncitems.lua delete mode 100644 macros/luatex/generic/autopuncitems/autopuncitems.pdf delete mode 100644 macros/luatex/generic/autopuncitems/autopuncitems.sty delete mode 100644 macros/luatex/generic/autopuncitems/autopuncitems.tex create mode 100644 macros/luatex/latex/autopuncitems/README.md create mode 100644 macros/luatex/latex/autopuncitems/autopuncitems.lua create mode 100644 macros/luatex/latex/autopuncitems/autopuncitems.pdf create mode 100644 macros/luatex/latex/autopuncitems/autopuncitems.sty create mode 100644 macros/luatex/latex/autopuncitems/autopuncitems.tex (limited to 'macros/luatex') diff --git a/macros/luatex/generic/autopuncitems/README.md b/macros/luatex/generic/autopuncitems/README.md deleted file mode 100644 index 3cd4844b10..0000000000 --- a/macros/luatex/generic/autopuncitems/README.md +++ /dev/null @@ -1,28 +0,0 @@ -# autopuncitems - -Automatically punctuate lists by passing the autopunc option to enumitem lists. - -# License - -Copyright (C) 2021 Kale Ewasiuk - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE -OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/macros/luatex/generic/autopuncitems/autopuncitems.lua b/macros/luatex/generic/autopuncitems/autopuncitems.lua deleted file mode 100644 index 5e8e5b10c6..0000000000 --- a/macros/luatex/generic/autopuncitems/autopuncitems.lua +++ /dev/null @@ -1,106 +0,0 @@ ---% Kale Ewasiuk (kalekje@gmail.com) ---% 2021-12-20 ---% Copyright (C) 2021 Kale Ewasiuk ---% ---% Permission is hereby granted, free of charge, to any person obtaining a copy ---% of this software and associated documentation files (the "Software"), to deal ---% in the Software without restriction, including without limitation the rights ---% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ---% copies of the Software, and to permit persons to whom the Software is ---% furnished to do so, subject to the following conditions: ---% ---% The above copyright notice and this permission notice shall be included in ---% all copies or substantial portions of the Software. ---% ---% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ---% ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED ---% TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A ---% PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT ---% SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ---% ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ---% ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ---% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE ---% OR OTHER DEALINGS IN THE SOFTWARE. - - -local ap = {} -- module table - -function ap.rtrim(s) - return (s:gsub("^(.-)%s*$", "%1")) -end - -ap.punc = {} -ap.punc = {'.', '; and'} -- punctuation table, 1 is last val, 2 is 2nd last val -ap.punc[0] = ';' -- [0] is default punctuation -ap.total = 0 -- total num of items (int) -ap.curr = 0 -- current item we're on (int) -ap.itemp = '\9' -- temporary item, item which WILL be affected by autopunc -ap.item = '\\item' -- item -ap.omit = '\\APomit' -- flag for hiding an item from punc and count, acts as if item is not there -ap.pass = '\\APpass' -- flag for passing item from punc, but still considered in count -ap.code = 0 -- code for skipping punc if > 0, keep in count if == 1, omit from count if == 2 - -ap.autopassnested = true - -function ap.start(s) - ap.curr = 0 - _, ap.total = s:gsub(ap.itemp, '') - local _, omit = s:gsub(ap.omit, '') - ap.total = ap.total - omit -end - -function ap.setcode(s) - local _, code1 = s:gsub(ap.pass, '', 1) - local _, code2 = s:gsub(ap.omit, '', 1) - ap.code = code1 + 2*code2 -end - -function ap.addcount(s) - ap.setcode(s) - if ap.code < 2 then -- if not omitting, we still keep counter going - ap.curr = ap.curr + 1 -- increment counter - end -end - -function ap.getdelim() - local d = '' - if ap.code == 0 then -- d limiter -- if not passing look at punctuation table for delimiter - d = ap.punc[ap.total-ap.curr+1] or ap.punc[0] - end - return d -end - -function ap.protectnest(s) - local x = '' - if ap.autopassnested then x = ap.pass..'{}' end - s = s:gsub("\0", "\0", 0) -- dummy replacement to make code easier - :gsub("\\begin%s*{itemize}", x.."\1%0") -- pad \1 and \2 in inner envirnments - :gsub("\\end%s*{itemize}", "%0\2") - :gsub("\\begin%s*{enumerate}", x.."\1%0") - :gsub("\\end%s*{enumerate}", "%0\2") - :gsub("\\begin%s*{description}", x.."\1%0") - :gsub("\\end%s*{description}", "%0\2") - :gsub("%b\1\2", "\0%0\0") -- use bracket to place \0 (on OUTER) nested lists only - :gsub("(%Z*)%z?(%Z*)%z?", -- only affect matches outside list - function(a, b) return a:gsub(ap.item, ap.itemp)..b:gsub("[\1\2]", "") end) - return s -end - - -function ap.go(s) - s = ap.protectnest(s) - ap.start(s) -- start counters - --texio.write_nl('yooo...'..s) - s = s:gsub(ap.itemp, '\0\0'):gsub('\0', '', 1) -- make all items \0\0 then change first item to one \0 - s = s:gsub('(%z)(%Z*)(%z?)', -- find betwen \0 .. \0 - function(it, s, _it) -- discarding duplicate item '_it' that was made in first gsub - ap.addcount(s) -- add count, helps determine delimiter - return ap.rtrim(it..s)..ap.getdelim()..' ' - end - ) - s = s:gsub('\0', ap.itemp) -- replace items - s = s:gsub(ap.itemp, ap.item) -- replace items - return s -end - -return ap \ No newline at end of file diff --git a/macros/luatex/generic/autopuncitems/autopuncitems.pdf b/macros/luatex/generic/autopuncitems/autopuncitems.pdf deleted file mode 100644 index fd743e4d99..0000000000 Binary files a/macros/luatex/generic/autopuncitems/autopuncitems.pdf and /dev/null differ diff --git a/macros/luatex/generic/autopuncitems/autopuncitems.sty b/macros/luatex/generic/autopuncitems/autopuncitems.sty deleted file mode 100644 index 8045fa4737..0000000000 --- a/macros/luatex/generic/autopuncitems/autopuncitems.sty +++ /dev/null @@ -1,56 +0,0 @@ -% Kale Ewasiuk (kalekje@gmail.com) -% 2021-12-20 -% Copyright (C) 2021 Kale Ewasiuk -% -% Permission is hereby granted, free of charge, to any person obtaining a copy -% of this software and associated documentation files (the "Software"), to deal -% in the Software without restriction, including without limitation the rights -% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -% copies of the Software, and to permit persons to whom the Software is -% furnished to do so, subject to the following conditions: -% -% The above copyright notice and this permission notice shall be included in -% all copies or substantial portions of the Software. -% -% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -% ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -% TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -% PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -% SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR -% ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -% ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE -% OR OTHER DEALINGS IN THE SOFTWARE. - - -\ProvidesPackage{autopuncitems}[2021-12-20] - -\RequirePackage{enumitem} -\RequirePackage{luacode} - -\luadirect{autopuncitems = require'autopuncitems'} - -\newcommand{\APomit}{} % blank flag used in '\item' to hide it from counting and auto -\newcommand{\APpass}{} % blank flag used in '\item', autopunc is skipped, but count is still - -\newcommand{\disableAPautopassnest}{\luadirect{autopuncitems.autopassnested = false}} -\newcommand{\enableAPautopassnest}{\luadirect{autopuncitems.autopassnested = true}} - -\NewDocumentCommand{\setAPeach}{m m m}{\setAPdef{#1}\setAPseclast{#2}\setAPlast{#3}} % set each one, default, second last, last -\NewDocumentCommand{\setAPall}{m}{\setAPdef{#1}\setAPseclast{#1}\setAPlast{#1}} % set all the same -\NewDocumentCommand{\setAPdef}{m}{\luadirect{autopuncitems.punc[0] = \luastring{#1}}} % default punc value -\NewDocumentCommand{\setAPlast}{m}{\luadirect{autopuncitems.punc[1] = \luastring{#1}}} % second last punc value -\NewDocumentCommand{\setAPseclast}{m}{\luadirect{autopuncitems.punc[2] = \luastring{#1}}} % final punc value - -\NewDocumentEnvironment{AutoPuncItemize}{ +b }{ -% \luadirect{texio.write_nl('auto >>>'..autopuncitems.go(\luastringN{#1}))} - \luadirect{tex.print(autopuncitems.go(\luastringN{#1}))} -}{} - -\SetEnumitemKey{autopunc}{ - first*=\expandafter\AutoPuncItemize, - after=\endAutoPuncItemize, -} - - - diff --git a/macros/luatex/generic/autopuncitems/autopuncitems.tex b/macros/luatex/generic/autopuncitems/autopuncitems.tex deleted file mode 100644 index fd829b81e6..0000000000 --- a/macros/luatex/generic/autopuncitems/autopuncitems.tex +++ /dev/null @@ -1,201 +0,0 @@ -% Kale Ewasiuk (kalekje@gmail.com) -% 2021-12-20 -% Copyright (C) 2021 Kale Ewasiuk -% -% Permission is hereby granted, free of charge, to any person obtaining a copy -% of this software and associated documentation files (the "Software"), to deal -% in the Software without restriction, including without limitation the rights -% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -% copies of the Software, and to permit persons to whom the Software is -% furnished to do so, subject to the following conditions: -% -% The above copyright notice and this permission notice shall be included in -% all copies or substantial portions of the Software. -% -% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -% ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -% TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -% PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -% SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR -% ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -% ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE -% OR OTHER DEALINGS IN THE SOFTWARE. - - -\documentclass[11pt,parskip=half]{scrartcl} -\setlength{\parindent}{0ex} -\newcommand{\llcmd}[1]{\leavevmode\llap{\texttt{\detokenize{#1}\ }}} -\newcommand{\cmd}[1]{\texttt{\detokenize{#1}}} -\newcommand{\qcmd}[1]{``\cmd{#1}''} -\RequirePackage{url} -\RequirePackage{xcolor} -\RequirePackage{showexpl} -\lstset{explpreset={justification=\raggedright,pos=r,wide=true}} -\setlength\ResultBoxRule{0mm} -\lstset{ - language=[LaTeX]TeX, - basicstyle=\ttfamily\small, - commentstyle=\ttfamily\small\color{gray}, - frame=none, - numbers=left, - numberstyle=\ttfamily\small\color{gray}, - prebreak=\raisebox{0ex}[0ex][0ex]{\color{gray}\ensuremath{\hookleftarrow}}, - extendedchars=true, - breaklines=true, - tabsize=4, -} -\addtokomafont{title}{\raggedright} -\addtokomafont{author}{\raggedright} -\addtokomafont{date}{\raggedright} -\author{Kale Ewasiuk (\url{kalekje@gmail.com})} -\RequirePackage[yyyymmdd]{datetime}\renewcommand{\dateseparator}{--} -\date{\today} - - -\usepackage{autopuncitems} -\setlist{nosep} - -\title{autopuncitems} - - -\begin{document} -\maketitle - -\section{Introduction} -This package provides the \cmd{autopunc} option in the -\cmd{enumitem} environemnts \cmd{itemize}, \cmd{enumerate}, and \cmd{description} -to automatically punctuate the items. -It uses lua pattern matching to modify the environment's contents. - -\section{Some commands} -\llcmd{\APomit}Used in an \cmd{\item} to signify that that item should not be automatically punctuated, and not be counted. Expands to nothing.\\ -\llcmd{\APpass}Used in an \cmd{\item} to signify that that item should not be automatically punctuated, and but still counted. Expands to nothing.\\ - -\begin{addmargin}[0.8in]{0in} -\llcmd{\setAPeach{}{}{}}Set the default, second last, and last punctuation point in that order.\\ -\llcmd{\setAPall{}}Set all punctuation points the same.\\ -\llcmd{\setAPdef{}}Set the default punctuation point. \cmd{;} by default.\\ -\llcmd{\setAPseclast{}}Set the second last punctuation point. \cmd{; and} by default.\\ -\llcmd{\setAPlast{}}Set the second last punctuation point. \cmd{.} by default.\\ - -\llcmd{\enableAPautopassnest}Automatically put an \cmd{\APpass} on items that introduce a nested list. Default behaviour.\\ -\llcmd{\disableAPautopassnest}Do not automatically put an \cmd{\APpass} on items that introduce a nested list.\\ - -\end{addmargin} - - -\section{Tutorial} -\subsection{Basic Use} - -\begin{LTXexample} -\begin{itemize}[autopunc] - \item one - \item two - \item three - \item four -\end{itemize} -\end{LTXexample} - - -\subsection{Demonstrating Pass} - -\begin{LTXexample} -\begin{itemize}[autopunc] - \item one - \item two - \item three \APpass - \item four -\end{itemize} -\end{LTXexample} - -\begin{LTXexample} -\begin{itemize}[autopunc] - \item one - \item two - \item three \APpass - \item four \APpass -\end{itemize} -\end{LTXexample} - - -\subsection{Demonstrating Omit} - -\begin{LTXexample} -\begin{itemize}[autopunc] - \item one - \item two - \item three \APomit - \item four -\end{itemize} -\end{LTXexample} - -\begin{LTXexample} -\begin{itemize}[autopunc] - \item one - \item two - \item three \APomit - \item four \APomit -\end{itemize} -\end{LTXexample} - -\subsection{Nested} -You must use \cmd{autopunc} on each nested list if you want that sub-list to be automatically punctuated. -Note that by default, the item introducing (before) a sub-list will not be automatically punctuated. - -\begin{LTXexample} -\begin{itemize}[autopunc] - \item one - \item two - \item three: - \begin{enumerate}[autopunc] - \item alpha: - \begin{description}[autopunc] - \item[hello] world - \end{description} - \item beta - \item delta - \end{enumerate} - \item four -\end{itemize} -\end{LTXexample} - - -\subsubsection{If you forget to use APpass} -If you disable auto-pass nested lists, and don't use \cmd{\APpass}, here is what happens. Notice the extra ``; and'' below hello world and beta. -\begin{LTXexample} -\disableAPautopassnest -\begin{itemize}[autopunc] - \item one - \item two - \item three - \begin{enumerate}[autopunc] - \item alpha - \begin{description}[autopunc] - \item[hello] world - \end{description} - \item beta - \end{enumerate} - \item four -\end{itemize} -\end{LTXexample} - -\begin{LTXexample} -\enableAPautopassnest -\begin{itemize}[autopunc] - \item one - \item two - \item three - \begin{enumerate} - \item alpha - \begin{description}[autopunc] - \item[hello] world - \end{description} - \item beta - \end{enumerate} - \item four -\end{itemize} -\end{LTXexample} - -\end{document} - diff --git a/macros/luatex/latex/autopuncitems/README.md b/macros/luatex/latex/autopuncitems/README.md new file mode 100644 index 0000000000..3cd4844b10 --- /dev/null +++ b/macros/luatex/latex/autopuncitems/README.md @@ -0,0 +1,28 @@ +# autopuncitems + +Automatically punctuate lists by passing the autopunc option to enumitem lists. + +# License + +Copyright (C) 2021 Kale Ewasiuk + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE +OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/macros/luatex/latex/autopuncitems/autopuncitems.lua b/macros/luatex/latex/autopuncitems/autopuncitems.lua new file mode 100644 index 0000000000..5e8e5b10c6 --- /dev/null +++ b/macros/luatex/latex/autopuncitems/autopuncitems.lua @@ -0,0 +1,106 @@ +--% Kale Ewasiuk (kalekje@gmail.com) +--% 2021-12-20 +--% Copyright (C) 2021 Kale Ewasiuk +--% +--% Permission is hereby granted, free of charge, to any person obtaining a copy +--% of this software and associated documentation files (the "Software"), to deal +--% in the Software without restriction, including without limitation the rights +--% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +--% copies of the Software, and to permit persons to whom the Software is +--% furnished to do so, subject to the following conditions: +--% +--% The above copyright notice and this permission notice shall be included in +--% all copies or substantial portions of the Software. +--% +--% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +--% ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +--% TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +--% PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +--% SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +--% ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +--% ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +--% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE +--% OR OTHER DEALINGS IN THE SOFTWARE. + + +local ap = {} -- module table + +function ap.rtrim(s) + return (s:gsub("^(.-)%s*$", "%1")) +end + +ap.punc = {} +ap.punc = {'.', '; and'} -- punctuation table, 1 is last val, 2 is 2nd last val +ap.punc[0] = ';' -- [0] is default punctuation +ap.total = 0 -- total num of items (int) +ap.curr = 0 -- current item we're on (int) +ap.itemp = '\9' -- temporary item, item which WILL be affected by autopunc +ap.item = '\\item' -- item +ap.omit = '\\APomit' -- flag for hiding an item from punc and count, acts as if item is not there +ap.pass = '\\APpass' -- flag for passing item from punc, but still considered in count +ap.code = 0 -- code for skipping punc if > 0, keep in count if == 1, omit from count if == 2 + +ap.autopassnested = true + +function ap.start(s) + ap.curr = 0 + _, ap.total = s:gsub(ap.itemp, '') + local _, omit = s:gsub(ap.omit, '') + ap.total = ap.total - omit +end + +function ap.setcode(s) + local _, code1 = s:gsub(ap.pass, '', 1) + local _, code2 = s:gsub(ap.omit, '', 1) + ap.code = code1 + 2*code2 +end + +function ap.addcount(s) + ap.setcode(s) + if ap.code < 2 then -- if not omitting, we still keep counter going + ap.curr = ap.curr + 1 -- increment counter + end +end + +function ap.getdelim() + local d = '' + if ap.code == 0 then -- d limiter -- if not passing look at punctuation table for delimiter + d = ap.punc[ap.total-ap.curr+1] or ap.punc[0] + end + return d +end + +function ap.protectnest(s) + local x = '' + if ap.autopassnested then x = ap.pass..'{}' end + s = s:gsub("\0", "\0", 0) -- dummy replacement to make code easier + :gsub("\\begin%s*{itemize}", x.."\1%0") -- pad \1 and \2 in inner envirnments + :gsub("\\end%s*{itemize}", "%0\2") + :gsub("\\begin%s*{enumerate}", x.."\1%0") + :gsub("\\end%s*{enumerate}", "%0\2") + :gsub("\\begin%s*{description}", x.."\1%0") + :gsub("\\end%s*{description}", "%0\2") + :gsub("%b\1\2", "\0%0\0") -- use bracket to place \0 (on OUTER) nested lists only + :gsub("(%Z*)%z?(%Z*)%z?", -- only affect matches outside list + function(a, b) return a:gsub(ap.item, ap.itemp)..b:gsub("[\1\2]", "") end) + return s +end + + +function ap.go(s) + s = ap.protectnest(s) + ap.start(s) -- start counters + --texio.write_nl('yooo...'..s) + s = s:gsub(ap.itemp, '\0\0'):gsub('\0', '', 1) -- make all items \0\0 then change first item to one \0 + s = s:gsub('(%z)(%Z*)(%z?)', -- find betwen \0 .. \0 + function(it, s, _it) -- discarding duplicate item '_it' that was made in first gsub + ap.addcount(s) -- add count, helps determine delimiter + return ap.rtrim(it..s)..ap.getdelim()..' ' + end + ) + s = s:gsub('\0', ap.itemp) -- replace items + s = s:gsub(ap.itemp, ap.item) -- replace items + return s +end + +return ap \ No newline at end of file diff --git a/macros/luatex/latex/autopuncitems/autopuncitems.pdf b/macros/luatex/latex/autopuncitems/autopuncitems.pdf new file mode 100644 index 0000000000..fd743e4d99 Binary files /dev/null and b/macros/luatex/latex/autopuncitems/autopuncitems.pdf differ diff --git a/macros/luatex/latex/autopuncitems/autopuncitems.sty b/macros/luatex/latex/autopuncitems/autopuncitems.sty new file mode 100644 index 0000000000..8045fa4737 --- /dev/null +++ b/macros/luatex/latex/autopuncitems/autopuncitems.sty @@ -0,0 +1,56 @@ +% Kale Ewasiuk (kalekje@gmail.com) +% 2021-12-20 +% Copyright (C) 2021 Kale Ewasiuk +% +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% +% The above copyright notice and this permission notice shall be included in +% all copies or substantial portions of the Software. +% +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +% ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +% TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +% PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +% SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +% ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +% ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE +% OR OTHER DEALINGS IN THE SOFTWARE. + + +\ProvidesPackage{autopuncitems}[2021-12-20] + +\RequirePackage{enumitem} +\RequirePackage{luacode} + +\luadirect{autopuncitems = require'autopuncitems'} + +\newcommand{\APomit}{} % blank flag used in '\item' to hide it from counting and auto +\newcommand{\APpass}{} % blank flag used in '\item', autopunc is skipped, but count is still + +\newcommand{\disableAPautopassnest}{\luadirect{autopuncitems.autopassnested = false}} +\newcommand{\enableAPautopassnest}{\luadirect{autopuncitems.autopassnested = true}} + +\NewDocumentCommand{\setAPeach}{m m m}{\setAPdef{#1}\setAPseclast{#2}\setAPlast{#3}} % set each one, default, second last, last +\NewDocumentCommand{\setAPall}{m}{\setAPdef{#1}\setAPseclast{#1}\setAPlast{#1}} % set all the same +\NewDocumentCommand{\setAPdef}{m}{\luadirect{autopuncitems.punc[0] = \luastring{#1}}} % default punc value +\NewDocumentCommand{\setAPlast}{m}{\luadirect{autopuncitems.punc[1] = \luastring{#1}}} % second last punc value +\NewDocumentCommand{\setAPseclast}{m}{\luadirect{autopuncitems.punc[2] = \luastring{#1}}} % final punc value + +\NewDocumentEnvironment{AutoPuncItemize}{ +b }{ +% \luadirect{texio.write_nl('auto >>>'..autopuncitems.go(\luastringN{#1}))} + \luadirect{tex.print(autopuncitems.go(\luastringN{#1}))} +}{} + +\SetEnumitemKey{autopunc}{ + first*=\expandafter\AutoPuncItemize, + after=\endAutoPuncItemize, +} + + + diff --git a/macros/luatex/latex/autopuncitems/autopuncitems.tex b/macros/luatex/latex/autopuncitems/autopuncitems.tex new file mode 100644 index 0000000000..fd829b81e6 --- /dev/null +++ b/macros/luatex/latex/autopuncitems/autopuncitems.tex @@ -0,0 +1,201 @@ +% Kale Ewasiuk (kalekje@gmail.com) +% 2021-12-20 +% Copyright (C) 2021 Kale Ewasiuk +% +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% +% The above copyright notice and this permission notice shall be included in +% all copies or substantial portions of the Software. +% +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +% ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +% TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +% PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +% SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +% ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +% ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE +% OR OTHER DEALINGS IN THE SOFTWARE. + + +\documentclass[11pt,parskip=half]{scrartcl} +\setlength{\parindent}{0ex} +\newcommand{\llcmd}[1]{\leavevmode\llap{\texttt{\detokenize{#1}\ }}} +\newcommand{\cmd}[1]{\texttt{\detokenize{#1}}} +\newcommand{\qcmd}[1]{``\cmd{#1}''} +\RequirePackage{url} +\RequirePackage{xcolor} +\RequirePackage{showexpl} +\lstset{explpreset={justification=\raggedright,pos=r,wide=true}} +\setlength\ResultBoxRule{0mm} +\lstset{ + language=[LaTeX]TeX, + basicstyle=\ttfamily\small, + commentstyle=\ttfamily\small\color{gray}, + frame=none, + numbers=left, + numberstyle=\ttfamily\small\color{gray}, + prebreak=\raisebox{0ex}[0ex][0ex]{\color{gray}\ensuremath{\hookleftarrow}}, + extendedchars=true, + breaklines=true, + tabsize=4, +} +\addtokomafont{title}{\raggedright} +\addtokomafont{author}{\raggedright} +\addtokomafont{date}{\raggedright} +\author{Kale Ewasiuk (\url{kalekje@gmail.com})} +\RequirePackage[yyyymmdd]{datetime}\renewcommand{\dateseparator}{--} +\date{\today} + + +\usepackage{autopuncitems} +\setlist{nosep} + +\title{autopuncitems} + + +\begin{document} +\maketitle + +\section{Introduction} +This package provides the \cmd{autopunc} option in the +\cmd{enumitem} environemnts \cmd{itemize}, \cmd{enumerate}, and \cmd{description} +to automatically punctuate the items. +It uses lua pattern matching to modify the environment's contents. + +\section{Some commands} +\llcmd{\APomit}Used in an \cmd{\item} to signify that that item should not be automatically punctuated, and not be counted. Expands to nothing.\\ +\llcmd{\APpass}Used in an \cmd{\item} to signify that that item should not be automatically punctuated, and but still counted. Expands to nothing.\\ + +\begin{addmargin}[0.8in]{0in} +\llcmd{\setAPeach{}{}{}}Set the default, second last, and last punctuation point in that order.\\ +\llcmd{\setAPall{}}Set all punctuation points the same.\\ +\llcmd{\setAPdef{}}Set the default punctuation point. \cmd{;} by default.\\ +\llcmd{\setAPseclast{}}Set the second last punctuation point. \cmd{; and} by default.\\ +\llcmd{\setAPlast{}}Set the second last punctuation point. \cmd{.} by default.\\ + +\llcmd{\enableAPautopassnest}Automatically put an \cmd{\APpass} on items that introduce a nested list. Default behaviour.\\ +\llcmd{\disableAPautopassnest}Do not automatically put an \cmd{\APpass} on items that introduce a nested list.\\ + +\end{addmargin} + + +\section{Tutorial} +\subsection{Basic Use} + +\begin{LTXexample} +\begin{itemize}[autopunc] + \item one + \item two + \item three + \item four +\end{itemize} +\end{LTXexample} + + +\subsection{Demonstrating Pass} + +\begin{LTXexample} +\begin{itemize}[autopunc] + \item one + \item two + \item three \APpass + \item four +\end{itemize} +\end{LTXexample} + +\begin{LTXexample} +\begin{itemize}[autopunc] + \item one + \item two + \item three \APpass + \item four \APpass +\end{itemize} +\end{LTXexample} + + +\subsection{Demonstrating Omit} + +\begin{LTXexample} +\begin{itemize}[autopunc] + \item one + \item two + \item three \APomit + \item four +\end{itemize} +\end{LTXexample} + +\begin{LTXexample} +\begin{itemize}[autopunc] + \item one + \item two + \item three \APomit + \item four \APomit +\end{itemize} +\end{LTXexample} + +\subsection{Nested} +You must use \cmd{autopunc} on each nested list if you want that sub-list to be automatically punctuated. +Note that by default, the item introducing (before) a sub-list will not be automatically punctuated. + +\begin{LTXexample} +\begin{itemize}[autopunc] + \item one + \item two + \item three: + \begin{enumerate}[autopunc] + \item alpha: + \begin{description}[autopunc] + \item[hello] world + \end{description} + \item beta + \item delta + \end{enumerate} + \item four +\end{itemize} +\end{LTXexample} + + +\subsubsection{If you forget to use APpass} +If you disable auto-pass nested lists, and don't use \cmd{\APpass}, here is what happens. Notice the extra ``; and'' below hello world and beta. +\begin{LTXexample} +\disableAPautopassnest +\begin{itemize}[autopunc] + \item one + \item two + \item three + \begin{enumerate}[autopunc] + \item alpha + \begin{description}[autopunc] + \item[hello] world + \end{description} + \item beta + \end{enumerate} + \item four +\end{itemize} +\end{LTXexample} + +\begin{LTXexample} +\enableAPautopassnest +\begin{itemize}[autopunc] + \item one + \item two + \item three + \begin{enumerate} + \item alpha + \begin{description}[autopunc] + \item[hello] world + \end{description} + \item beta + \end{enumerate} + \item four +\end{itemize} +\end{LTXexample} + +\end{document} + -- cgit v1.2.3