tlienart / Franklin.jl

(yet another) static site generator. Simple, customisable, fast, maths with KaTeX, code evaluation, optional pre-rendering, in Julia.
https://franklinjl.org
MIT License
963 stars 114 forks source link

Support starred commands #629

Open schneiderfelipe opened 4 years ago

schneiderfelipe commented 4 years ago

The idea would be to support \newcommand{\mycommand*}{...} as in LaTeX \mycommand*. This came from a comment in #624.

This might have to do with #628 (for things such as \begin{equation*}, etc.).

tlienart commented 4 years ago

I never really got these starred commands, what are they for?

(I think the equation one is to avoid numbering?)

Edit: hmm https://tex.stackexchange.com/a/45394 right so probably not all of it is useful right now

schneiderfelipe commented 4 years ago

I never really got these starred commands, what are they for?

They normally mean something is executed, but less output is produced. That's more like a convention.

(I think the equation one is to avoid numbering?)

Yes. Allowing * to appear in a command's name would solve it. Is it too hard?

tlienart commented 4 years ago

I think the question is more whether it's really super useful or not :-)

Franklin cannot hope to support all of LaTeX so it would make sense to determine a "useful subset", I agree that unnumbered equations might be good but apart from that the general command* seems a bit useless to me?

schneiderfelipe commented 4 years ago

I think the question is more whether it's really super useful or not :-)

I have to admit, not really. But it is super cool 😄.

Franklin cannot hope to support all of LaTeX so it would make sense to determine a "useful subset", I agree that unnumbered equations might be good but apart from that the general command* seems a bit useless to me?

I agree. But you might not need to support all of LaTeX if all of LaTeX could be defined from within Franklin. And it suffices (I think) to support \newcommand and \newenvironment both with and without *.

And this could be a simple fix. At

https://github.com/tlienart/Franklin.jl/blob/9ba09dec6fb5d1b8a16ab9510eddb3eff4cd27e6/src/regexes.jl#L14

the definition could be rewritten to be

r"^\s*(\\[\p{L}]+\*?)\s*$"

(Disclaimer: I haven't tested it.) Do you think it will clash with something else in Franklin?

tlienart commented 4 years ago

your modification is correct (feel free to open a draft pr with it!) the only thing to test is that there's no ambiguity with the emphasis since *blah* is meant to give blah and so there's a parsing ordering to consider. I think it will be fine but it should be tested nonetheless with things like

\com*{foo *bar*}
\com*{foo} *bar*
*\com*{foo}*

for environment it's within braces so it's trivial.

tlienart commented 4 years ago

this is effectively done on branch https://github.com/tlienart/Franklin.jl/tree/beginend (which is not ready to be released but hopefully soon).