├── adoc2typ ├── .typstrc.typ ├── adoc2docbook ├── docbook2typ ├── README.adoc └── sample.adoc /adoc2typ: -------------------------------------------------------------------------------- 1 | # last modified 2025-04-12 2 | # created 2023-11-05 3 | # Dorai Sitaram 4 | 5 | # convert argument adoc file a.adoc to typst file a.typ 6 | 7 | test $# -ne 1 && 8 | echo $0 requires precisely one argument && 9 | exit 1 10 | 11 | f=$1 12 | 13 | test ! -f $f && 14 | echo File $f not found && 15 | exit 1 16 | 17 | g=${f%.*} 18 | 19 | # first convert $f to $g.xml (Docbook), then 20 | # convert $g.xml to $g.typ (Typst) 21 | 22 | adoc2docbook $f 23 | docbook2typ $g.xml 24 | -------------------------------------------------------------------------------- /.typstrc.typ: -------------------------------------------------------------------------------- 1 | // created 2023-03-24 2 | // last modified 2025-04-11 3 | 4 | // To use, at head of document, have 5 | // 6 | // #import "/.typstrc.typ": * 7 | // #show: config 8 | // 9 | // Above assumes .typstrc.typ is in ~, and $TYPST_ROOT is ~ 10 | 11 | #let config(doc) = { 12 | set page("us-letter") 13 | set page(numbering: "1") 14 | set par(leading: 0.65em) 15 | set par(spacing: 0.65em) 16 | set par(first-line-indent: 1.5em) 17 | set par(justify: true) 18 | set math.mat(delim: "[") 19 | set math.vec(delim: "[") 20 | doc 21 | } 22 | -------------------------------------------------------------------------------- /adoc2docbook: -------------------------------------------------------------------------------- 1 | # last modified 2025-04-12 2 | # created 2025-03-31 3 | # Dorai Sitaram 4 | 5 | # convert adoc to docbook 6 | 7 | test $# -ne 1 && 8 | echo $0 requires precisely one argument && 9 | exit 1 10 | 11 | f=$1 12 | 13 | test ! -f $f && 14 | echo File $f not found && 15 | exit 1 16 | 17 | g=${f%.*} 18 | 19 | asciidoctor -b docbook $f 20 | 21 | # rewrite admonitions, as Pandoc strips them otherwise 22 | 23 | vi -es $g.xml <<'EOF' 24 | 25 | g//+1 s//\0CAUTION:<\/emphasis> / 26 | g//+1 s//\0IMPORTANT:<\/emphasis> / 27 | g//+1 s//\0NOTE:<\/emphasis> / 28 | g//+1 s//\0TIP:<\/emphasis> / 29 | g//+1 s//\0WARNING:<\/emphasis> / 30 | 31 | g/^<\/\?\%(caution\|important\|note\|tip\|warning\)>$/d 32 | 33 | w 34 | 35 | EOF 36 | -------------------------------------------------------------------------------- /docbook2typ: -------------------------------------------------------------------------------- 1 | # last modified 2025-04-12 2 | # created 2025-04-02 3 | # Dorai Sitaram 4 | 5 | test $# -ne 1 && 6 | echo $0 requires precisely one argument && 7 | exit 1 8 | 9 | f=$1 10 | 11 | test ! -f $f && 12 | echo File $f not found && 13 | exit 1 14 | 15 | g=${f%.*} 16 | 17 | pandoc -f docbook -t typst $f -o $g.typ 18 | 19 | # some cleanup 20 | 21 | vi -es $g.typ <<'EOF' 22 | 23 | 1s/^/#import "\/.typstrc.typ": *; #show: config\r/ 24 | 25 | g/^#quote(block: true)\[$/ .+1,/^\]$/-1 s/.*/%VERSE \0 \\/ 26 | 27 | %s/^%VERSE ```// 28 | g/^%VERSE #quote(block: true)\[/d 29 | g/^%VERSE \]/d 30 | 31 | %s/^%VERSE // 32 | 33 | %s/^\$\s\(.\+\)\s\$$/#v(0.5em)\r\0\r#v(0.5em)/ 34 | 35 | g/^\$\s.*\s\$$/ s/without/\\\r/g 36 | 37 | g/^```/ .-1s/^$/\r#v(0.5em)/ 38 | g/^```/ .+1s/^$/#v(0.5em)\r/ 39 | 40 | g/^#figure(/ .s/^/#v(0.5em)\r\0/ 41 | 42 | func! Close_figure() 43 | norm % 44 | s/$/\r#v(0.5em)/ 45 | endfunc 46 | 47 | g/^#figure(/ call Close_figure() 48 | 49 | w 50 | EOF 51 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | = adoc2typ 2 | 3 | `adoc2typ` converts an 4 | https://github.com/asciidoctor/asciidoctor[AsciiDoc] file to 5 | https://github.com/typst/typst[Typst]. 6 | 7 | We can then generate PDF from the Typst, and that may be a better 8 | option than existing methods for converting AsciiDoc to PDF. 9 | 10 | `adoc2typ` uses Asciidoctor to convert to Docbook, and 11 | https://pandoc.org[Pandoc] to convert Docbook to Typst, with some 12 | bash and batch-vi processing in the interstices. 13 | 14 | == Install 15 | 16 | Put the scripts `adoc2typ`, `adoc2docbook`, `docbook2typ` in your 17 | `PATH`. 18 | 19 | == Usage 20 | 21 | adoc2typ sample.adoc 22 | 23 | produces `sample.typ`. 24 | 25 | A file `.typstrc.typ` from `$TYPST_ROOT` is included at the head 26 | of `sample.typ`. You can either have this be an empty file or put 27 | in it whatever Typst macros you prefer. 28 | 29 | To convert the generated `sample.typ` to PDF: 30 | 31 | typst c sample.typ 32 | 33 | You may find that you need to spot-check `sample.typ` for stray 34 | spacing issues. 35 | 36 | Adoc files may include other adoc subfiles, images, math. The 37 | extension need not be `.adoc`. 38 | -------------------------------------------------------------------------------- /sample.adoc: -------------------------------------------------------------------------------- 1 | == A Sample Document 2 | :stem: 3 | 4 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. In venenatis 5 | ligula libero, nec cursus odio aliquet at. Donec in lorem et quam tempor 6 | fringilla nec vitae massa. Curabitur a lacus cursus, facilisis magna in, 7 | pretium turpis. Donec eu ante quis neque faucibus pellentesque. Aenean 8 | viverra arcu in nunc rutrum semper. 9 | 10 | == Image 11 | 12 | // image:crow.png[crow,scaledwidth=20.0%] 13 | image::t2p.png[crow,200, align=center] 14 | 15 | == Math 16 | 17 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean 18 | pellentesque dignissim lacus, vitae ultrices tellus gravida 19 | nec. 20 | 21 | stem:[(a + b)^2 = a^2 + 2ab + b^2 ] 22 | 23 | Donec felis lectus, iaculis nec sollicitudin in, 24 | iaculis ac eros. 25 | 26 | [.center] 27 | -- 28 | [stem] 29 | ++++ 30 | 31 | sum_(i=1)^n i^3=((n(n+1))/2)^2 \ 32 | 33 | 1 / sqrt(2 pi) int_(- infty)^infty e^(-x^2 // 2) dx = 1 \ 34 | 35 | E = m c^2 36 | 37 | ++++ 38 | -- 39 | 40 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. In 41 | lorem ante, venenatis vitae tincidunt non, tempus non 42 | sapien. Fusce et efficitur orci, vitae gravida 43 | turpis. Morbi ornare, felis maximus pellentesque varius, magna 44 | est accumsan nisi, et tempor turpis libero ut neque. Nam non 45 | risus vel nisl tincidunt pretium. Aenean tempus nulla mi, at 46 | sollicitudin ex vestibulum vestibulum. 47 | 48 | == Code 49 | 50 | Vestibulum luctus vulputate lectus ut consectetur. A definition 51 | of `fact` using `define` and `if`: 52 | 53 | (define (fact n) 54 | (if (= n 0) 1 55 | (* n (fact (- n 1))))) 56 | 57 | Donec mattis scelerisque ipsum. Interdum 58 | et malesuada fames ac ante ipsum primis in faucibus. Donec gravida est 59 | pulvinar ante mattis, id porta magna ultrices. Etiam sit amet rutrum 60 | arcu, quis tempor turpis. Suspendisse potenti. Sed vel eleifend turpis, 61 | quis imperdiet urna. Aliquam dictum ultricies sem ut rutrum. Integer in 62 | mauris quam. 63 | 64 | == Table 65 | 66 | [%autowidth,cols="<,>,>,>"] 67 | |=== 68 | | type | original | remaining | % gone 69 | 70 | | humpbacks | 100,000 | 3,000 | 97.0 71 | | fin whales | 400,000 | 2,000 | 99.5 72 | | seis | 150,000 | 1,500 | 99.0 73 | | blue whales | 180,000 | 660 | 99.6 74 | |=== 75 | 76 | ⏹ 77 | --------------------------------------------------------------------------------