Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for algorithm packages, such as algorithmic and algpseudocodex #496

Closed
wants to merge 3 commits into from

Conversation

Saltsmart
Copy link
Contributor

what is this pull request about?

This pull request adds the support for algorithm packages, such as algorithmic and algpseudocodex

does this relate to an existing issue?

Here is the link: issue 427

does this change any existing behaviour?

yes

what does this add?

Here is a minimal example:

\begin{algorithm}[ht]
    \caption{some caption.}
    \begin{algorithmic}[1]
        \Require{aaa}
        \Ensure{bbb}
        % for-loop
        \For{$n = 1, \dots, 10$}
        \State body
        \EndFor
        % nesting for-loop
        \FOR{for 1}
        \FOR{for 2}
        \FOR{for 3}
        \STATE{some statement.}
        \ENDFOR
        \ENDFOR
        \ENDFOR
        % while-loop in if-statement
        \If{$quality\ge 9$}
        \State $a\gets perfect$
        \ElsIf{$quality\ge 7$}
        \State $a\gets good$
        \ElsIf{$quality\ge 5$}
        \State $a\gets medium$
        \ElsIf{$quality\ge 3$}
        \State $a\gets bad$
        \Else
        \While{$i\le n$}
        \State $sum\gets sum+i$
        \State $i\gets i+1$
        \EndWhile
        \EndIf
        % nesting blocks
        \ForAll{$n \in \{1, \dots, 10\}$}
        \State body
        \Loop
        \State body
        \EndLoop
        \State $sum\gets 0$
        \State $i\gets 1$
        \Repeat
        \State $sum\gets sum+i$
        \State $i\gets i+1$
        \Until{$i>n$}
        \EndFor
        % fuction block
        \Function{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
        \State $r\gets a\bmod b$
        \While{$r\not=0$}\Comment{We have the answer if r is 0}
        \State $a\gets b$
        \State $b\gets r$
        \State $r\gets a\bmod b$
        \EndWhile
        \State \textbf{return} $b$\Comment{The gcd is b}
        \EndFunction
    \end{algorithmic}
\end{algorithm}

After merging the pull request, latexindent.pl could format the file as follows (with 4-space indents):

\begin{algorithm}[ht]
    \caption{some caption.}
    \begin{algorithmic}[1]
        \Require{aaa}
        \Ensure{bbb}
        % for-loop
        \For{$n = 1, \dots, 10$}
            \State body
        \EndFor
        % nesting for-loop
        \FOR{for 1}
            \FOR{for 2}
                \FOR{for 3}
                    \STATE{some statement.}
                \ENDFOR
            \ENDFOR
        \ENDFOR
        % while-loop in if-statement
        \If{$quality\ge 9$}
            \State $a\gets perfect$
        \ElsIf{$quality\ge 7$}
            \State $a\gets good$
        \ElsIf{$quality\ge 5$}
            \State $a\gets medium$
        \ElsIf{$quality\ge 3$}
            \State $a\gets bad$
        \Else
            \While{$i\le n$}
                \State $sum\gets sum+i$
                \State $i\gets i+1$
            \EndWhile
        \EndIf
        % nesting blocks
        \ForAll{$n \in \{1, \dots, 10\}$}
            \State body
            \Loop
                \State body
            \EndLoop
            \State $sum\gets 0$
            \State $i\gets 1$
            \Repeat
                \State $sum\gets sum+i$
                \State $i\gets i+1$
            \Until{$i>n$}
        \EndFor
        % fuction block
        \Function{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
            \State $r\gets a\bmod b$
            \While{$r\not=0$}\Comment{We have the answer if r is 0}
                \State $a\gets b$
                \State $b\gets r$
                \State $r\gets a\bmod b$
            \EndWhile
            \State \textbf{return} $b$\Comment{The gcd is b}
        \EndFunction
    \end{algorithmic}
\end{algorithm}

how do I test this?

You can test this as the above section depicts.

anything else?

No more further comments. Best wishes for you and your family!

Copy link

github-actions bot commented Dec 2, 2023

Thank you for your contribution! Please can you change this pull request so that it goes to the develop branch? Thank you

@Saltsmart Saltsmart changed the base branch from main to develop December 2, 2023 07:06
@cmhughes
Copy link
Owner

cmhughes commented Dec 2, 2023

Thanks this looks like a good contribution!

A few comments to address, please

  • It looks you might have branched from an earlier version; can you rebase from V3.23.4? you'll see that, for example, Version.pm is out of date on your branch
  • the lookForThis: 1 is not necessary, so can you remove it in each occurrence?
  • can you add dedicated test cases that demonstrate these to test-cases/ specials? this is really important so that when new features are added/developed, I can ensure that nothing breaks.

Thanks so much for your time on this!

- \\ELSIF\{[^}]+?\}
end: \\ENDIF
lookForThis: 1
specialBeforeCommand: 1 # search for these fields before searching for commands
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line shouldn't be the default. Please leave this value at 0

@Saltsmart Saltsmart closed this by deleting the head repository Dec 4, 2023
- \\ELSIF\{[^}]+?\}
end: \\ENDIF
lookForThis: 1
specialBeforeCommand: 1 # search for these fields before searching for commands
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line shouldn't be the default. Please leave this value at 0

Did you refer to this line? I have tried specialBeforeCommand: 0 and found this couldn't format the code.
The picture depicts the result with specialBeforeCommand: 0:
image

This is the result with specialBeforeCommand: 1:
image

I'm creating a new fork to rebase from the dev branch (sorry for not noticing this branch :-)), and will start a new pull request.
If there is any idea related to this problem please let me know.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new pull request: #498

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants