On Sun, 8 Jun 2025 at 22:54, Pavel Sanda <sa...@lyx.org> wrote:

> On Sun, Jun 08, 2025 at 11:13:45PM +0300, Noam Zaks wrote:
> > I honestly think it's a great idea to implement a LyX to Typst backend
> > aswell!  Didn't think about it mostly because LyX seems so "intertwined"
> with
> > (La)-TeX. I will have to look into the source code to see if it's
> something
> > I can try to do myself!
>
> It's true, that lyx is intertwined with latex, on the other hand we can
> produce
> decent docbook output as well. If you just search through the docbook
> related
> output routines in our source code that might give you an idea how
> difficult
> it could be to add one more output target.
>
> But it's definitely within 1 person scope of coding, which is totally not
> the
> case if you wanted to code full blown lyx equivalent.
>
> The whole docbook thing was done by single person within one-two years as a
> side hobby (plus minus further tuning of details; only Thibaut would know
> the
> real person-hours for first decent version available).
>

It's totally doable by one person, as long as you know some C++!

LyX is really made for LaTeX, so output in formats such as XHTML or DocBook
is a bit awkward at times, but that shouldn't really be the case for Typst,
as the principles are much more aligned with those of LaTeX.

Time-wise, the DocBook output didn't take that much time. The first draft
was working in a few months (I started from the previous implementation, so
I had quite a bit of plumbing that didn't change that much); the largest
part was fine-tuning the output for it to be valid, which included making
the code as flexible as possible in many parts. I expect this work to be
much easier with Typst!
I'm speaking in months mostly because I worked in spikes: a few hours
everyday for some time, then not at all for weeks.
(Bibliographies in DocBook were quite hard, because the format is really
different from .bib files, whereas Typst can use them directly; on the
other hand, I could rely on LyX' MathML output, while Typst has its own
syntax for maths.)

A few pointers:
- More or less every inset would need a typst() method that does some
specific job for that inset. For instance, InsetHyperlink::typst() would
output a link in Typst.
- The entry point would be a new method Buffer::writeTypstSource.
- For maths (not the first thing you should have a look at!), you have the
same system of insets (but in the mathed folder instead of insets). The
entry point is InsetMathHull. For instance, you would have to implement an
InsetMathFrac::typst() to output the formula as Typst. In a first step, you
can implement the usual fallback: if you can't understand a formula, render
it as a PNG and embed it as an image; it's better than nothing and much
easier to implement than a full Typst output for formulae.
- In a later stage, you will want to support layouts and other
customisation options in LyX. They are mostly configured in .layout and
.module files (lib/layouts in the Git repo). You can have a look at
InsetLayout and InsetFlex.
-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
https://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to