fenjalien / cirCeTZ

A port of circuitikz to Typst using CeTZ!
Apache License 2.0
110 stars 9 forks source link

Support for TOML or JSON files #1

Closed saadulkh closed 1 year ago

saadulkh commented 1 year ago

Hi!

I recently found this awesome contribution for the typst project.

I was wondering that, the current process of defining a circuit is quite verbose and boiler-plate and if this could be automated/supported using the configuration/description of the circuit given in either .toml or .json files (both of which have native typst support).

For example, typst-timetable accepts a .toml file to generate a table, which is a quite convenient approach.

An example of how a digital circuit can be expressed in json files, XOR.json

[
    {
        "inputs": [
            {
                "inputs": [
                    {
                        "inputs": [],
                        "name": "A"
                    },
                    {
                        "inputs": [
                            {
                                "inputs": [],
                                "name": "B"
                            }
                        ],
                        "name": "NOT"
                    }
                ],
                "name": "AND"
            },
            {
                "inputs": [
                    {
                        "inputs": [],
                        "name": "B"
                    },
                    {
                        "inputs": [
                            {
                                "inputs": [],
                                "name": "A"
                            }
                        ],
                        "name": "NOT"
                    }
                ],
                "name": "AND"
            }
        ],
        "name": "OR"
    }
]

But again, this is too much boilerplate, than something similar expressed in a .toml file. Also, .toml can be a better choice for this kind of requirement, as analogue as well as digital circuits can easily become complex (interconnections between different parts of the circuit, intricate wiring), which a .json template like above cannot handle (no wiring details). Tho, we can a template like, an array for listing all the components and an array to mention all the wiring between inputs and outputs of different components.

I would like to know if there's any plan for such support? As, I worked on a project called logic-sim, I want to continue this project in future as well. And this project can generate output descriptions of the digital circuits, as shown above. Was wondering to integrate both these projects to make things easier.

fenjalien commented 1 year ago

Its a cool idea but this is supposed to be a port of circuitikz (https://github.com/circuitikz/circuitikz) so thats where my focus lies. Well its actually helping to improve typst-canvas so that I can work on this library.

If you want to do something like a proof of concept go ahead but I don't think the library is anywhere near stable yet.

saadulkh commented 1 year ago

Hmm, I understand the interests of this project. I'll see what I can do about this feature. Thanks for the quick response tho.