diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/algxpar/algxpar.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/algxpar/algxpar.sty | 511 |
1 files changed, 312 insertions, 199 deletions
diff --git a/Master/texmf-dist/tex/latex/algxpar/algxpar.sty b/Master/texmf-dist/tex/latex/algxpar/algxpar.sty index 3da15d94157..e5ffa55b566 100644 --- a/Master/texmf-dist/tex/latex/algxpar/algxpar.sty +++ b/Master/texmf-dist/tex/latex/algxpar/algxpar.sty @@ -2,12 +2,14 @@ %! Author: Jander Moreira %! Email = moreira.jander@gmail.com +%! suppress = FileNotFound + \NeedsTeXFormat{LaTeX2e}[2005/12/01] -\ProvidesPackage{algxpar}[2023/06/26 v0.99 Algorithms with multi-line/paragraph support and some enhancements] +\ProvidesPackage{algxpar}[2024/10/23 v0.99.2 Algorithms with multi-line/paragraph support and some enhancements] %% Documentation -\NewDocumentCommand{\AlgVersion}{}{0.99} -\NewDocumentCommand{\AlgDate}{}{2023/06/26} +\NewDocumentCommand{\AlgVersion}{}{0.99.2} +\NewDocumentCommand{\AlgDate}{}{2024/10/23} %% Required packages @@ -20,7 +22,10 @@ \RequirePackage{amssymb} \RequirePackage{pgfmath} \RequirePackage{varwidth} -\RequirePackage{ifthen} +% \RequirePackage{ifthen} +\RequirePackage{tikz} +\usetikzlibrary{calc, arrows} +\RequirePackage{etoolbox} % \RequirePackage{listings} % to load verbatim with tabs % \RequirePackage{tcolorbox} % to save verbatim @@ -90,17 +95,26 @@ } -% RenewFullyExpandedDocumentCommand: fully expands argument before +% axp@RenewFullyExpandedDocumentCommand: fully expands argument before % renewing document command % #1: macro % #2: value -\NewDocumentCommand{\RenewFullyExpandedDocumentCommand} { m m }{ +\NewDocumentCommand{\axp@RenewFullyExpandedDocumentCommand} { m m }{ \exp_args:NNnV \RenewDocumentCommand #1 { } { #2 } } \ExplSyntaxOff +%% Settings +\newif\ifaxp@NoEnd\axp@NoEndfalse % whether line with 'end' is used or not +\newif\ifaxp@IsStatement\axp@IsStatementfalse % set in \Statep +\newif\ifaxp@ShowBoxes\axp@ShowBoxesfalse % show parboxes for debugging +\newif\ifaxp@LineBalanceAuto % true for 'auto'; false for 'fixed' +\newif\ifaxp@IndentLines\axp@IndentLinesfalse % draw lines in blocks + + \NewDocumentCommand{\axp@DisableEnds}{}{% + \axp@NoEndtrue% \RenewDocumentCommand{\ALG@noend}{}{t}% \algtext*{EndWhile}% \algtext*{EndFor}% @@ -114,6 +128,7 @@ } \NewDocumentCommand{\axp@EnableEnds}{}{% + \axp@NoEndfalse% \RenewDocumentCommand{\ALG@noend}{}{f}% \algrenewtext{EndWhile}{\Keyword{endwhile}}% \algrenewtext{EndFor}{\Keyword{endfor}}% @@ -127,19 +142,12 @@ } \axp@EnableEnds % update end-line texts -%% Settings -\newif\ifaxp@NoEnd\axp@NoEndfalse % whether line with 'end' is used or not -\newif\ifaxp@IsStatement\axp@IsStatementfalse % set in \Statep -\newif\ifaxp@ShowBoxes\axp@ShowBoxesfalse % show parboxes for debugging -\newif\ifaxp@LineBalanceAuto % true for 'auto'; false for 'fixed' - %% General options -%! formatter = off \pgfkeys{ /algxpar/options/.cd, - % language +% language language/.store in = \axp@Language, - % styles +% styles text font/.store in = \axp@TextFont, text color/.store in = \axp@TextColor, text style/.store in = \axp@TextStyle, @@ -152,24 +160,27 @@ constant color/.store in = \axp@ConstantColor, module font/.store in = \axp@ModuleFont, module color/.store in = \axp@ModuleColor, - % +% comment symbol/.store in = \axp@CommentSymbol, comment symbol right/.store in = \axp@CommentSymbolRight, comment separator width/.store in = \axp@CommentSeparatorWidth, - % +% noend/.code = {\axp@DisableEnds}, no end/.code = {\axp@DisableEnds}, end/.code = {\axp@EnableEnds}, - % - % keywords/.code = {\pgfkeysalso{/algxpar/languages/.cd, \trim@spaces{#1}}}, +% +% keywords/.code = {\pgfkeysalso{/algxpar/languages/.cd, \trim@spaces{#1}}}, keywords/.code = {\axp@LanguageSet{#1}}, - % +% algorithmic indent/.store in = \algorithmicindent, statement indent/.store in = \axp@StatementIndent, parameter indent/.store in = \axp@ParameterIndent, - % +% + indent lines/.is if = axp@IndentLines, + line style/.code = {\tikzset{line style/.style = {#1}}}, +% show boxes/.is if = axp@ShowBoxes, - % +% comment width/.code = {% \axp@LineBalanceAutotrue% \ifthenelse{\equal{auto}{#1}}{% @@ -183,8 +194,9 @@ }% }% }, +% +% style/.style = {\pgfkeysalso{/algxpar/styles/#}}, } -%! formatter = on \NewDocumentCommand{\AlgSet}{ > { \TrimSpaces } m }{% \pgfkeys{% @@ -194,6 +206,14 @@ } +% %% Styles +% \NewDocumentCommand{\AlgStyle}{ > { \TrimSpaces } m > { \TrimSpaces m }{% +% \pgfkeys{ +% /algxpar/style/.cd, +% #1/.style = {#2} +% } +% } + %% Languages and translations \pgfkeys{ /algxpar/languages/.cd, @@ -201,11 +221,11 @@ } \NewDocumentCommand{\AlgLanguageSet}{ > { \TrimSpaces } m > { \TrimSpaces } m }{% - \AlgSet{language = #1} + \AlgSet{language = #1}% \pgfkeys{ /algxpar/languages/.cd, #2 - } + }% } \NewDocumentCommand{\axp@LanguageSet}{ > { \TrimSpaces } m }{% \pgfkeys{ @@ -238,6 +258,8 @@ algorithmic indent = 1.5em, statement indent = 1em, parameter indent = 0pt, + indent lines = false, + line style = {lightgray, thick}, show boxes = false, comment width = auto, } @@ -249,9 +271,8 @@ language/.store in = \axp@Language, noend/.is if = axp@NoEnd, .unknown/.code = { - %! suppress = FileNotFound + \axp@RenewFullyExpandedDocumentCommand{\axp@Language}{\pgfkeyscurrentname} \input{algxpar-\pgfkeyscurrentname.kw} - \RenewFullyExpandedDocumentCommand{\axp@Language}{\pgfkeyscurrentname} } } \pgfkeys{ @@ -295,16 +316,74 @@ % #3: text after token \newlength{\axp@TokenWidth} \NewDocumentCommand{\axp@MakeSingleToken}{ m m m }{% - \settowidth{\axp@TokenWidth}{#2}% - \ifdim\axp@TokenWidth>0pt\relax#1\fi% + \axp@SetToWidth{\axp@TokenWidth}{#2}% + \ifdimcomp{\axp@TokenWidth}{>}{0pt}{#1}{}% #2% - \ifdim\axp@TokenWidth>0pt\relax#3\fi% + \ifdimcomp{\axp@TokenWidth}{>}{0pt}{#3}{}% } \newif\ifaxp@NoCommentPresent \newlength{\axp@TextWidth} \newlength{\axp@CommentWidth} +%%%%%%%% LINES + +\NewDocumentCommand{\axp@MarkLineBegin}{}{% + \ifbool{axp@IndentLines}{% + \stepcounter{axp@BlockLevelCounter}% + \tikz[remember picture] \coordinate (axp-block-start-\theaxp@BlockLevelCounter) (0, 0);% + % \tikz[remember picture, overlay] \draw[<-] (axp-block-start-\theaxp@BlockLevelCounter) -- ++ (-4em, 0.5ex) node[anchor = east] {B:\theaxp@BlockLevelCounter};% + }{}% +}% + +\NewDocumentCommand{\axp@MarkLineEndShort}{}{% + \ifbool{axp@IndentLines}{% + \tikz[remember picture] \coordinate (axp-block-end-\theaxp@BlockLevelCounter) (0, 0);% + \begin{tikzpicture}[remember picture, overlay] + \draw[line style] + ($ (axp-block-start-\theaxp@BlockLevelCounter) + (0.3ex, -1ex) $) + -- + ($ (axp-block-end-\theaxp@BlockLevelCounter) + (0.3ex, 1em) $); + \end{tikzpicture}% + \addtocounter{axp@BlockLevelCounter}{-1}% + }% +} + +\NewDocumentCommand{\axp@MarkLineEndCont}{}{% + \ifbool{axp@IndentLines}{% + \tikz[remember picture] \coordinate (axp-block-end-\theaxp@BlockLevelCounter) (0, 0);% + \begin{tikzpicture}[remember picture, overlay] + \draw[line style] + ($ (axp-block-start-\theaxp@BlockLevelCounter) + (0.3ex, -1ex) $) + -- + ($ (axp-block-end-\theaxp@BlockLevelCounter) + (0.3ex, 1em) $); + \end{tikzpicture}% + \addtocounter{axp@BlockLevelCounter}{-1}% + }% +} + +\NewDocumentCommand{\axp@MarkLineEndFinal}{}{% + \ifbool{axp@IndentLines}{% + \tikz[remember picture] \coordinate (axp-block-end-\theaxp@BlockLevelCounter) (0, 0);% + \begin{tikzpicture}[remember picture, overlay] + \draw[line style] + ($ (axp-block-start-\theaxp@BlockLevelCounter) + (0.3ex, -1ex) $) + -- + ($ (axp-block-end-\theaxp@BlockLevelCounter) + (0.3ex, 0) $) + |- ++ (1ex, 0); + \end{tikzpicture}% + \addtocounter{axp@BlockLevelCounter}{-1}% + }% +} + +% % *********************************************** +% % For debugging! +\NewDocumentCommand{\msg}{ m O{-1} }{% + \begin{tikzpicture}[overlay] + \draw[black!30] (0, 0.1) -- (#2, 0.3) node[fill=black!5, anchor=east] {\scriptsize\color{darkgray}#1}; + \end{tikzpicture}% +} + % axp@CalculateDimensions: evaluate space needed for text and comments % #1: nesting ajustment (1 when openning a block; 0 when closing) @@ -319,50 +398,62 @@ \newlength{\axp@CurrentLineWidth} \newlength{\axp@RemainingWidth} \NewDocumentCommand{\axp@CalculateDimensions}{ m m m }{% + \booltrue{axp@NoCommentPresent}% \axp@SetToWidth{\axp@FullTextWidth}{\axp@TextFont#2}% text \axp@SetToWidth{\axp@FullCommentWidth}{\axp@CommentFont#3}% comment - %! formatter = off - \ifdim\axp@FullCommentWidth=0pt\relax% - % No comments present - \axp@NoCommentPresenttrue% + \ifdimcomp{\axp@FullCommentWidth}{=}{0pt}{% + % No comments present + % \msg{no comment!}% + \global\booltrue{axp@NoCommentPresent}% + % \ifbool{axp@LineBalanceAuto}{% \setlength{\axp@TextWidth}{ \dimexpr \linewidth - \axp@CurrentTokenWidth - (\algorithmicindent)*(\theALG@nested - #1) }% - \else - % Yep, we have a comment - \axp@NoCommentPresentfalse% - \settowidth{\axp@CommentSymbolWidth}{\hspace{\axp@CommentSeparatorWidth}\CommentSymbol~}% - \setlength{\axp@CurrentLineWidth}{ - \dimexpr \linewidth - \axp@CurrentTokenWidth - (\algorithmicindent)*(\theALG@nested - #1) + \ifdimcomp{\axp@FullTextWidth}{<}{\axp@TextWidth}{% + \axp@TextWidth\axp@FullTextWidth% makes the parbox fit the actual text width + }{}% + % }{} + }{% + % Yep, we have a comment in this line + % \msg{got a comment!}% + \global\boolfalse{axp@NoCommentPresent}% + \axp@SetToWidth{\axp@CommentSymbolWidth}{\hspace{\axp@CommentSeparatorWidth}\CommentSymbol~}% + \deflength{\axp@CurrentLineWidth}{ + \linewidth - \axp@CurrentTokenWidth - (\algorithmicindent)*(\theALG@nested - #1) }% - \ifaxp@LineBalanceAuto% - % 'auto': decide here how to balance text and comment widths + \ifbool{axp@LineBalanceAuto}{% + % 'auto': decide here how to balance text and comment widths \setlength{\axp@RemainingWidth}{ \dimexpr \axp@CurrentLineWidth - \axp@FullTextWidth - \axp@FullCommentWidth - \axp@CommentSymbolWidth }% - \ifdim\axp@RemainingWidth>0pt\relax% - % Both text and comment fit the line + \null% I don't understand the difference this null makes here! + % \msg{\the\axp@RemainingWidth}% + \ifdimcomp{\axp@RemainingWidth}{>}{0pt}{% + % Both text and comment fit the line \axp@TextWidth\axp@FullTextWidth% \axp@CommentWidth\axp@FullCommentWidth% - \else% - % Text/comment will go multi-line + % \msg{fits \the\axp@RemainingWidth}% + }{% + % Text/comment will go multi-line + % \msg{not fit \the\axp@RemainingWidth}% \pgfmathsetmacro{\axp@CurrentRatio}{ int(round(\axp@FullTextWidth/(\axp@FullTextWidth + \axp@FullCommentWidth) * 100)) }% - \ifnum\axp@CurrentRatio<25\relax% never less than 0.25 + \ifnumcomp{\axp@CurrentRatio}{<}{25}{% never less than 0.25 \edef\axp@CurrentRatio{25}% - \fi% - \ifnum\axp@CurrentRatio>75\relax% never more than 0.75 - \edef\axp@CurrentRatio{75}% - \fi% + }{% + \ifnumcomp{\axp@CurrentRatio}{>}{75}{% never more than 0.75 + \edef\axp@CurrentRatio{75}% + }{}% + }% \pgfmathparse{ - \axp@CurrentRatio/100 * \axp@CurrentLineWidth - \axp@CommentSymbolWidth/2 + (100 - \axp@CurrentRatio)/100 * \axp@CurrentLineWidth - \axp@CommentSymbolWidth }% - \setlength{\axp@TextWidth}{\pgfmathresult pt}% - \pgfmathparse{\axp@CurrentLineWidth - \axp@TextWidth - \axp@CommentSymbolWidth}% \setlength{\axp@CommentWidth}{\pgfmathresult pt}% + \pgfmathparse{\axp@CurrentLineWidth - \axp@CommentWidth - \axp@CommentSymbolWidth}% + \setlength{\axp@TextWidth}{\pgfmathresult pt}% % fine tunning the widths - \settowidth{\axp@CommentWidth}{% + \axp@SetToWidth{\axp@CommentWidth}{% \begin{varwidth}[t]{\axp@CommentWidth}% \axp@CommentStyle% \textcolor{\axp@CommentColor}{\axp@CommentFont#3}\strut% @@ -370,44 +461,51 @@ }% \pgfmathparse{\axp@CurrentLineWidth - \axp@CommentWidth - \axp@CommentSymbolWidth}% \setlength{\axp@TextWidth}{\pgfmathresult pt}% - \fi% - \else% - % 'fixed': limit comment width - % todo: think about using \axp@CurrentLineWidth instead of \linewidth + % \msg{\the\axp@TextWidth}% + }% + }{% + % 'fixed': limit comment width + % todo: think about using \axp@CurrentLineWidth instead of \linewidth \setlength{\axp@CommentWidth}{\axp@CommentFixedWidth}% \setlength{\axp@TextWidth}{ \dimexpr \axp@CurrentLineWidth - \axp@CommentWidth - \axp@CommentSymbolWidth }% - \fi% + }% \setlength{\axp@RemainingWidth}{ \dimexpr \linewidth - \axp@CurrentTokenWidth - (\algorithmicindent)*(\theALG@nested - #1) - \axp@CommentWidth - \axp@CommentSymbolWidth }% - \fi% - % - \ifdim\axp@FullTextWidth<\axp@TextWidth\relax% - \axp@TextWidth\axp@FullTextWidth% makes the parbox fit the actual text width - \fi% - %! formatter = on + }% } +\newcounter{cont} +\newif\ifaxp@CloseBlock % axp@MakeCommand: builds the command (see axp@DefineCommand) % #1 (star): star = end block; no star = begin block \NewDocumentCommand{\axp@MakeCommand}{ s }{% - \axp@DoCommand{% ajustment for opening/closing blocks - \IfBooleanTF{#1}{0}{1}% - }{% command or module+name - \axp@MakeSingleToken{}{\axp@CommandKeyword}{\ifaxp@IsModule(\else\ \fi}% - }{% text or module arguments - \axp@CommandText\ifaxp@IsModule)\fi% - }{% command complement - \axp@MakeSingleToken{ }{\axp@CommandComplementKeyword}{}% - }{% comment - \axp@CommentText% - }{% options - \axp@CommandOptions% - }% +\IfBooleanTF{#1}{% + \axp@MarkLineEndShort% +}{% + \ifaxp@CloseBlock% + \axp@MarkLineEndCont% + \axp@CloseBlockfalse% + \fi% + \axp@MarkLineBegin% +}% +\axp@DoCommand{% ajustment for opening/closing blocks + \IfBooleanTF{#1}{0}{1}% +}{% command or module+name +\axp@MakeSingleToken{}{\axp@CommandKeyword}{\ifaxp@IsModule(\else\ \fi}% +}{% text or module arguments +\axp@CommandText\ifaxp@IsModule)\fi% +}{% command complement +\axp@MakeSingleToken{ }{\axp@CommandComplementKeyword}{}% +}{% comment +\axp@CommentText% +}{% options +\axp@CommandOptions% +}% } %! formatter = off @@ -426,7 +524,6 @@ \usebox{\axp@SaveBox}% \fi% } -%! formatter = on % axp@DoCommand: builds the command (see axp@DefineCommand) @@ -438,16 +535,15 @@ % #6: options \newlength{\axp@CurrentTokenWidth} \NewDocumentCommand{\axp@DoCommand}{ m m m m m m }{% - \AlgSet{#6}% - % Dimensions - \settowidth{\axp@CurrentTokenWidth}{#2}% - \axp@CalculateDimensions{#1}{{\axp@TextStyle\axp@TextFont#3}#4}{#5}% - % - % Making the line: body - #2% - %! formatter = off +\AlgSet{#6}% +% Dimensions +\axp@SetToWidth{\axp@CurrentTokenWidth}{#2}% +\axp@CalculateDimensions{#1}{{\axp@TextStyle\axp@TextFont#3}#4}{#5}% +% +% Making the line: body +#2% \begin{axp@FBox}% - \ifaxp@IsModule\hspace{\axp@ParameterIndent}\fi% + \ifbool{axp@IsModule}{\hspace{\axp@ParameterIndent}}{}% \parbox[t]{\axp@TextWidth}{% \ifaxp@IsStatement% \setlength{\hangindent}{\axp@StatementIndent}% @@ -457,23 +553,22 @@ }% \end{axp@FBox}% % Making the line: comment - \ifaxp@NoCommentPresent\else% + \ifbool{axp@NoCommentPresent}{}{% \hspace{\axp@CommentSeparatorWidth}\hfill\CommentSymbol~% \begin{axp@FBox}% - \ifaxp@LineBalanceAuto + \ifbool{axp@LineBalanceAuto}{% \begin{varwidth}[t]{\axp@CommentWidth}% \axp@CommentStyle% \textcolor{\axp@CommentColor}{\axp@CommentFont#5}\strut% \end{varwidth}% - \else + }{% \parbox[t]{\axp@CommentWidth}{% \axp@CommentStyle% - \textcolor{\axp@CommentColor}{\axp@CommentFont{#5}}\strut% + \textcolor{\axp@CommentColor}{\axp@CommentFont#5}\strut% }% - \fi% + }% \end{axp@FBox}% - \fi% - %! formatter = on + }% } @@ -485,12 +580,14 @@ \NewDocumentCommand{\Break}{}{\Keyword{break}} \RenewDocumentCommand{\Return}{}{\axp@MakeSingleToken{}{\Keyword{return}}{ }} +\NewDocumentCommand{\ByRef}{}{\Constant{byref}} +\NewDocumentCommand{\ByValue}{}{\Constant{byvalue}} \NewDocumentCommand{\True}{}{\Constant{true}} \NewDocumentCommand{\False}{}{\Constant{false}} \NewDocumentCommand{\Nil}{}{\Constant{nil}} -\newcommand{\Id}[1]{\ensuremath{\textit{\rmfamily#1}}} +\newcommand{\Id}[1]{\ensuremath{\emph{\rmfamily#1}}} % \newcommand{\TextString}[1]{\textrm{\normalfont``{\ttfamily\mbox{#1}}''}} % \algnewcommand{\VisibleSpace}{\textrm{\color{black!70}\textvisiblespace}} @@ -503,35 +600,39 @@ % Read, write \NewDocumentCommand{\Set}{ m m }{% - \PackageWarning{alxpar}{The macro \string\Set\ is no longer supported.}% - \Id{#1} \gets #2% +\PackageWarning{alxpar}{The macro \string\Set\ is no longer supported.}% +\Id{#1} \gets #2% } \NewDocumentCommand{\Read}{}{\Keyword{read} } \NewDocumentCommand{\Write}{}{\Keyword{write} } % %% Comments \algnewcommand{\CommentIn}[1]{% - \begin{axp@FBox} - \textcolor{\axp@CommentColor}{\CommentSymbol~\axp@CommentFont#1~\CommentSymbolRight}% - \end{axp@FBox}% +\begin{axp@FBox} +\textcolor{\axp@CommentColor}{\CommentSymbol~\axp@CommentFont#1~\CommentSymbolRight}% +\end{axp@FBox}% } \NewDocumentCommand{\Commentl}{ m D<>{} }{% - \begingroup% - \AlgSet{#2}% - \textcolor{\axp@CommentColor}{\CommentSymbol~\axp@CommentFont#1\strut}% - \endgroup% +\begingroup% +\AlgSet{#2}% +\textcolor{\axp@CommentColor}{\CommentSymbol~\axp@CommentFont#1\strut}% +\endgroup% } \RenewDocumentCommand{\Comment}{ m D<>{} }{% - \hfill\Commentl{#1}<#2>% +\hfill\Commentl{#1}<#2>% } \newlength{\axp@CurrentIndent} -\NewDocumentCommand{\axp@BeginGroup}{}{\begingroup} +\newcounter{axp@BlockCounter} +\newcounter{axp@BlockLevelCounter} +\NewDocumentCommand{\axp@BeginGroup}{}{% +\begingroup% +} \NewDocumentCommand{\axp@EndGroup}{}{% - \global\edef\axp@SaveIndent{\the\ALG@tlm}% - \endgroup% - \setlength{\ALG@tlm}{\axp@SaveIndent}% +\global\edef\axp@SaveIndent{\the\ALG@tlm}% +\endgroup% +\setlength{\ALG@tlm}{\axp@SaveIndent}% } @@ -541,12 +642,12 @@ % #3: comments % #4: options \NewDocumentCommand{\Statep}{ O{} +m O{} D<>{} }{% - \axp@IsStatementtrue% - \State\axp@DoCommand{1}{}{#2}{}{#1#3}{#4}% - \axp@IsStatementfalse% +\axp@IsStatementtrue% +\State\axp@DoCommand{1}{}{#2}{}{#1#3}{#4}% +\axp@IsStatementfalse% } \RenewDocumentCommand{\Statex}{}{% - \item[]\strut% +\item[]\strut% } @@ -557,16 +658,17 @@ % #3: comment % #4: options \RenewDocumentCommand{\While}{ O{} m O{} D<>{} }{% - \axp@BeginGroup - \axp@DefineCommand{\Keyword{while}}{#2}{\Keyword{do}}{#1#3}{#4}% - \ALG@makeentity{While}% +\axp@BeginGroup% +\axp@DefineCommand{\Keyword{while}}{#2}{\Keyword{do}}{#1#3}{#4}% +\ALG@makeentity{While}% } % #1: comment % #2: options \RenewDocumentCommand{\EndWhile}{ O{} D<>{} }{% - \axp@DefineCommand{\Keyword{endwhile}}{}{}{#1}{#2}% - \ALG@makeentity{EndWhile}% - \axp@EndGroup +\axp@DefineCommand{\Keyword{endwhile}}{}{}{#1}{#2}% +\ALG@makeentity{EndWhile}% +\ifaxp@NoEnd\axp@MarkLineEndFinal\fi% +\axp@EndGroup% } @@ -575,18 +677,19 @@ % #1: comments % #2: options \RenewDocumentCommand{\Repeat}{ O{} D<>{} }{% - \axp@BeginGroup - \axp@DefineCommand{\Keyword{repeat}}{}{}{#1}{#2}% - \ALG@makeentity{Repeat}% +\axp@BeginGroup% +\axp@DefineCommand{\Keyword{repeat}}{}{}{#1}{#2}% +\ALG@makeentity{Repeat}% } % #1: old style comment % #2: text % #3: comment % #4: options \RenewDocumentCommand{\Until}{ O{} m O{} D<>{} }{% - \axp@DefineCommand{\Keyword{until}}{#2}{}{#1#3}{#4}% - \ALG@makeentity{Until}% - \axp@EndGroup +\axp@DefineCommand{\Keyword{until}}{#2}{}{#1#3}{#4}% +\ALG@makeentity{Until}% +\ifaxp@NoEnd\axp@MarkLineEndFinal\fi% +\axp@EndGroup% } %% Loop @@ -594,16 +697,17 @@ % #1: comment % #2: options \RenewDocumentCommand{\Loop}{ O{} D<>{} }{% - \axp@BeginGroup - \axp@DefineCommand{\Keyword{loop}}{}{}{#1}{#2}% - \ALG@makeentity{Loop}% +\axp@BeginGroup% +\axp@DefineCommand{\Keyword{loop}}{}{}{#1}{#2}% +\ALG@makeentity{Loop}% } % #1: comment % #2: options \RenewDocumentCommand{\EndLoop}{ O{} D<>{} }{% - \axp@DefineCommand{\Keyword{endloop}}{}{}{#1}{#2}% - \ALG@makeentity{EndLoop}% - \axp@EndGroup +\axp@DefineCommand{\Keyword{endloop}}{}{}{#1}{#2}% +\ALG@makeentity{EndLoop}% +\ifaxp@NoEnd\axp@MarkLineEndFinal\fi% +\axp@EndGroup% } @@ -618,30 +722,33 @@ % #3: comment % #4: options \RenewDocumentCommand{\If}{ O{} m O{} D<>{} }{% - \axp@BeginGroup - \axp@DefineCommand{\Keyword{if}}{#2}{\Keyword{then}}{#1#3}{#4}% - \ALG@makeentity{If}% +\axp@BeginGroup% +\axp@DefineCommand{\Keyword{if}}{#2}{\Keyword{then}}{#1#3}{#4}% +\ALG@makeentity{If}% } % #1: old style comment % #2: text % #3: comment % #4: options \RenewDocumentCommand{\ElsIf}{ O{} m O{} D<>{} }{% - \axp@DefineCommand{\Keyword{else}~\Keyword{if}}{#2}{\Keyword{then}}{#1#3}{#4}% - \ALG@makeentity{ElsIf}% +\axp@DefineCommand{\Keyword{else}~\Keyword{if}}{#2}{\Keyword{then}}{#1#3}{#4}% +\axp@CloseBlocktrue% +\ALG@makeentity{ElsIf}% } % #1: comment % #2: options \RenewDocumentCommand{\Else}{ O{} D<>{} }{% - \axp@DefineCommand{\Keyword{else}}{}{}{#1}{#2}% - \ALG@makeentity{Else}% +\axp@DefineCommand{\Keyword{else}}{}{}{#1}{#2}% +\axp@CloseBlocktrue% +\ALG@makeentity{Else}% } % #1: comment % #2: options \RenewDocumentCommand{\EndIf}{ O{} D<>{} }{% - \axp@DefineCommand{\Keyword{endif}}{}{}{#1}{#2}% - \ALG@makeentity{EndIf}% - \axp@EndGroup +\axp@DefineCommand{\Keyword{endif}}{}{}{#1}{#2}% +\ALG@makeentity{EndIf}% +\ifaxp@NoEnd\axp@MarkLineEndFinal\fi% +\axp@EndGroup% } @@ -656,46 +763,49 @@ % #3: comment % #4: options \RenewDocumentCommand{\Switch}{ O{} m O{} D<>{} }{% - \axp@BeginGroup - \axp@DefineCommand{\Keyword{switch}}{#2}{}{#1#3}{#4}% - \ALG@makeentity{Switch}% +\axp@BeginGroup +\axp@DefineCommand{\Keyword{switch}}{#2}{}{#1#3}{#4}% +\ALG@makeentity{Switch}% } % #1: comment % #2: options \RenewDocumentCommand{\EndSwitch}{ O{} D<>{} }{% - \axp@DefineCommand{\Keyword{endswitch}}{}{}{#1}{#2}% - \ALG@makeentity{EndSwitch}% - \axp@EndGroup +\axp@DefineCommand{\Keyword{endswitch}}{}{}{#1}{#2}% +\ALG@makeentity{EndSwitch}% +\ifaxp@NoEnd\axp@MarkLineEndFinal\fi% +\axp@EndGroup } % #1: old style comment % #2: text % #3: comment % #4: options \RenewDocumentCommand{\Case}{ O{} m O{} D<>{} }{% - \axp@BeginGroup - \axp@DefineCommand{\Keyword{case}}{#2}{\Keyword{do}}{#1#3}{#4}% - \ALG@makeentity{Case}% +\axp@BeginGroup +\axp@DefineCommand{\Keyword{case}}{#2}{\Keyword{do}}{#1#3}{#4}% +\ALG@makeentity{Case}% } % #1: comment % #2: options \RenewDocumentCommand{\EndCase}{ O{} D<>{} }{% - \axp@DefineCommand{\Keyword{endcase}}{}{}{#1}{#2}% - \ALG@makeentity{EndCase}% - \axp@EndGroup +\axp@DefineCommand{\Keyword{endcase}}{}{}{#1}{#2}% +\ALG@makeentity{EndCase}% +\ifaxp@NoEnd\axp@MarkLineEndFinal\fi% +\axp@EndGroup } % #1: comment % #2: options \RenewDocumentCommand{\Otherwise}{ O{} D<>{} }{% - \axp@BeginGroup - \axp@DefineCommand{\Keyword{otherwise}}{}{}{#1}{#2}% - \ALG@makeentity{Otherwise}% +\axp@BeginGroup +\axp@DefineCommand{\Keyword{otherwise}}{}{}{#1}{#2}% +\ALG@makeentity{Otherwise}% } % #1: comment % #2: options \RenewDocumentCommand{\EndOtherwise}{ O{} D<>{} }{% - \axp@DefineCommand{\Keyword{endotherwise}}{}{}{#1}{#2}% - \ALG@makeentity{EndOtherwise}% - \axp@EndGroup +\axp@DefineCommand{\Keyword{endotherwise}}{}{}{#1}{#2}% +\ALG@makeentity{EndOtherwise}% +\ifaxp@NoEnd\axp@MarkLineEndFinal\fi% +\axp@EndGroup } @@ -718,34 +828,35 @@ % #3: comment % #4: options \RenewDocumentCommand{\For}{ O{} m O{} D<>{} }{% - \axp@BeginGroup - \axp@DefineCommand{\Keyword{for}}{#2}{\Keyword{do}}{#1#3}{#4}% - \ALG@makeentity{For}% +\axp@BeginGroup +\axp@DefineCommand{\Keyword{for}}{#2}{\Keyword{do}}{#1#3}{#4}% +\ALG@makeentity{For}% } % #1: old style comment % #2: text % #3: comment % #4: options \RenewDocumentCommand{\ForEach}{ O{} m O{} D<>{} }{% - \axp@BeginGroup - \axp@DefineCommand{\Keyword{foreach}}{#2}{\Keyword{do}}{#1#3}{#4}% - \ALG@makeentity{ForEach}% +\axp@BeginGroup +\axp@DefineCommand{\Keyword{foreach}}{#2}{\Keyword{do}}{#1#3}{#4}% +\ALG@makeentity{ForEach}% } % #1: old style comment % #2: text % #3: comment % #4: options \RenewDocumentCommand{\ForAll}{ O{} m O{} D<>{} }{% - \axp@BeginGroup - \axp@DefineCommand{\Keyword{forall}}{#2}{\Keyword{do}}{#1#3}{#4}% - \ALG@makeentity{For}% +\axp@BeginGroup +\axp@DefineCommand{\Keyword{forall}}{#2}{\Keyword{do}}{#1#3}{#4}% +\ALG@makeentity{For}% } % #1: comment % #2: options \RenewDocumentCommand{\EndFor}{ O{} D<>{} }{% - \axp@DefineCommand{\Keyword{endfor}}{}{}{#1}{#2}% - \ALG@makeentity{EndFor}% - \axp@EndGroup +\axp@DefineCommand{\Keyword{endfor}}{}{}{#1}{#2}% +\ALG@makeentity{EndFor}% +\ifaxp@NoEnd\axp@MarkLineEndFinal\fi% +\axp@EndGroup } @@ -758,18 +869,19 @@ % #4: comment % #5: options \RenewDocumentCommand{\Procedure}{ O{} m m O{} D<>{} }{% - \axp@BeginGroup - \axp@IsModuletrue% - \axp@DefineCommand{\Keyword{procedure}~\Module{#2}}{#3}{}{#4}{#5}% - \ALG@makeentity{Procedure}% - \axp@IsModulefalse% +\axp@BeginGroup +\axp@IsModuletrue% +\axp@DefineCommand{\Keyword{procedure}~\Module{#2}}{#3}{}{#1#4}{#5}% +\ALG@makeentity{Procedure}% +\axp@IsModulefalse% } % #1: comment % #2: options \RenewDocumentCommand{\EndProcedure}{ O{} D<>{} }{% - \axp@DefineCommand{\Keyword{endprocedure}}{}{}{#1}{#2}% - \ALG@makeentity{EndProcedure}% - \axp@EndGroup +\axp@DefineCommand{\Keyword{endprocedure}}{}{}{#1}{#2}% +\axp@MarkLineEndFinal% +\ALG@makeentity{EndProcedure}% +\axp@EndGroup } \algblockdefx[Function]{Function}{EndFunction}{\axp@MakeCommand}{\axp@MakeCommand*} @@ -779,25 +891,26 @@ % #4: comment % #5: options \RenewDocumentCommand{\Function}{ O{} m m O{} D<>{} }{% - \axp@BeginGroup - \axp@IsModuletrue% - \axp@DefineCommand{\Keyword{function}~\Module{#2}}{#3}{}{#4}{#5}% - \ALG@makeentity{Function}% - \axp@IsModulefalse% +\axp@BeginGroup +\axp@IsModuletrue% +\axp@DefineCommand{\Keyword{function}~\Module{#2}}{#3}{}{#1#4}{#5}% +\ALG@makeentity{Function}% +\axp@IsModulefalse% } % #1: comment % #2: options \RenewDocumentCommand{\EndFunction}{ O{} D<>{} }{% - \axp@DefineCommand{\Keyword{endfunction}}{}{}{#1}{#2}% - \ALG@makeentity{EndFunction}% - \axp@EndGroup +\axp@DefineCommand{\Keyword{endfunction}}{}{}{#1}{#2}% +\axp@MarkLineEndFinal% +\ALG@makeentity{EndFunction}% +\axp@EndGroup } \RenewDocumentCommand{\Call}{ m m D<>{} }{% - \begingroup% - \AlgSet{#3}% - \Module{#1}\textcolor{\axp@TextColor}{\axp@TextFont(#2)}% - \endgroup% +\begingroup% +\AlgSet{#3}% +\Module{#1}\textcolor{\axp@TextColor}{\axp@TextFont(#2)}% +\endgroup% } @@ -822,13 +935,13 @@ \NewCommandCopy{\axp@AlgorithmicxAlgorithmic}{\algorithmic} \NewCommandCopy{\axp@AlgorithmicxEndAlgorithmic}{\endalgorithmic} \RenewDocumentCommand{\algorithmic}{ O{} D<>{} }{% - \begingroup% - \AlgSet{#2}% - \axp@AlgorithmicxAlgorithmic[#1]% +\begingroup% +\AlgSet{#2}% +\axp@AlgorithmicxAlgorithmic[#1]% } \RenewDocumentCommand{\endalgorithmic}{}{% - \axp@AlgorithmicxEndAlgorithmic% - \endgroup% +\axp@AlgorithmicxEndAlgorithmic% +\endgroup% } -\endinput
\ No newline at end of file +\endinput |