Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/preview/ascii-ipa/1.1.1/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Changelog of `ascii-ipa`

follows [semantic versioning][semver]

## 1.1.1

- Fixed a bug in X-SAMPA where ``` ` ``` falsely took precedence over ``` @` ``` (https://github.com/imatpot/typst-packages/issues/1)

## 1.1.0

- Translations will now return a [`string`][typst-string] if the font is not overridden
- The library now explicitly exposes functions via a "gateway" entrypoint
- Update internal project structure
- Update package metadata
- Update documentation

## 1.0.0

- Initial release

[semver]: https://semver.org
[typst-string]: https://typst.app/docs/reference/foundations/str/
21 changes: 21 additions & 0 deletions packages/preview/ascii-ipa/1.1.1/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 imatpot

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
93 changes: 93 additions & 0 deletions packages/preview/ascii-ipa/1.1.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# `ascii-ipa`

🔄 ASCII / IPA conversion for Typst

This package allows you to easily convert different ASCII representations of the International Phonetic Alphabet (IPA) to and from the IPA.
It also offers some minor utilities to make phonetic transcriptions easier to use overall.
The package is being maintained [here][repo].

Note: This is an extended port of the [`ipa-translate`][ipa-translate] Rust crate by [tirimid][tirimid]'s conversion features into native Typst.
Most conversions are implemented according to [this Wikipedia article][ipa-wikipedia] with the [following exceptions](#deviations-from-wikipedia).

## Conversion

The package supports multiple ASCII representations for the IPA with one function each:

| Notation | Function name |
|----------|-----------------|
| Branner | `#branner(...)` |
| Praat | `#praat(...)` |
| SIL | `#sil(...)` |
| X-SAMPA | `#xsampa(...)` |

They all return the converted value as either [`string`][typst-str] or [`content`][typst-content]* and accept the set of same parameters:

| Parameter | Type | Positional / Named | Default | Description |
|--------------------|-------------------------|--------------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `value` | [`string`][typst-str] | positional | | Main input to the function. Usually the transcription in the corresponsing ASCII-based notation. |
| `reverse` | [`boolean`][typst-bool] | named | `false` | Reverses the conversion. Pass Unicode IPA into `value` to get the corresponsing ASCII-based notation back. |
| `override-font`\* | [`boolean`][typst-bool] | named | `false` | Overrides the active font and forces rendering in Linux Libertine. Use this if your font has lackluster support for Unicode IPA. If set to `true`, the function will return [`content`][typst-content]. |

### Examples

All examples use the Russian word ⟨привет⟩ [prʲɪvʲet] for the conversion.

```typst
#import "@preview/ascii-ipa:1.1.1": *

// Branner
#branner("prj^Ivj^et") // prʲɪvʲet
#branner("prʲɪvʲet", reverse: true) // prj^Ivj^et

// Praat
#praat("pr\\^j\\icv\\^jet") // prʲɪvʲet
#praat("prʲɪvʲet", reverse: true) // pr\\^j\\icv\\^jet

// SIL
#sil("prj^i=vj^et") // prʲɪvʲet
#sil("prʲɪvʲet", reverse: true) // prj^i=vj^et

// X-SAMPA
#xsampa("pr_jIv_jet") // prʲɪvʲet
#xsampa("prʲɪvʲet", reverse: true) // pr_jIv_jet

// Font override
#xsampa("prj^Ivj^et", override-font: true) // prʲɪvʲet, but as content rendered in Linux Libertine
```

### Deviations from [Wikipedia][ipa-wikipedia]

Not everything could be implemented fully compliant with the information in the article.

- Branner
- `ts))` is represented as `t))s`
- SIL
- The only supported superscript characters are: `h` (`ʰ`), `j` (`ʲ`), `l` (`ˡ`), `n` (`ⁿ`), `w` (`ʷ`), `ɣ` (`ˠ`), `ʕ` (`ˤ`)

## Brackets & Braces

You can easily mark your notation text as phonetic, phonemic, orthographic, or prosodic.

```typst
#import "@preview/ascii-ipa:1.1.1": *

#phonetic("prʲɪˈvʲet") // [prʲɪˈvʲet]
#phnt("prʲɪˈvʲet") // [prʲɪˈvʲet]

#phonemic("prɪvet") // /prɪvet/
#phnm("prɪvet") // /prɪvet/

#orthographic("привет") // ⟨привет⟩
#orth("привет") // ⟨привет⟩

#prosodic("prʲɪˈvʲet") // {prʲɪˈvʲet}
#prsd("prʲɪˈvʲet") // {prʲɪˈvʲet}
```

[repo]: https://github.com/imatpot/typst-packages
[ipa-translate]: https://github.com/tirimid/ipa-translate
[tirimid]: https://github.com/tirimid
[ipa-wikipedia]: https://en.wikipedia.org/wiki/Comparison_of_ASCII_encodings_of_the_International_Phonetic_Alphabet
[typst-content]: https://typst.app/docs/reference/foundations/content/
[typst-str]: https://typst.app/docs/reference/foundations/str/
[typst-bool]: https://typst.app/docs/reference/foundations/bool/
1 change: 1 addition & 0 deletions packages/preview/ascii-ipa/1.1.1/ascii-ipa.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#import "src/lib.typ": branner, praat, sil, xsampa, phonetic, phnt, phonemic, phnm, orthographic, orth, prosodic, prsd
40 changes: 40 additions & 0 deletions packages/preview/ascii-ipa/1.1.1/src/lib.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#import "translations/branner.typ": *
#import "translations/praat.typ": *
#import "translations/sil.typ": *
#import "translations/xsampa.typ": *

#let apply-translations(content, translations, reverse) = {
let (from, to) = if reverse {( 1, 0 )} else {( 0, 1 )}

for translation in translations {
content = content.replace(translation.at(from), translation.at(to))
}

return content
}

#let translate(content, translations, reverse, override-font) = {
let translation = apply-translations(content, translations, reverse)

return if override-font {
set text(font: "Linux Libertine")
translation
} else {
translation
}
}

#let branner(content, reverse: false, override-font: false) = translate(content, branner-translations, reverse, override-font)
#let praat(content, reverse: false, override-font: false) = translate(content, praat-translations, reverse, override-font)
#let sil(content, reverse: false, override-font: false) = translate(content, sil-translations, reverse, override-font)
#let xsampa(content, reverse: false, override-font: false) = translate(content, xsampa-translations, reverse, override-font)

#let phonetic(content) = [[#content]]
#let phonemic(content) = [/#content/]
#let orthographic(content) = [⟨#content⟩]
#let prosodic(content) = [{#content}]

#let phnt = phonetic
#let phnm = phonemic
#let orth = orthographic
#let prsd = prosodic
182 changes: 182 additions & 0 deletions packages/preview/ascii-ipa/1.1.1/src/translations/branner.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
// adaptation of https://github.com/tirimid/ipa-translate/blob/master/translations/branner.rs

#let branner-translations = (
// vowels part 1.
("i-", "ɨ"),
("e&", "ɘ"),
("E&", "ɜ"),
("E\"", "ɞ"),
("a\"&", "ɒ"),
("a\"", "ɑ"),
("a&", "ɐ"),
("ae)", "æ"),
("c&", "ɔ"),
("o/)", "ø"),
("oe)", "œ"),
("OE)", "ɶ"),
("o-", "ɵ"),
("u-", "ʉ"),
("v&", "ʌ"),
("U\"", "ɤ"),
("m&", "ɯ"),
("xr^", "ɚ"),

// consonants part 1.
("tr)", "ʈ"),
("dr)", "ɖ"),
("j-", "ɟ"),
("m\"", "ɱ"),
("nr)", "ɳ"),
("nj)", "ɲ"),
("ng)", "ŋ"),
("r\"", "ɾ"),
("rr)", "ɽ"),
("P\"", "ɸ"),
("B\"", "β"),
("O-", "θ"),
("d-", "ð"),
("3\"", "ʒ"),
("sr)", "ʂ"),
("zr)", "ʐ"),
("c\"", "ç"),
("j\"", "ʝ"),
("g\"", "ɣ"),
("R%", "ʁ"),
("h-", "ħ"),
("?&", "ʕ"),
("h\"", "ɦ"),
("l-", "ɬ"),
("l3\")", "ɮ"),
("v\"", "ʋ"),
("r&", "ɹ"),
("jr)", "ɻ"),
("m&\"", "ɰ"),
("lr)", "ɭ"),
("y&", "ʎ"),
("b$", "ɓ"),
("d$", "ɗ"),
("j$", "ʄ"),
("g$", "ɠ"),
("G$", "ʛ"),
("w&", "ʍ"),
("h&", "ɥ"),
("?-", "ʡ"),
("?\"", "ʢ"),
("Sx)", "ɧ"),
("p!", "ʘ"),
("t!", "ǀ"),
("r!", "ǃ"),
("c!", "ǂ"),
("l!", "ǁ"),
("l\"", "ɺ"),
("ci)", "ɕ"),
("zi)", "ʑ"),
("l~)", "ɫ"),

// diacritics.
("`", "ʼ"),
("V)", "̥"),
("v)", "̬"),
("h^", "ʰ"),
("h\")", "̤"),
("~^", "̃"),
("~)", "̴"),
("~", "̰"),
("{", "̼"),
("[]", "̻"),
("[", "̪"),
("]", "̺"),
("u)", "̹"),
("U)", "̜"),
("+", "̟"),
("_", "̠"),
("\"^", "̈"),
("x^", "̽"),
("<", "̘"),
(">", "̙"),
("r^", "˞"),
("w^", "ʷ"),
("j^", "ʲ"),
("&g^", "ˤ"),
("g^", "ˠ"),
("n^", "ⁿ"),
("l^", "ˡ"),
(".)", "̚"),
("=\"", "̞"),
("=)", "͜"),
("=", "̝"),
(",)", "̩"),
("(", "̯"),

// not implemented according to description.
// branner describes this being placed after two segments: `ts))`.
// in this implementation, it is placed in the middle: `t))s`.
("))", "͡"),

("'", "ˈ"),
(",", "ˌ"),
(":", "ː"),
(";", "ˑ"),
("(^", "̆"),
(".", "."),
("||", "‖"),
("|", "|"),
("/)", "ꜛ"),
("\\)", "ꜜ"),
("/", "↗"),
("\\", "↘"),
("15", "̌"),
("51", "̂"),
("35", "᷄"),
("13", "᷅"),
("342", "᷈"),
("5", "̋"),
("4", "́"),
("3", "̄"),
("2", "̀"),
("1", "̏"),

// vowels part 2.
("i", "i"),
("e", "e"),
("E", "ɛ"),
("a", "a"),
("o", "o"),
("u", "u"),
("y", "y"),
("I", "ɪ"),
("Y", "ʏ"),
("U", "ʊ"),
("@", "ə"),

// consonants part 2.
("p", "p"),
("b", "b"),
("t", "t"),
("d", "d"),
("c", "c"),
("k", "k"),
("g", "ɡ"),
("q", "q"),
("G", "ɢ"),
("?", "ʔ"),
("m", "m"),
("n", "n"),
("N", "ɴ"),
("B", "ʙ"),
("r", "r"),
("R", "ʀ"),
("f", "f"),
("v", "v"),
("s", "s"),
("z", "z"),
("S", "ʃ"),
("x", "x"),
("X", "χ"),
("h", "h"),
("j", "j"),
("l", "l"),
("L", "ʟ"),
("w", "w"),
("H", "ʜ"),
)
Loading