Skip to content

support please: sile w/ fennel (for lua) #1839

Closed

Description

@reuleaux

I have successfully installed sile - and can use it to typeset this little document for example:
the lua script therein being one of the first examples from the sile manual:

\begin{document}
Hello SILE!
\begin{script}
  for i=1,10 do
    SILE.typesetter:typeset(i .. " x " .. i .. " = " .. i*i .. ". ")
    SILE.typesetter:leaveHmode()
    SILE.call("smallskip")
  end
\end{script}
\end{document}

Now I would prefer to use fennel instead of lua - cf.
https://fennel-lang.org/
And according to
https://fennel-lang.org/setup#embedding-fennel
it should be possible to use fennel from sile somehow (!?) like this:

\begin{document}
Hello SILE!
\begin{script}
  require("fennel").install().dofile("main.fnl")
  ...fennel code...
\end{script}
\end{document}

assuming fennel is properly installed - but this is my question, really:
following the https://fennel-lang.org/setup#embedding-fennel instructions I can e.g. clone fennel

cd ~/tmp && git clone --depth 1 -b 1.3.1 https://git.sr.ht/~technomancy/fennel

and then make it

cd ~/tmp/fennel && LUA=lua5.4 make

this creates a ~/tmp/fennel/fennel.lua for me.
but how do I tell sile to use this ~/tmp/fennel now ?

Or could I use luarocks for fennel? - If I do

luarocks install --lua-version=5.4  fennel

I get a fennel executable, not a fennel.lua file, however.

I am fairly experienced in computing in general, but with regards to lua / luarocks only a beginner,
thus bear with me.

Any help in this regard welcome. - Thanks - A'

Activity

  1. reuleaux commented on Jul 18, 2023

    @reuleaux
    Author

    To answer my own question: I got it working (at least with a separat main.fnl file, cf. below) - like so:

    (I am installing everything as a normal user rx (/home/rx), except sile's luarocks deps - those as root)

    clone & make fennel

    cd ~/tmp && git clone --depth 1 -b 1.3.1 https://git.sr.ht/~technomancy/fennel
    cd ~/tmp/fennel && LUA=lua5.4 make
    

    (there should be a fennel.lua file then in ~/tmp/fennel)

    then configure/make/install sile - with fennel in mind:

    configure 1st time - just so that sile-dev-1.rockspec is created:

    cd ~/tmp/sile && LUA=/usr/bin/lua5.4 ./configure --prefix=/home/rx/opt/sile
    

    install lua deps (this step as root):

    # cd /home/rx/tmp/sile && luarocks install --lua-version=5.4 --only-deps  sile-dev-1.rockspec
    

    now do the real configure - and as for fennel: use LDFLAGS

    cd ~/tmp/sile && LUA=/usr/bin/lua5.4 ./configure LDFLAGS="-L/home/rx/tmp/fennel" --prefix=/home/rx/opt/sile --with-system-luarocks
    

    make & inscall

    cd ~/tmp/sile && make
    cd /tmp/sile && make install
    

    then have a sample file foobar.sil

    \begin{document}
    Hello SILE!
    
    \begin{script}
      require("fennel").install().dofile("main.fnl")
    \end{script}
    
    \end{document}
    

    and next to it a file main.fnl:

    (each [i value (ipairs ["b" "b" "c"])]
          ;; (print index value)
          (SILE.typesetter:typeset (.. i " x " i " = " (* i i)))
          (SILE.typesetter:leaveHmode)
          (SILE.call "smallskip")
          )

    This (sile foobar.sil) creates a foobar.pdf as attached.
    foobar.pdf

    I yet have to find out how to just use fennel - without a separate main.fnl - somehow like this ??:

    \begin{document}
    Hello SILE!
    \begin{script}
      require("fennel").install().(each [i value (ipairs ["b" "b" "c"])]
                                                       (SILE.typesetter:typeset (.. i " x " i " = " (* i i)))
                                                       (SILE.typesetter:leaveHmode)
                                                       (SILE.call "smallskip")
                                                   )
    \end{script}
    
    \end{document}
    

    Maybe fennel could become a first class sile citizen ?

    What always works, of course: use fennel as a converter:

    fennel file.fnl
    

    to create a file.lua - and this could be sile-lua file

    but I was interested here really, how to integrate fennel in a (normal) .sil file.

    Thanks, A'

  2. alerque commented on Jul 18, 2023

    @alerque
    Member

    I'm not at home and have spotty access and time for a few weeks, but off the top of my head it should be possible to simplify this quite a bit. I would probably write a LuaRocks package as a 3rd party module for SILE that copies most of the current lua inputter code but adds the Fennel preprocessor step. Then post it to LuaRocks with a dependency on fennel. That done a simple "luarocks install fennel.sile" should get things going, and in a document you could then \use[module=fennel] to load the inputer, after which you could have a \fennel{...} command available to use in place of \lua{} (of which \script{} is just an alias).

  3. reuleaux commented on Jul 18, 2023

    @reuleaux
    Author

    Great! - And thanks for getting back to me about this. - I will have a look (and a stab) at writing
    a loarocks sile package for fennel then sometime - not immediately though: I am busy myself, and have only just started reading the sile manual, and I prefer to continue reading / progressing step by step: but I see that in the later chapters
    of the manual writing a sile package is explained.

  4. Omikhleia commented on Jul 23, 2023

    @Omikhleia
    Member

    I agree with @alerque that this is best addressed as a 3rd-party package. The fennel.lua file is above 5KLoc and 230kB of machine-generated code, which is quite a lot for such a niche use case, without clear rationale (except a vague user preference for Lisp-like syntax?) Besides, it's certainly not the task of the SILE core distribution to maintain such an embedding and keep track of versions and updates for such a niche language - not even mentioning investigating potential bugs.

    On the technical aspect, however, I don't think an inputter is even needed, neither the need for a reserving a \fennel command as SIL pass-through exception... Raw command handlers should be largely sufficient and have the necessary API, and provided one does read the manual up to the relevant chapter before asking how to implement things, one should find there the needed information. I would suggest starting with this solution...

    As for being busy, aren't we all?

    But bear with me, the above suggestion is then at most 15-20mn of coding for an experienced senior developer :)
    Really? Aye, just did it. This said, I will close this issue and move it to the discussions (Q&A). I'll post my PoC code there.

  5. locked and limited conversation to collaborators on Jul 23, 2023
  6. converted this issue into a discussion #1841 on Jul 23, 2023
  7. added
    wontfixRejected for other reasons than duplicate or invalid
    on Jul 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionAsk for advice or investigate solutionswontfixRejected for other reasons than duplicate or invalid

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions