diff --git a/.github/workflows/tests-compile-ci.yml b/.github/workflows/tests-compile-ci.yml index 8d443e7..d4f83da 100644 --- a/.github/workflows/tests-compile-ci.yml +++ b/.github/workflows/tests-compile-ci.yml @@ -8,9 +8,9 @@ name: Tests Compile CI on: # Triggers the workflow on push or pull request events but only for the branches below push: - branches: [ "main", "0.0.x", "0.1.0-dev" ] + branches: ["main", "0.0.x", "0.1.0-dev"] pull_request: - branches: [ "main", "0.0.x", "0.1.0-dev" ] + branches: ["main", "0.0.x", "0.1.0-dev"] # Allows one to run this workflow manually from the Actions tab workflow_dispatch: @@ -25,8 +25,8 @@ jobs: matrix: # Test for the following Typst versions # 0.2.0 (earliest supported), 0.6.0 (first version with package management), - # 0.10.0 (latest supported) - typst-version: [v0.2.0, v0.6.0, v0.10.0] + # 0.10.0, 0.11.1, 0.12.0 (latest supported) + typst-version: [v0.2.0, v0.6.0, v0.10.0, v0.11.1, v0.12.0] # Steps represent a sequence of tasks that will be executed as part of the job steps: @@ -44,14 +44,14 @@ jobs: DISCLAIMER - name: 📥 Setup Typst 0.2.0 - uses: yusancky/setup-typst@v1 + uses: typst-community/setup-typst@v1 id: setup-typst-old if: ${{ matrix.typst-version == 'v0.2.0' }} with: version: ${{ matrix.typst-version }} - name: 📥 Setup Typst (0.3.0+) - uses: yusancky/setup-typst@v2 + uses: typst-community/setup-typst@v3 id: setup-typst if: ${{ matrix.typst-version != 'v0.2.0' }} with: diff --git a/LICENSE-APACHE b/LICENSE-APACHE new file mode 100644 index 0000000..71b8799 --- /dev/null +++ b/LICENSE-APACHE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2024 PgBiel + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/LICENSE b/LICENSE-MIT similarity index 97% rename from LICENSE rename to LICENSE-MIT index 762c85e..869be70 100644 --- a/LICENSE +++ b/LICENSE-MIT @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Pg Biel +Copyright (c) 2024 PgBiel Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index abd9549..304226a 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ -# typst-tablex (v0.0.8) +# typst-tablex (v0.0.9) **More powerful and customizable tables in Typst.** -**NOTE: Please open an issue if you find a bug with tablex** and I'll get to it as soon as I can. **(PRs are also welcome!)** - ## Sponsors ❤️ If you'd like to appear here, [consider sponsoring the project!](https://github.com/sponsors/PgBiel) @@ -10,11 +8,49 @@ If you'd like to appear here, [consider sponsoring the project!](https://github.
+## Important notice regarding Tablex usage + +**Summary: Please use built-in Typst tables instead of tablex.** Most of tablex's features were implemented in Typst 0.11.0, see the [docs](https://typst.app/docs/reference/model/table/). + +However, **keep an eye for future tablex updates** as there might be some interesting goodies ahead, including CeTZ support! + +**Details:** + +A large amount of tablex's features have successfully been upstreamed by this package's author to Typst's built-in `table` and `grid` elements (see the new Tables Guide, at https://typst.app/docs/guides/table-guide/, and the `table` element's reference, at https://typst.app/docs/reference/model/table/, for more information). + +This effort was tracked in the following Typst issue: https://github.com/typst/typst/issues/3001 + +This means that, starting with Typst 0.11.0, **many advanced table features can now be used with Typst grids and tables without tablex!** This includes: + +- Per-cell customization (through `table.cell(inset: ..., align: ..., fill: ...)[body]`, and `#show table.cell: it => ...` instead of `map-cells`); +- Merging cells (colspans and rowspans, through `table.cell(colspan: 2, rowspan: 2)[body]`); +- Line customization (you can control the `stroke` parameter of `table.cell` to control the lines around it, and you can use `table.hline` and `table.vline` which work similarly to their tablex counterparts - the equivalent of `map-hlines` and `map-vlines` is `table(stroke: (x, y) => (left: ..., right: ..., top: ..., bottom: ...))`); +- Repeatable table headers (through `table.header(... cells ...)`); +- The features above are available within `grid` as well by replacing `table` with `grid` where applicable (e.g. `grid.cell` instead of `table.cell`). + +Additionally, built-in Typst tables have support for features which weren't previously available within tablex, such as **repeatable table footers** (through `table.footer` and `grid.footer`). + +Therefore, **for the vast majority of use cases, you will no longer need to use this library.** + +There are a few observations: + +1. **Tablex will still receive updates over time** with extra features. In the next version (tablex 0.1.0), there will be **support for CeTZ integration**, which will allow you to easily **annotate your tables** using CeTZ (e.g. draw arrows between cells). If you're interested in such features, then tablex might still be useful for you in the future! +2. **Not _all_ tablex features are present in built-in tables, at least yet.** Therefore, **if you happen to use the features listed below, you might still have to use tablex** depending on your use case. It is expected, however, that built-in tables will eventually have support for most of the missing features in future Typst releases. Here's a non-exhaustive list of them: + 1. Built-in tables do not yet have the ability to expand table lines by some arbitrary length. + 2. The tablex `fit-spans` option, through which colspans and rowspans don't cause `auto`-sized columns and/or rows to expand, is not yet supported in built-in tables. + 3. Built-in repeatable table headers currently always repeat in all pages, whereas you can define in which pages a tablex header should be repeated. +3. **Regarding sponsorships:** Any future sponsorships to the tablex author, [@PgBiel](https://github.com/PgBiel), who was also responsible for upstreaming the various tablex features to built-in tables, will go not only towards extended maintenance of tablex, but also towards other general contributions to the Typst ecosystem and his other open-source contributions! More information here: https://github.com/sponsors/PgBiel/ + +If there any questions, feel free to open a thread in the `Discussions` page of this repository, or ping the author on Discord. Thanks to everyone who supported me throughout tablex's development and the upstreaming process. I hope you enjoy the new update, and have fun with tables! 😄 + +And make sure to keep an eye for future tablex updates. 😉 + ## Table of Contents * [Usage](#usage) @@ -29,6 +65,7 @@ If you'd like to appear here, [consider sponsoring the project!](https://github. * [Basic types and functions](#basic-types-and-functions) * [Gridx and Tablex](#gridx-and-tablex) * [Changelog](#changelog) + * [v0.0.9](#v009) * [v0.0.8](#v008) * [v0.0.7](#v007) * [v0.0.6](#v006) @@ -42,11 +79,13 @@ If you'd like to appear here, [consider sponsoring the project!](https://github. ## Usage -To use this library through the Typst package manager **(for Typst v0.6.0+)**, write for example `#import "@preview/tablex:0.0.8": tablex, cellx` at the top of your Typst file (you may also add whichever other functions you use from the library to that import list!). +**NOTE: Please use built-in tables instead of this library** (see notice above). **The rest of the README is kept for reference purposes only.** + +To use this library through the Typst package manager **(for Typst v0.6.0+)**, write for example `#import "@preview/tablex:0.0.9": tablex, cellx` at the top of your Typst file (you may also add whichever other functions you use from the library to that import list!). For older Typst versions, download the file `tablex.typ` from the latest release (or directly from the main branch, for the 'bleeding edge') at the tablex repository (https://github.com/PgBiel/typst-tablex) and place it on the same folder as your own Typst file. Then, at the top of your file, write for example `#import "tablex.typ": tablex, cellx` (plus whichever other functions you use from the library). -This library should be compatible with Typst v0.2.0, v0.3.0, v0.4.0, v0.5.0, v0.6.0, v0.7.0, v0.8.0, v0.9.0 and v0.10.0. +This library should be compatible with Typst versions between v0.2.0 and v0.12.0 (inclusive). **Using the latest Typst version is always recommended** in order to make use of the latest optimizations and features available. Here's an example of what `tablex` can do: @@ -55,7 +94,7 @@ Here's an example of what `tablex` can do: Here's the code for that table: ```typ -#import "@preview/tablex:0.0.8": tablex, rowspanx, colspanx +#import "@preview/tablex:0.0.9": tablex, rowspanx, colspanx #tablex( columns: 4, @@ -104,10 +143,12 @@ Here's the code for that table: ### _Almost_ drop-in replacement for `#table` +(**Update:** tablex's syntax was designed to be compatible with Typst tables created **up to Typst v0.10.0**. The new table features introduced in Typst v0.11.0 use syntax which isn't compatible with tablex, so it won't be a drop-in replacement in that case. However, tablex does have its own syntax for those features, as will be explained below!) + In most cases, you should be able to replace `#table` with `#tablex` and be good to go for a start - it should look _very_ similar (if not identical). Indeed, the syntax is very similar for the basics: ```typ -#import "@preview/tablex:0.0.8": tablex +#import "@preview/tablex:0.0.9": tablex #tablex( columns: (auto, 1em, 1fr, 1fr), // 4 columns @@ -134,7 +175,7 @@ This is mostly a word of caution in case anything I haven't anticipated happens, Your cells can now span more than one column and/or row at once, with `colspanx` / `rowspanx`: ```typ -#import "@preview/tablex:0.0.8": tablex, colspanx, rowspanx +#import "@preview/tablex:0.0.9": tablex, colspanx, rowspanx #tablex( columns: 3, @@ -165,7 +206,7 @@ Also, note that, by default, the horizontal lines below the header are transport Example: ```typ -#import "@preview/tablex:0.0.8": tablex, hlinex, vlinex, colspanx, rowspanx +#import "@preview/tablex:0.0.9": tablex, hlinex, vlinex, colspanx, rowspanx #pagebreak() #v(80%) @@ -212,7 +253,7 @@ Something similar occurs for `vlinex()`, which has `start`, `end` (first row and Here's some sample usage: ```typ -#import "@preview/tablex:0.0.8": tablex, gridx, hlinex, vlinex, colspanx, rowspanx +#import "@preview/tablex:0.0.9": tablex, gridx, hlinex, vlinex, colspanx, rowspanx #tablex( columns: 4, @@ -256,7 +297,7 @@ Here's some sample usage: You can also *bulk-customize lines* by specifying `map-hlines: h => new_hline` and `map-vlines: v => new_vline`. This includes any automatically generated lines. For example: ```typ -#import "@preview/tablex:0.0.8": tablex, colspanx, rowspanx +#import "@preview/tablex:0.0.9": tablex, colspanx, rowspanx #tablex( columns: 3, @@ -288,7 +329,7 @@ Additionally, instead of specifying content to the cell, you can specify a funct For example: ```typ -#import "@preview/tablex:0.0.8": tablex, cellx, colspanx, rowspanx +#import "@preview/tablex:0.0.9": tablex, cellx, colspanx, rowspanx #tablex( columns: 3, @@ -320,7 +361,7 @@ To customize multiple cells at once, you have a few options: Example: ```typ -#import "@preview/tablex:0.0.8": tablex, colspanx, rowspanx +#import "@preview/tablex:0.0.9": tablex, colspanx, rowspanx #tablex( columns: 4, @@ -587,7 +628,7 @@ Another example (summing columns): - `rows`: The sizes (heights) of each row. They follow the exact same format as `columns`, except that the "available space" is infinite (auto rows can expand as much as is needed, as the table can add rows over multiple pages). - **Note:** For rows, percentages (such as `49%`) are fixed width lengths, like in `columns`; however, here, they are **multiplied by the page's full height** (minus margins), and not width. - **Note:** If more rows than specified are added, the height for the **last row** will be the one assigned to all extra rows. (If the last row is `auto`, the extra ones will also be `auto`, for example.) - - Your table can have more rows than expected by simply having more cells than `(# columns)` multipled by `(# rows)`. In this case, you will have an extra row for each `(# columns)` cells after the limit. In other words, **the amount of columns is always fixed** (determined by the amount of widths in the array given to `columns`), but the amount of rows can vary depending on your input of cells to the table. + - Your table can have more rows than expected by simply having more cells than `(# columns)` multiplied by `(# rows)`. In this case, you will have an extra row for each `(# columns)` cells after the limit. In other words, **the amount of columns is always fixed** (determined by the amount of widths in the array given to `columns`), but the amount of rows can vary depending on your input of cells to the table. - Adding a cell at an arbitrary `y` coordinate can also cause your table to have extra rows (enough rows to reach the cell at that coordinate). - **Warning:** support for fractional sizes for rows is still rudimentary - they only work properly on the table's first page; on the second page and onwards, they will not behave properly, differently from the default `#table`. - `inset`: Inset/internal padding to give to each cell. Can be either a length (same inset from the top, bottom, left and right of the cell), or a dictionary (e.g. `(left: 5pt, right: 10pt, bottom: 2pt, top: 4pt)`, or even `(left: 5pt, rest: 10pt)` to apply the same value to the remaining sides). Defaults to `5pt` (the `#table` default). @@ -652,6 +693,15 @@ Another example (summing columns): ## Changelog +### v0.0.9 + +**NOTE:** Please use Typst's built-in tables instead of tablex (starting with Typst 0.11.0). +Most of tablex's features were implemented in Typst's tables by the author of tablex. + +- Added compatibility with Typst v0.12.0 (https://github.com/PgBiel/typst-tablex/issues/135) +- Added library usage notice to README +- Tablex is now dual-licensed under MIT/Apache-2.0 (https://github.com/PgBiel/typst-tablex/issues/134) + ### v0.0.8 - Added `fit-spans` option to `tablex` and `cellx` (https://github.com/PgBiel/typst-tablex/pull/111) @@ -825,4 +875,4 @@ Initial release. ## License -MIT license (see the `LICENSE` file). +Tablex is licensed under MIT or Apache-2.0, at your option (see the files `LICENSE-MIT` and `LICENSE-APACHE`). diff --git a/tablex-test.typ b/tablex-test.typ index f2c5941..99cd03d 100644 --- a/tablex-test.typ +++ b/tablex-test.typ @@ -1,5 +1,7 @@ #import "tablex.typ": * +#let _style = if using-typst-v0110 { func => context(func(none)) } else { style } + *Test* test @@ -767,8 +769,8 @@ Combining em and pt (with a stroke object): columns: 2, [A #box(line(length: 50pt)) B], [A #line(length: 50pt) B], [C], [D], - style(styles => { - measure(line(length: 40pt), styles) + _style(styles => { + _measure(line(length: 40pt), styles) }), [E] ) @@ -776,8 +778,8 @@ Combining em and pt (with a stroke object): columns: 2, [A #box(line(length: 50pt)) B], [A #line(length: 50pt) B], [C], [D], - style(styles => { - measure(line(length: 40pt), styles) + _style(styles => { + _measure(line(length: 40pt), styles) }), [E] ) @@ -791,7 +793,7 @@ Combining em and pt (with a stroke object): frac-total: 10pt, ) = { set text(size: 1pt) // Set 1em to 1pt - style(styles => { + _style(styles => { let actual = convert-length-to-pt( len, styles: styles, @@ -864,7 +866,7 @@ Combining em and pt (with a stroke object): compare-repr: false, ) = { set text(size: 1pt) // Set 1em to 1pt - style(styles => { + _style(styles => { let actual = stroke-len( value, styles: styles, diff --git a/tablex.typ b/tablex.typ index dbcf6fc..1949079 100644 --- a/tablex.typ +++ b/tablex.typ @@ -1,6 +1,6 @@ // Welcome to tablex! // Feel free to contribute with any features you think are missing. -// Version: v0.0.8 +// Version: v0.0.9 // -- table counter -- @@ -35,6 +35,21 @@ // Attachments use "t" and "b" instead of "top" and "bottom" since v0.3.0. #let using-typst-v030-or-later = using-typst-v080-or-later or $a^b$.body.has("t") +#let using-typst-v090 = using-typst-v080-or-later and str(-1).codepoints().first() == "\u{2212}" +#let using-typst-v0110 = using-typst-v090 and sys.version >= version(0, 11, 0) + +// Polyfill for locate() when there is no context yet +#let _locate = if using-typst-v0110 { func => context(func(here())) } else { locate } + +// Polyfill for locate() when there is already context +#let _locate-inherit = if using-typst-v0110 { func => func(here()) } else { locate } + +// Polyfill for style() when there is already context +#let _style-inherit = if using-typst-v0110 { func => func((:)) } else { style } + +// Polyfill for measure(_, styles) +#let _measure = if using-typst-v0110 { (value, _) => measure(value) } else { measure } + // This is true if types have fields in the current Typst version. // This means we can use stroke.thickness, length.em, and so on. #let typst-fields-supported = using-typst-v080-or-later @@ -443,13 +458,13 @@ let em = len.em // Measure with abs (and later multiply by the sign) so negative em works. // Otherwise it would return 0pt, and we would need to measure again with abs. - let measured-em = calc-sign(em) * measure(box(width: calc.abs(em) * 1em), styles).width + let measured-em = calc-sign(em) * _measure(box(width: calc.abs(em) * 1em), styles).width return pt + measured-em } // Fields not supported, so we have to measure twice when em can be negative. - let measured-pt = measure(box(width: len), styles).width + let measured-pt = _measure(box(width: len), styles).width // If the measured length is positive, `len` must have overall been positive. // There's nothing else to be done, so return the measured length. @@ -462,7 +477,7 @@ // Hence, `len` must either be `0pt` or negative. // We multiply `len` by -1 to get a positive length, draw a line and measure it, then negate // the measured length. This nicely handles the `0pt` case as well. - measured-pt = -measure(box(width: -len), styles).width + measured-pt = -_measure(box(width: -len), styles).width return measured-pt } @@ -476,12 +491,6 @@ return len } - // At this point, we will need to draw a line for measurement, - // so we need the styles. - if styles == none { - panic("Cannot convert length to pt ('styles' not specified).") - } - return measure-pt(len, styles) } @@ -543,12 +552,6 @@ return convert-ratio-type-to-pt(len.ratio, page-size) + convert-length-type-to-pt(len.length, styles: styles) } - // We will need to draw a line for measurement later, - // so we need the styles. - if styles == none { - panic("Cannot convert relative length to pt ('styles' not specified).") - } - // Note on precision: the `repr` for em components is precise, unlike // other length components, which are rounded to a precision of 2. // This is true up to Typst 0.9.0 and possibly later versions. @@ -1258,7 +1261,6 @@ // calculate the size of auto columns (based on the max width of their cells) #let determine-auto-columns(grid: (), styles: none, columns: none, inset: none, align: auto, fit-spans: none, page-width: 0pt) = { - assert(styles != none, message: "Cannot measure auto columns without styles") let total_auto_size = 0pt let auto_sizes = () let new_columns = columns @@ -1319,7 +1321,7 @@ inset: cell_inset, align_default: auto ) - let width = measure(cell-box, styles).width// + 2*cell_inset // the box already considers inset + let width = _measure(cell-box, styles).width// + 2*cell_inset // the box already considers inset // here, we are excluding from the width of this cell // at this column all width that was already covered by @@ -1498,7 +1500,6 @@ // calculate the size of auto rows (based on the max height of their cells) #let determine-auto-rows(grid: (), styles: none, columns: none, rows: none, align: auto, inset: none, fit-spans: none) = { - assert(styles != none, message: "Cannot measure auto rows without styles") let total_auto_size = 0pt let auto_sizes = () let new_rows = rows @@ -1543,7 +1544,7 @@ // measure the cell's actual height, // with its calculated width // and with other constraints - let height = measure(cell-box, styles).height// + 2*cell_inset (box already considers inset) + let height = _measure(cell-box, styles).height// + 2*cell_inset (box already considers inset) // here, we are excluding from the height of this cell // at this row all height that was already covered by @@ -2027,11 +2028,11 @@ // NOTE: This function cannot differentiate between the actual page // and a possible box or block where the component using this function // could be contained in. -#let get-page-dim-writer() = locate(w_loc => { +#let get-page-dim-writer() = _locate(w_loc => { let table_id = _tablex-table-counter.at(w_loc) let page_dim_state = get-page-dim-state(table_id) - place(top + left, locate(loc => { + place(top + left, _locate(loc => { page_dim_state.update(s => { if s.top_left != none { s @@ -2044,7 +2045,7 @@ }) })) - place(bottom + right, locate(loc => { + place(bottom + right, _locate(loc => { page_dim_state.update(s => { if s.bottom_right != none { s @@ -2088,7 +2089,7 @@ let vlines = row-group.vlines let (start-y, end-y) = row-group.y_span - locate(loc => { + _locate(loc => { // let old_page = latest-page-state.at(loc) // let this_page = loc.page() @@ -2114,7 +2115,7 @@ if repeat-header != false { header-pages-state.update(l => l + (page,)) if (repeat-header == true) or (type(repeat-header) == _int-type and rel_page <= repeat-header) or (type(repeat-header) == _array-type and rel_page in repeat-header) { - let measures = measure(first-row-group.content, styles) + let measures = _measure(first-row-group.content, styles) place(top+left, first-row-group.content) // add header added_header_height = measures.height } @@ -2163,7 +2164,7 @@ dy: height-between(start: first_y, end: y) + added_header_height, cell_box.box) - // let box_h = measure(cell_box.box, styles).height + // let box_h = _measure(cell_box.box, styles).height // tallest_box_h = calc.max(tallest_box_h, box_h) } first_row = false @@ -2838,10 +2839,10 @@ let map-cols = validate-map-func(map-cols) let fit-spans = validate-fit-spans(fit-spans, default: (x: false, y: false)) - layout(size => locate(t_loc => style(styles => { + layout(size => _locate-inherit(t_loc => _style-inherit(styles => { let table_id = _tablex-table-counter.at(t_loc) let page_dimensions = get-page-dim-state(table_id) - let page_dim_at = page_dimensions.final(t_loc) + let page_dim_at = if using-typst-v0110 { page_dimensions.final() } else { page_dimensions.final(t_loc) } let t_pos = t_loc.position() // Subtract the max width/height from current width/height to disregard margin/etc. diff --git a/typst.toml b/typst.toml index 6fde0d6..d83edf4 100644 --- a/typst.toml +++ b/typst.toml @@ -1,8 +1,8 @@ [package] name = "tablex" -version = "0.0.8" +version = "0.0.9" authors = ["PgBiel