ytliu74 / obsidian-pseudocode

An obsidian plugin that helps to render a LaTeX-style pseudocode inside a code block.
MIT License
84 stars 4 forks source link

Adjust alignment for comments #16

Closed rosshjb closed 1 month ago

rosshjb commented 9 months ago

Could you support an option to align comments?

Sample: image

\begin{algorithm}
    \caption{Merge Sort}
    \begin{algorithmic}
        \Procedure{Merge-Sort}{$A,p,q,r$}
            \If{$p\ge r$} \Comment{zero or one element?}
                \State \Return\Comment{early return}
            \EndIf
            \State $q \gets \lfloor(p+r)/2\rfloor$
            \State \Call{Merge-Sort}{$A,p,q$}
            \State \Call{Merge-Sort}{$A,q+1,r$}
            \State \Call{Merge}{$A,p,q,r$}
        \EndProcedure
    \end{algorithmic}
\end{algorithm}
ytliu74 commented 9 months ago

Hi, well, the comment now indeed looks bad. How about let them align to the right side like below:

image

If you are okay with this, I can try to implement.

rosshjb commented 9 months ago

@ytliu74 Awesome! If the comment is on a separate line, it would be better to display it as before:

image

\begin{algorithm}
    \caption{Merge Sort}
    \begin{algorithmic}
        \Procedure{Merge-Sort}{$A,p,q,r$}
                \State \Comment{zero or one element?}
            \If{$p\ge r$}
                \State \Return
            \EndIf
            \State $q \gets \lfloor(p+r)/2\rfloor$
            \State \Call{Merge-Sort}{$A,p,q$}
            \State \Call{Merge-Sort}{$A,q+1,r$}
            \State \Call{Merge}{$A,p,q,r$}
        \EndProcedure
    \end{algorithmic}
\end{algorithm}
ytliu74 commented 4 months ago

Hi @rosshjb, you can refer to this pull request https://github.com/ytliu74/obsidian-pseudocode/pull/18 for a possible solution. But it's not perfect. But you can use it as a workaround, thanks.

dzx-dzx commented 4 months ago

Example here: image image image

anton-dergunov commented 1 month ago

Hi @rosshjb, you can refer to this pull request #18 for a possible solution. But it's not perfect. But you can use it as a workaround, thanks.

This change seem to break the layout... image

anton-dergunov commented 1 month ago

This fix worked for me

.ps-comment {
        float: right;
}

image

anton-dergunov commented 1 month ago

Or, to make it even more consistent with LaTeX package documentation (https://ctan.math.washington.edu/tex-archive/macros/latex/contrib/algpseudocodex/algpseudocodex.pdf):

image

Change it like that:

.ps-root {
        font-family: KaTeX_Main, "Times New Roman", Times, serif;
        font-weight: 400;
        font-variant: normal;
        font-style: normal;
        text-transform: none;
}

.ps-comment {
        font-family: KaTeX_Main, "Times New Roman", Times, serif;
        font-weight: 400;
        font-variant: normal;
        font-style: italic;
        text-transform: none;
        opacity: 70%;
        float: right;
}

Now it looks like this:

image

I just hacked this file: .obsidian/plugins/pseudocode-in-obs/styles.css

anton-dergunov commented 1 month ago

https://github.com/ytliu74/obsidian-pseudocode/pull/22 This could address the issue, but more clean up is possible.

ytliu74 commented 1 month ago

Thanks so much for the support from @anton-dergunov. I've already merged the commit and it's included in the newest version.