-
Notifications
You must be signed in to change notification settings - Fork 4
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
More flexible styling #14
Comments
I've actually considered doing this myself before, but there were some concerns preventing me from implementing it. With regards to keywords, the highlighting is achieved with a regex show-rule that is applied to each line of the main algorithm text. Because this can lead to false positives, I added a With regards to Separate from this issue, I also plan to entirely rewrite the package whenever Typst finally implements its types/content/context/styling reworks. If we decide not to act on this issue right now, I'll definitely get to it during my rewrite. |
You can have a look at fork (commit 32695f9) I also added the functionality to disable the default strong styling with false, which could also be changed to none or something else. I am also very much waiting for proper types and other future features to be implemented in typst, which is why I am also hesitant to change quite a few packages/scripts of my own. So I understand if you want to wait until this functionality is made clean and idiomatically. That way, many in between breaking changes can be avoided. However, if you decide this is the right direction for now, I can clean up my code and rewrite also the other parts as describe before. |
Currently, it runs into the Notice that instances of keywords in the inline comment are also displayed in blue text. The current scheme avoids this by simply disabling strong text in comments: #let no-emph(body) = {
...
set strong(delta: 0)
body
}
#let comment(
body,
inline: false,
) = {
...
if inline {
_algo-comment-prefix.display(comment-prefix => {
_algo-comment-styles.display(comment-styles => {
set text(..comment-styles)
comment-prefix
no-emph(body)
})
})
} else {
...
}
} To allow the user to style keywords arbitrarily, we would need to generalize |
Ah okay, I see. But then, I think, one can solve the problem in
The second case's 'side effect' matches that of the current However, it is you to decide. Meanwhile, I will look into if, what I was saying, even works. |
Btw, both cases should be much easier to handle, as soon as the 'Type and content rework' from typst is done — especially for the second case. |
I just had a look, and I think the approach is reasonable (I wish I had thought of it sooner haha). I think it's fine if the user is unable to add additional styling to certain keywords, as all keywords should probably look the same anyway. I'll maybe look back on this when revokable show rules come in. You're free to move forward with a PR. Just some other points to consider:
|
Ok perfect. One should probably document, that end users can save the transformation in a function and use that everywhere within the code. I'll look into all mentioned points. |
Btw, I noticed, that the multi-word keyword implementation is wrong, as ':' for instance will not be matched, as the word boundaries are then messed up. I am now trying to figure out how to deal properly with this. One idea is to have a regex like '\b(?:let|if|such that)\b|:', hence additionally adding non-word keywords. |
Good catch, it's unfortunate I let that slip through. The main thing I'm trying to prevent is false positive matches against substrings (e.g. 'in' in 'interpolate'), since it's something that'll come up for users that prefer to write algorithms in "plain english". Similar to your idea, it might make sense to match against a word boundary only where the keyword ends with a word character. So if the keywords were |
Thank you for your package — I like how convenient and non-bloated it is to write code with it.
Right now, however, I noticed that one can only style keywords to be bold or not. Now one could say, that similar to other styling mechanisms in this package, one could instead give
text
parameters.However, this is quite inflexible. For instance, what if I wanted every keyword to be highlighted with
highlight
or to be boxed or underlined. This would not be possible with the current design.If we instead allowed functions mapping content to content, we would allow all these cases. It would behave similar to the following
returning
If you agree on this change, then I could work on this (while also changing the other styles arguments) and make a PR.
The text was updated successfully, but these errors were encountered: