aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2024-03-14 10:16:51 -0700
committerJohn MacFarlane <[email protected]>2024-03-14 10:16:51 -0700
commit876bd497868c4511e4463005062350c52324d22c (patch)
treec6feb1b5a9aa96e048f087ea2edb676acfb540f5
parentb2b04a2f1c787344d09740498a1ee0319d657b88 (diff)
Typst writer: add 'kind' parameter to figures.
This helps to distinguish tables from other figures for purposes of labeling and numbering. Closes #9574.
-rw-r--r--src/Text/Pandoc/Writers/Typst.hs40
-rw-r--r--test/tables.typst251
-rw-r--r--test/writer.typst3
3 files changed, 157 insertions, 137 deletions
diff --git a/src/Text/Pandoc/Writers/Typst.hs b/src/Text/Pandoc/Writers/Typst.hs
index c9df66f77..515f0bee7 100644
--- a/src/Text/Pandoc/Writers/Typst.hs
+++ b/src/Text/Pandoc/Writers/Typst.hs
@@ -175,26 +175,38 @@ blockToTypst block =
formatalign AlignCenter = "center,"
formatalign AlignDefault = "auto,"
let alignarray = parens $ mconcat $ map formatalign aligns
- return $ "#figure(" $$
- "align(center)[#table("
- $$ nest 2
- ( "columns: " <> text (show numcols) <> "," -- auto
- $$ "align: (col, row) => " <> alignarray <> ".at(col),"
- $$ "inset: 6pt" <> ","
- $$ hsep (map ((<>",") . brackets) headers')
- $$ vcat (map (\x -> brackets x <> ",") (concat rows'))
- )
- $$ ")]"
- $$ capt'
- $$ ")"
+ return $
+ "#figure("
+ $$
+ nest 2
+ ("align(center)[#table("
+ $$ nest 2
+ ( "columns: " <> text (show numcols) <> "," -- auto
+ $$ "align: (col, row) => " <> alignarray <> ".at(col),"
+ $$ "inset: 6pt" <> ","
+ $$ hsep (map ((<>",") . brackets) headers')
+ $$ vcat (map (\x -> brackets x <> ",") (concat rows'))
+ )
+ $$ ")]"
+ $$ capt'
+ $$ ", kind: table"
+ $$ ")")
$$ lab
$$ blankline
Figure (ident,_,_) (Caption _mbshort capt) blocks -> do
caption <- blocksToTypst capt
contents <- blocksToTypst blocks
let lab = toLabel FreestandingLabel ident
- return $ "#figure(" <> nest 2 (brackets contents <> "," <> cr <>
- ("caption: [" $$ nest 2 caption $$ "]"))
+ let kind = case blocks of
+ Table{}:_ -> "table"
+ CodeBlock{}:_ -> "code"
+ _ -> "auto"
+ return $ "#figure(" <> nest 2 ((brackets contents <> ",")
+ $$
+ ("caption: [" $$ nest 2 caption $$ "],")
+ $$
+ "kind: " <> literal kind
+ )
$$ ")" $$ lab $$ blankline
Div (ident,_,_) (Header lev ("",cls,kvs) ils:rest) ->
blocksToTypst (Header lev (ident,cls,kvs) ils:rest)
diff --git a/test/tables.typst b/test/tables.typst
index 46b3e7133..e84b7c41c 100644
--- a/test/tables.typst
+++ b/test/tables.typst
@@ -1,149 +1,156 @@
Simple table with caption:
#figure(
-align(center)[#table(
- columns: 4,
- align: (col, row) => (right,left,center,auto,).at(col),
- inset: 6pt,
- [Right], [Left], [Center], [Default],
- [12],
- [12],
- [12],
- [12],
- [123],
- [123],
- [123],
- [123],
- [1],
- [1],
- [1],
- [1],
-)]
-, caption: [Demonstration of simple table syntax.]
-)
+ align(center)[#table(
+ columns: 4,
+ align: (col, row) => (right,left,center,auto,).at(col),
+ inset: 6pt,
+ [Right], [Left], [Center], [Default],
+ [12],
+ [12],
+ [12],
+ [12],
+ [123],
+ [123],
+ [123],
+ [123],
+ [1],
+ [1],
+ [1],
+ [1],
+ )]
+ , caption: [Demonstration of simple table syntax.]
+ , kind: table
+ )
Simple table without caption:
#figure(
-align(center)[#table(
- columns: 4,
- align: (col, row) => (right,left,center,auto,).at(col),
- inset: 6pt,
- [Right], [Left], [Center], [Default],
- [12],
- [12],
- [12],
- [12],
- [123],
- [123],
- [123],
- [123],
- [1],
- [1],
- [1],
- [1],
-)]
-)
+ align(center)[#table(
+ columns: 4,
+ align: (col, row) => (right,left,center,auto,).at(col),
+ inset: 6pt,
+ [Right], [Left], [Center], [Default],
+ [12],
+ [12],
+ [12],
+ [12],
+ [123],
+ [123],
+ [123],
+ [123],
+ [1],
+ [1],
+ [1],
+ [1],
+ )]
+ , kind: table
+ )
Simple table indented two spaces:
#figure(
-align(center)[#table(
- columns: 4,
- align: (col, row) => (right,left,center,auto,).at(col),
- inset: 6pt,
- [Right], [Left], [Center], [Default],
- [12],
- [12],
- [12],
- [12],
- [123],
- [123],
- [123],
- [123],
- [1],
- [1],
- [1],
- [1],
-)]
-, caption: [Demonstration of simple table syntax.]
-)
+ align(center)[#table(
+ columns: 4,
+ align: (col, row) => (right,left,center,auto,).at(col),
+ inset: 6pt,
+ [Right], [Left], [Center], [Default],
+ [12],
+ [12],
+ [12],
+ [12],
+ [123],
+ [123],
+ [123],
+ [123],
+ [1],
+ [1],
+ [1],
+ [1],
+ )]
+ , caption: [Demonstration of simple table syntax.]
+ , kind: table
+ )
Multiline table with caption:
#figure(
-align(center)[#table(
- columns: 4,
- align: (col, row) => (center,left,right,left,).at(col),
- inset: 6pt,
- [Centered Header], [Left Aligned], [Right Aligned], [Default aligned],
- [First],
- [row],
- [12.0],
- [Example of a row that spans multiple lines.],
- [Second],
- [row],
- [5.0],
- [Here’s another one. Note the blank line between rows.],
-)]
-, caption: [Here’s the caption. It may span multiple lines.]
-)
+ align(center)[#table(
+ columns: 4,
+ align: (col, row) => (center,left,right,left,).at(col),
+ inset: 6pt,
+ [Centered Header], [Left Aligned], [Right Aligned], [Default aligned],
+ [First],
+ [row],
+ [12.0],
+ [Example of a row that spans multiple lines.],
+ [Second],
+ [row],
+ [5.0],
+ [Here’s another one. Note the blank line between rows.],
+ )]
+ , caption: [Here’s the caption. It may span multiple lines.]
+ , kind: table
+ )
Multiline table without caption:
#figure(
-align(center)[#table(
- columns: 4,
- align: (col, row) => (center,left,right,left,).at(col),
- inset: 6pt,
- [Centered Header], [Left Aligned], [Right Aligned], [Default aligned],
- [First],
- [row],
- [12.0],
- [Example of a row that spans multiple lines.],
- [Second],
- [row],
- [5.0],
- [Here’s another one. Note the blank line between rows.],
-)]
-)
+ align(center)[#table(
+ columns: 4,
+ align: (col, row) => (center,left,right,left,).at(col),
+ inset: 6pt,
+ [Centered Header], [Left Aligned], [Right Aligned], [Default aligned],
+ [First],
+ [row],
+ [12.0],
+ [Example of a row that spans multiple lines.],
+ [Second],
+ [row],
+ [5.0],
+ [Here’s another one. Note the blank line between rows.],
+ )]
+ , kind: table
+ )
Table without column headers:
#figure(
-align(center)[#table(
- columns: 4,
- align: (col, row) => (right,left,center,right,).at(col),
- inset: 6pt,
- [12],
- [12],
- [12],
- [12],
- [123],
- [123],
- [123],
- [123],
- [1],
- [1],
- [1],
- [1],
-)]
-)
+ align(center)[#table(
+ columns: 4,
+ align: (col, row) => (right,left,center,right,).at(col),
+ inset: 6pt,
+ [12],
+ [12],
+ [12],
+ [12],
+ [123],
+ [123],
+ [123],
+ [123],
+ [1],
+ [1],
+ [1],
+ [1],
+ )]
+ , kind: table
+ )
Multiline table without column headers:
#figure(
-align(center)[#table(
- columns: 4,
- align: (col, row) => (center,left,right,auto,).at(col),
- inset: 6pt,
- [First],
- [row],
- [12.0],
- [Example of a row that spans multiple lines.],
- [Second],
- [row],
- [5.0],
- [Here’s another one. Note the blank line between rows.],
-)]
-)
+ align(center)[#table(
+ columns: 4,
+ align: (col, row) => (center,left,right,auto,).at(col),
+ inset: 6pt,
+ [First],
+ [row],
+ [12.0],
+ [Example of a row that spans multiple lines.],
+ [Second],
+ [row],
+ [5.0],
+ [Here’s another one. Note the blank line between rows.],
+ )]
+ , kind: table
+ )
diff --git a/test/writer.typst b/test/writer.typst
index f7883a0e8..6ce17d339 100644
--- a/test/writer.typst
+++ b/test/writer.typst
@@ -783,7 +783,8 @@ From "Voyage dans la Lune" by Georges Melies (1902):
#figure([#box(width: 150.0pt, image("lalune.jpg"));],
caption: [
lalune
- ]
+ ],
+ kind: auto
)
Here is a movie #box(width: 20.0pt, image("movie.jpg")) icon.