let pages = labels.map((text) =>match (BigInt.parse(text, 10)) {
case Some(number) => number.toInt()
case None() => None()
})
io.writeLine("{pages}")
Expected output
[Some(12), None, Some(14)]
map goes after the list. BigInt.parse reads each string, and toInt converts a parsed number. The entry for “cover” becomes None.
Who, for what
Built for these teams
From manuscript to pages
Teams building a book typesetting engine
Build an engine that takes a manuscript and decides where lines and pages fall. Paragraph breaking and the Korean, Japanese and Chinese line-break rules come from the standard library. The same line-breaking code runs in the browser preview and in print composition.
Per-book decisions in rule files
Teams whose rules differ by publisher
Publisher decisions such as where a chapter starts live in Lispex rule files. When each client wants its own style, the line-breaking app code stays the same.
Data handling inside a web app
Teams building web tools
Write a function that handles input in Topaz, build it as a browser package and call it from JavaScript. The browser tools on jeni.kr work this way.
std.typeset
Typesetting in the standard library
std.typeset in Topaz 6.0 is the standard module that breaks paragraphs into lines. The program below sets one Korean sentence at a width of ten Hangul syllables. Looking at the whole paragraph keeps a lone word off the last line.
io.writeLine("Line by line\n{linesOf(clusters, plans.greedy)}")
}
case Err(error) => io.writeLine("{error}")
}
Expected output
Whole paragraph
문단 전체를 보고
줄을 나누면 마지막
줄이 짧게 남지
않고 줄마다 길이가
고르게 됩니다.
Line by line
문단 전체를 보고 줄을
나누면 마지막 줄이
짧게 남지 않고 줄마다
길이가 고르게
됩니다.
Paragraph breaking
Get the breaks chosen for the whole paragraph together with a greedy, line-by-line result. Choose the Knuth-Plass cost model or a fixed-point cost model.
Unicode line breaking
Find break opportunities with the Unicode 16.0 line breaking algorithm (UAX #14).
Rules for each locale
Add the Korean (KLReq), Japanese (JLReq), or Chinese (CLReq) rules, and an opening bracket never ends a line while a closing bracket or period never starts one. The Japanese rules follow the JLReq character classes.
East Asian width
The Unicode East Asian Width property decides breaks around quotation marks and brackets next to CJK text.
Spacing
Set how far justification may stretch or shrink the space between Latin words, and how far it may stretch the space between CJK characters.
Length units
Write lengths such as 12pt, 3mm, 1cm, 1in, and 1em directly in code and convert between units.
ATLAS turns a manuscript into print-ready book pages. Here is a page it set, with two of its line-breaking predicates rewritten for Topaz 6.0. ATLAS names these functions with Korean typesetting terms, shown here in English.
Common tasks have one way to write them. Whether a person or an agent writes the code, it takes the same shape, so a review only has to follow what the code does.
One way to write it
Converting a number to text and collection operations are methods on the value. Use map on an array and toString on a number. Format the source with topaz fmt.
A value that may be missing is an Option, an operation that may fail returns a Result, and cleanup is written with defer. At the end of a paragraph there is no next character, so a line-break rule receives None rather than an error.
Put a fixed set of cases, such as line-break classes, in an enum, and the compiler checks that each match handles every one. When you add a case later, the build reports each match that does not handle it yet.
An int is a signed 64-bit integer, and overflow stops the program at that point instead of continuing with a wrong value. When you measure line widths and layout costs in integers, an overflow cannot hide in the result.
Direct runs, native executables and browser packages follow the same language rules. So the on-screen preview and the print layout break lines at the same places.
Computing such as line breaking happens in Topaz code. Decisions that change with each publisher and book, such as which page a chapter starts on or how many lines may stand alone, go into separate Lispex rules. Topaz 6.0 runs Lispex 2.0 rules through std.lispex with separate limits for preparation, value conversion and evaluation. Change a rule source and prepare it again, and the same manuscript takes another style without any change to the application code.
Rules never touch files, the system clock, or the network.
A rule stops where it runs past its limit.
The same rule, input, and settings give the same decision every time.
Break a paragraph into lines with std.typeset. Set widths such as 12pt or 3mm, the line breaking rules of each language, and the spacing of justified lines.