File size: 76,675 Bytes
fdbb2bf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 | #let rtext(content)={
text(fill: red,content)
}
#let btext(content)={
text(fill: blue,content)
}
= 文本库(Text)<text_type>
文本样式。
文本功能尤为值得关注。
== 高亮文本(highlight)<highlight>
用背景色高亮文本。
=== 示例(Example)
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typst
This is #highlight[important].
```
],[
#set align(horizon)
#image("images/4001.png",width: auto)
]
)
=== 参数(Parameters)
```typc
highlight(
fill: none color gradient tiling,
stroke: none length color gradient stroke tiling dictionary,
top-edge: length str,
bottom-edge: length str,
extent: length,
radius: relative dictionary,
body:content,
) → content
```
- *fill*: none or color or gradient or tiling
用于高亮文本的颜色。默认值:```typc rgb("#fffd11a1")```
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typst
This is #highlight(
fill: blue
)[highlighted with blue].
```
],[
#set align(horizon)
#image("images/4002.png",width: auto)
]
)
- *stroke*:none length color gradient stroke tiling dictionary
高亮部分的边框颜色。更多详情请参阅#link(<rect_stroke>)[矩形组件]的文档。默认值:( : )。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typst
This is a #highlight(
stroke: fuchsia
)[stroked highlighting].
```
],[
#set align(horizon)
#image("images/4003.png",width: auto)
]
)
- *top-edge*: length str
背景矩形的顶端。默认值:```typc "ascender"```。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typst
#set highlight(top-edge: "ascender")
#highlight[a] #highlight[aib]
#set highlight(top-edge: "x-height")
#highlight[a] #highlight[aib]
```
],[
#set align(horizon)
#image("images/4004.png",width: auto)
]
)
#table(
columns: (0.5fr,1.5fr),
stroke: none,
align: left,
table.header([Variant],[Details]),
table.hline(),
[\"ascender\"],[字体的升部,通常会超出所有字形的高度。],
[\"cap-height\"],[大写字母的近似高度。],
[\"x-height\"],[非升部小写字母的近似高度。],
[\"baseline\"],[字母赖以放置的基线。],
[\"bounds\"],[字形边界框的上边缘。]
)
- *bottom-edge*: length str
背景矩形的底端。默认值:```typc "descender"```。
#table(
columns: 1fr,
align: left,
stroke: none,
[
```typst
#set highlight(bottom-edge: "descender")
#highlight[a] #highlight[ap]
#set highlight(bottom-edge: "baseline")
#highlight[a] #highlight[ap]
```
],
[
#set quote(block: true)
#show quote: set align(center)
#rect(
fill: luma(240),
width: 100%,
height: auto,
quote[
#image("images/4005.png",width: 80%)
]
)
]
)
#table(
columns: (0.5fr,1.5fr),
stroke: none,
align: left,
table.header([Variant],[Details]),
table.hline(),
[\"baseline\"],[字母所在的基线。],
[\"descender\"],[该字体的下行延伸部分,通常超过所有字形的下沉深度。],
[\"bounds\"],[字形边界框的底边。]
)
- *extent*: length
向两侧延伸背景的距离;若数值为负,则代表向内容内部收缩。默认值:#text(fill: red,"0pt")。
#table(
columns: 1fr,
align: left,
stroke: none,
[
```typst
A long #highlight(extent: 4pt)[background].
```
],
[
#set quote(block: true)
#show quote: set align(center)
#rect(
fill: luma(240),
width: 100%,
height: auto,
quote[
#image("images/4006.png",width: 80%)
]
)
]
)
- *radius*: relative dictionary
高亮区域圆角的弧度大小。更多详情请参阅矩形相关文档。默认值:( : )。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typst
Listen #highlight(
radius: 5pt, extent: 2pt
)[carefully], it will be on the test.
```
],[
#set align(horizon)
#image("images/4007.png",width: auto)
]
)
- *body*: content
需要突出显示的内容。
== 换行(linebreak)<linebreak>
插入换行符。
将段落切换至下一行。段落末尾单个尾随换行符会被忽略,但多个换行符会生成额外空行。
=== 示例(Example)
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typst
*Date:* 26.12.2022 \
*Topic:* Infrastructure Test \
*Severity:* High \
```
],[
#set align(horizon)
#image("images/4008.png",width: auto)
]
)
=== 语法(Syntax)
该函数还有专用语法:如需插入换行,只需输入反斜杠后接空白字符。该方式生成的换行始终为非对齐换行。
=== 参数(Parameters)
```typc
linebreak(justify:bool) → content
```
- *justify*: bool
是否对断行前的文本进行两端对齐。默认值:#text(fill: red,"false")。
如果你在两端对齐文本中找到了比Typst自动判定更合适的断行位置,该选项会很有用。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typst
#set par(justify: true)
#let jb = linebreak(justify: true)
I have manually tuned the #jb
line breaks in this paragraph #jb
for an _interesting_ result. #jb
```
],[
#set align(horizon)
#image("images/4009.png",width: auto)
]
)
== Lorem(lorem)<lorem>
生成占位文本。
该函数可生成类拉丁文的乱数占位文本,单词数量由用户指定。函数生成的单词序列固定,但单词是随机选取的。和常规占位文本一样,文本本身没有实际含义。可将其作为占位内容,用于测试页面布局。
=== 示例(Example)
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typst
= Blind Text
#lorem(30)
= More Blind Text
#lorem(15)
```
],[
#set align(horizon)
#image("images/4010.png",width: auto)
]
)
=== 参数(Parameters)
```typc
lorem(words:int) → str
```
- *words*: int
盲文本的单词数量。
== Lower(lower)<lower>
将字符串或内容转换为小写。
=== 示例(Example)
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typst
#lower("ABC") \
#lower[*My Text*] \
#lower[already low]
```
],[
#set align(horizon)
#image("images/4011.png",width: auto)
]
)
=== 参数(Parameters)
```typc
lower(text:str content) → strcontent
```
- *text*: str or content
要转换为小写的文本。
== Overline(overline)<overline>
为文本添加上划线。
=== 示例(Example)
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typst
#overline[A line over text.]
```
],[
#set align(horizon)
#image("images/4012.png",width: auto)
]
)
=== 参数(Parameters)
```typc
overline(
stroke: auto length color gradient stroke tiling dictionary,
offset: auto length,
extent: length,
evade: bool,
background: bool,
body:content,
) → content
```
- *stroke*: auto length color gradient stroke tiling dictionary
如何描边。默认值:#rtext()[auto]。
如果设置为自动,则采用文本的颜色以及当前字体所定义的粗细。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typst
#set text(fill: olive)
#overline(
stroke: green.darken(20%),
offset: -12pt,
[The Forest Theme],
)
```
],[
#set align(horizon)
#image("images/4013.png",width: auto)
]
)
- *offset*: auto length
该线条相对于基线的位置。若为自动,则从字体表读取。默认值:#rtext()[auto]。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typst
#overline(offset: -1.2em)[
The Tale Of A Faraway Line II
]
```
],[
#set align(horizon)
#image("images/4014.png",width: auto)
]
)
- *extent*: length
需要将线条延伸超出内容的距离(若为负值,则向内容内部延伸)。默认值:#rtext()[0pt]。
#table(
columns: 1fr,
align: left,
stroke: none,
[
```typst
#set overline(extent: 4pt)
#set underline(extent: 4pt)
#overline(underline[Typography Today])
```
],
[
#set quote(block: true)
#show quote: set align(center)
#rect(
fill: luma(240),
width: 100%,
height: auto,
quote[
#image("images/4015.png",width: 80%)
]
)
]
)
- *evade*: bool
该行是否会跳过会与字形发生碰撞的区域。默认值:#rtext()[true]。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typst
#overline(
evade: false,
offset: -7.5pt,
stroke: 1pt,
extent: 3pt,
[Temple],
)
```
],[
#set align(horizon)
#image("images/4016.png",width: auto)
]
)
- *background*: bool
该线条是否放置在其上划线内容的后方。默认值:#rtext()[false]。
#table(
columns: 1fr,
align: left,
stroke: none,
[
```typst
#set overline(stroke: aqua + 5pt)
#overline(background: true)[Fully visible.] \
#overline(background: false)[Partially hidden.]
```
],
[
#set quote(block: true)
#show quote: set align(center)
#rect(
fill: luma(240),
width: 100%,
height: auto,
quote[
#image("images/4017.png",width: 80%)
]
)
]
)
- *body*: content
需要在上方添加线条的内容。
== 原始文本/代码(Raw Text / Code)<raw>
带有可选语法高亮的原始文本。
以等宽字体原样展示文本。这通常用于在文档中嵌入计算机代码。
传递给该元素的文本会忽略标记语法,例如*加粗*或_斜体_,并原样显示。如果你希望使用等宽字体展示内容,同时保留标记语法,不要使用原始文本模式,你可以通过 #link(<text_font>)[text.font]
参数将文本字体显式设置为等宽字体。
原始元素主要通过#link(<raw_Syntax>)[专用语法]生成:在文本两侧使用单个反引号(\`)或三个及以上反引号包裹文本。当使用三个或更多反引号时,紧跟起始反引号后的文本会被视为用于语法高亮的#link(<raw_lang>)[语言标记],原始文本则从第一个空白字符之后开始。
=== 示例(Example)
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typst
Adding `rbx` to `rcx` gives
the desired result.
What is ```rust fn main()``` in Rust
would be ```c int main()``` in C.
```rust
fn main() {
println!("Hello World!");
}
```
This has ``` `backticks` ``` in it
(but the spaces are trimmed). And
``` here``` the leading space is
also trimmed.
```
],[
#set align(horizon)
#image("images/4018.png",width: auto)
]
)
你也可以通过代码从字符串构建原生元素(并可通过可选的 #link(<raw_lang>)[lang] 参数提供语言标签)。
#table(
columns: 1fr,
align: left,
stroke: none,
[
```typst
#raw("fn " + "main() {}", lang: "rust")
```
],
[
#set quote(block: true)
#show quote: set align(center)
#rect(
fill: luma(240),
width: 100%,
height: auto,
quote[
#image("images/4019.png",width: 80%)
]
)
]
)
如果你的指定语言标签默认没有可用的语法高亮(或者你想要覆盖内置定义),你可以向语法参数提供自定义语法规范文件。
=== 风格(Styling)<raw_Styling>
风默认情况下,原始元素使用 DejaVu Sans Mono 字体(Typst自带),字号设为更小的 0.8em(即全局字号的80%)。这是因为等宽字体在视觉上通常比非等宽字体更大。
你可以通过show-set规则来自定义这些属性:
```typc
// Switch to Cascadia Code for both
// inline and block raw.
#show raw: set text(font: "Cascadia Code")
// Reset raw blocks to the same size as normal text,
// but keep inline raw at the reduced size.
#show raw.where(block: true): set text(1em / 0.8)
Now using the `Cascadia Code` font for raw text.
Here's some Python code. It looks larger now:
```
```py
def python():
return 5 + 5
```
#figure(
table(
columns: 1,
align: center,
stroke: none,
fill: luma(240),
[
#image("images/4020.png",width: 80%)
]
)
)
此外,你可以通过 #link(<raw_theme>)[theme] 参数设置自定义主题,来定制语法高亮颜色。
如果要对原始代码块的外观进行完整自定义,可以使用 raw.line 的显示规则,例如添加行号。
请注意,在原始文本中,#link(<text_hyphenate>)[断字]、#link(<text_overhang>)[悬挂缩进]、#link(<text_cjk-latin-spacing>)[中日韩文字与拉丁文字间距]等排版特性,(对于原始代码块而言)#link(<Paragraph_justify>)[两端对齐功能]默认将被禁用。
=== 语法(Syntax)<raw_Syntax>
该函数提供专用语法,可在标记模式与代码模式下生成原始文本元素。你可以在文本两侧使用一个或三个及以上反引号(\`)将其包裹,从而转为原始文本。两侧反引号数量必须保持一致,且被包裹的文本内部不能连续出现同等数量的反引号。仅输入两个反引号(\`\`)会生成空原始文本。
与Markdown的显著区别包括:单个反引号包裹的文本可以跨多行,并且不会移除缩进;而三个及以上反引号语法在行内使用时,仍然会解析语言标签。
用单个反引号包裹的原始文本无法指定语言标签,始终作为行内元素放在段落内,也就是#link(<raw_block>)[块参数]为#rtext()[false]。
#set par(hanging-indent: 1.3cm)
使用三个或更多反引号的原始语法具备以下特性:
-- *在起始反引号之后,原始块仅会被数量相同的一串反引号终止。*\
若要在内容中包含一串反引号,首尾使用的反引号数量必须比该串反引号至少多一个。
-- *如果原始文本包含换行,则为块级元素;否则为行内元素。*\
这会相应地将#link(<raw_block>)[块参数]设置为#rtext()[true]或#rtext()[false]。
-- *起始反引号之后、首个空白字符之前的文本,会被当作用于语法高亮的语言标签。*\
判定哪些文本可作为语言标签的具体规则计划进行调整,#link(<raw_Language-tag-changes>)[详细说明见下文]。
-- *首行与末行拥有特殊的裁剪规则*\
对于首行:如果起始反引号或语言标签之后全部都是空白字符,则整行都会被裁剪。但如果该行存在非空白字符,那么仅会裁剪起始反引号或语言标签之后紧邻的单个空格(若存在)。
如果末行到结束反引号为止全部为空白字符,则该行会被裁剪。反之,若末行最后一个非空白字符是反引号,那么会从该行末尾裁剪掉一个空格(若存在)。
-- *各行开头共有的缩进会被裁剪*\
Typst 会移除原始文本所有行开头共有的空白字符,也就是公共缩进。起始反引号所在行除外。\
Typst首先找到包含非空白字符且开头空白字符数量最少的行(包含结束反引号所在行)。然后 Typst 对每一行都裁剪对应数量的开头空白字符。纯空白行也会移除同等数量字符直至该行清空,但会保留末尾多余的空白字符。\
请注意,为简化处理,该检查将制表符和空格视为等价字符,并且它基于#link("https://www.unicode.org/glossary/#code_point")[Unicode码点]数量(即字符数量)进行处理,而非字节长度。
#set par(hanging-indent: 0cm)
三反引号语法的这些特性支持一些不太直观的使用场景:
#set par(hanging-indent: 1.3cm)
-- 若要书写包含连续反引号的文本,使用比该序列数量更多的反引号将其包裹:\`\`\`\` enclosed\`\`\`backticks\`\`\`\`
-- 若要书写以反引号开头或结尾的文本,在首尾反引号内侧添加空格:\`\`\` \`backticks\` \`\`\`
-- 若要书写带语言标签的行内高亮文本,在语言标签与文本之间添加空格:\`\`\`rust #rtext()[fn] main() {}\`\`\`
-- 若要书写不带任何语言标签的行内文本,在起始反引号后添加空格:\`\`\` text\`\`\`,也可以使用单反引号语法:\`text\`
#set par(hanging-indent: 0cm)
*使用原始语法嵌入字符串*(*Embedding strings with raw syntax*)
原始语法的一个常见用例是:通过访问原始内容的.textfield来获取底层字符串,从而将带格式的数据嵌入为字符串。这也可以配合字节构造函数,把字符串转换为字节。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typst
An inline YAML dictionary via `.text`
#yaml(bytes(
```yaml
Magic:
limited-by: Mana
Pokémon:
limited-by: Energy
Yu-Gi-Oh:
limited-by: false
```text
// ^^^^ used as a string
))
```
],[
#set align(horizon)
#image("images/4021.png",width: auto)
]
)
*语言标签变更(Language tag changes)*<raw_Language-tag-changes>
在使用三个或更多反引号的原始代码语法时,起始反引号之后紧跟的文本(直到第一个空白字符为止)会被视作#link(<raw_lang>)[语言标签]。但在当前版本的 Typst 中,只有符合 Typst
标识符规范的文本才会被识别为语言标签。第一个不属于合法标识符的字符,会被当作原始文本的起始。
例如,在当前版本的 Typst 中,如果一个原始代码块以 C++ 开头,标识符 C 会作为语言标签,而原始文本从 ++ 开始。如果原始代码块以 ++C 开头,则不会设置语言标签,原始文本直接从 ++C 开始。
若要在当前版本 Typst 中使用不符合标识符规范的语言标签,必须使用 #link(<raw_lang>)[lang] 参数:既可以通过构造函数传入字符串调用:```typst #raw("text", lang: "...")```,也可以使用 set 规则:```typ #set raw(lang: "...")```。
在下一个版本的 Typst 中,到第一个空白字符或反引号之前的全部文本都会被当作语言标签,语言标签支持的字符集更广。包含空格或反引号的标签,仍然需要通过 #link(<raw_lang>)[lang] 参数手动设置。
如果你的原始代码块在下一版 Typst 中的解析逻辑会发生变化,Typst 会发出警告提示你。
=== 参数(Parameters)
```typc
raw(
text:str,
block: bool,
lang: none str,
align: alignment,
syntaxes: str path bytes array,
theme: none auto str path bytes,
tab-size: int,
) → content
```
- *text*: str<raw_text>
原始文本。
你也可以创造性地使用原始代码块,为自动化操作创建自定义语法。
#table(
columns: 1fr,
align: left,
stroke: none,
[
```typst
// Parse numbers in raw blocks with the
// `mydsl` tag and sum them up.
#show raw.where(lang: "mydsl"): it => {
let sum = 0
for part in it.text.split("+") {
sum += int(part.trim())
}
sum
}
```
```mydsl
1 + 2 + 3 + 4 + 5
```
],
[
#set quote(block: true)
#show quote: set align(center)
#rect(
fill: luma(240),
width: 100%,
height: auto,
quote[
#image("images/4022.png",width: 80%)
]
)
]
)
- *block*: bool<raw_block>
原始文本是否作为独立块展示。默认值:#rtext()[false]。
在标记模式下,使用单反引号写法时该选项为否。若使用三反引号写法,当包裹内容至少包含一处换行时,该选项为是。
#table(
columns: 1fr,
align: left,
stroke: none,
[
```typst
// Display inline code in a small box
// that retains the correct baseline.
#show raw.where(block: false): box.with(
fill: luma(240),
inset: (x: 3pt, y: 0pt),
outset: (y: 3pt),
radius: 2pt,
)
// Display block code in a larger block
// with more padding.
#show raw.where(block: true): block.with(
fill: luma(240),
inset: 10pt,
radius: 4pt,
)
With `rg`, you can search through your files quickly.
This example searches the current directory recursively
for the text `Hello World`:
```
\`\`\`bash
rg "Hello World"
\`\`\`
],
[
#set quote(block: true)
#show quote: set align(center)
#rect(
fill: luma(240),
width: 100%,
height: auto,
quote[
#image("images/4023.png",width: 80%)
]
)
]
)
- *lang*: none str<raw_lang>
用于语法高亮解析原始文本的语言。默认值:#rtext()[none]。
在HTML导出时,该选项会设置生成的html.code元素的data-lang属性。
除了Markdown中常见的语言标签外,还支持用于#link(<Syntax_Markup>)[Typst标记]、#link(<Syntax_Code_mode>)[Typst代码]和#link(<Syntax_Math_mode>)[Typst数学公式]的标签,分别为\"typ\"、\"typc\"以及\"typm\"。
#table(
columns: 1fr,
align: left,
stroke: none,
[
```typ
This is *Typst!*
```
This is ```typ also *Typst*```, but inline!
],
[
#set quote(block: true)
#show quote: set align(center)
#rect(
fill: luma(240),
width: 100%,
height: auto,
quote[
#image("images/4024.png",width: 80%)
]
)
]
)
- *align: alignment*<raw_align>
原始块中每一行应采用的水平对齐方式。如果当前不是原始块(设置了 block: false,或在标记模式中使用了单个反引号),该选项会被忽略。默认值:start。
默认值为 start,即默认情况下原始文本沿块内文本方向的起始端对齐,不受当前上下文对齐方式影响(例如,这允许你将原始块整体居中,而不把块内的文本也居中)。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typst
#set raw(align: center)
```typc
let f(x) = x
code = "centered"
```
```
],[
#set align(horizon)
#image("images/4025.png",width: auto)
]
)
- *syntaxes*: str path bytes array<raw_syntaxes>
要加载的附加语法定义。语法定义需采用 sublime-syntax 文件格式。
你可以传入以下任意类型的值:\
#set par(hanging-indent: 1cm)
-- 用于加载语法文件的路径字符串或#link(<Path>)[路径]。\
-- 可从中解码出语法的原始字节。\
-- 一个数组,数组内每一项为上述类型之一。
#set par(hanging-indent: 0cm)
#table(
columns: 1fr,
align: left,
stroke: none,
[
```typ
#set raw(syntaxes: "SExpressions.sublime-syntax")
```
```sexp
(defun factorial (x)
(if (zerop x)
; with a comment
1
(\* x (factorial (- x 1)))))
```
],
[
#set quote(block: true)
#show quote: set align(center)
#rect(
fill: luma(240),
width: 100%,
height: auto,
quote[
#image("images/4026.png",width: 80%)
]
)
]
)
- *theme: none auto str path bytes*<raw_theme>
用于语法高亮的主题。主题需采用 tmTheme 文件格式。默认值:#rtext()[auto]。
你可以传入以下任意值:\
#set par(hanging-indent: 1cm)
-- #rtext()[none]:禁用语法高亮。\
-- #rtext()[auto]:使用 Typst 默认主题进行高亮。\
-- 路径字符串,即加载主题文件的#link(<Path>)[路径]。\
-- 用于解码主题的原始字节数据。
#set par(hanging-indent: 0cm)
应用主题仅会影响被专门高亮文本的颜色。它不会读取主题的前景色与背景色属性,因此你可以自主控制普通文本的颜色。你可以通过 #rtext()[text] 函数自行设置前景色,通过#link(<block_fill>)[填充块]设置背景色,也可以使用 xml 函数从主题文件中提取这些属性。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set raw(theme: "halcyon.tmTheme")
#show raw: it => block(
fill: rgb("#1d2433"),
inset: 8pt,
radius: 5pt,
text(fill: rgb("#a2aabc"), it)
)
= Chapter 1
#let hi = "Hello World"
```
],[
#set align(horizon)
#image("images/4027.png",width: auto)
]
)
- *tab-size*: int
制表位的空格宽度。一个制表符会替换为足量空格,以对齐到该宽度的下一个整数倍位置。默认值:#rtext()[2]。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set raw(tab-size: 8)
#set par(first-line-indent: 0cm)
```
#set par(first-line-indent: 0cm)
\`\`\`tsv\
Year Month Day\
2000 2 3\
2001 2 1\
2002 3 10\
\`\`\`
],[
#set align(horizon)
#image("images/4028.png",width: auto)
]
)
=== 定义(Definitions)
- line<raw_line>
一行高亮的原始文本。
这是由原始元素合成的辅助元素。
它允许你获取该行的各类属性,例如行号、未高亮的原始文本、高亮文本,以及它是否为原始代码块的首行或末行。
```typc
raw.line(
number:int,
count:int,
text:str,
body:content,
) → content
```
#set par(hanging-indent: 1cm)
-- *number*: int
原始代码块内原始行的行号,从1开始。
-- *count*: int
原始代码块中的总行数。
-- *body*: content
高亮的原始文本。
#set par(hanging-indent: 0cm)
== 小型大写字母(smallcaps)<smallcaps>
以小型大写字母显示文本。
=== 示例(Example)
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
Hello \
#smallcaps[Hello]
```
#set par(first-line-indent: 0cm)
],[
#set align(horizon)
#image("images/4029.png",width: auto)
]
)
=== 小写大写字体(Smallcaps fonts)<smallcaps_fonts>
默认情况下,该功能会使用字体上的smcp与c2sc OpenType特性。并非所有字体都支持这些特性。有时小型大写字母会作为独立字体的一部分存在,例如拉丁现代字体家族就是如此。在这类场景下,你可以使用show-set规则自定义小型大写字母文本的显示效果:
```typ
#show smallcaps: set text(font: "Latin Modern Roman Caps")
```
未来,该功能将支持从普通字母合成小型大写字母,但此功能尚未实现。
=== 小型大写字母标题(Smallcaps headings)<smallcaps_headings>
你可以使用显示规则为所有标题应用小型大写字母格式。在下面的示例中,我们还将标题设置为居中对齐,并取消默认的粗体字体。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set par(justify: true)
#set heading(numbering: "I.")
#show heading: smallcaps
#show heading: set align(center)
#show heading: set text(
weight: "regular"
)
= Introduction
#lorem(40)
```
],[
#set align(horizon)
#image("images/4030.png",width: auto)
]
)
=== 参数(Parameters)<smallcaps_Parameters>
```typc
smallcaps(
all: bool,
body:content,
) → content
```
- *all*: bool
是否同时将大写字母转为小型大写字母。默认值:#rtext()[false]。
除非显示规则覆盖该设置,否则会启用OpenType字体的c2sc特性。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#smallcaps(all: true)[UNICEF] is an
agency of #smallcaps(all: true)[UN].
```
],[
#set align(horizon)
#image("images/4031.png",width: auto)
]
)
- *body*: content
要以小型大写字母显示的内容。
== 智能引号(smartquote)<smartquote>
可感知语言的引号,能够根据上下文做出适配。
会根据当前使用的#link(<text_lang>)[文本语言],自动切换为合适的前引号或后引号。
=== 示例(Example)
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
"This is in quotes."
#set text(lang: "de")
"Das ist in Anführungszeichen."
#set text(lang: "fr")
"C'est entre guillemets."
```
],[
#set align(horizon)
#image("images/4032.png",width: auto)
]
)
=== 语法(Syntax)
该函数还有专用语法:普通引号字符(\'和\")。Typst 会自动将你的引号转换为智能引号。
=== 参数(Parameters)<smallcaps_Parameters>
```typc
smartquote(
double: bool,
enabled: bool,
alternative: bool,
quotes: auto str array dictionary,
) → content
```
- *double*: bool
这是否应该使用双引号。默认值:#rtext()[true]。
- *enabled*: bool
是否启用智能引号。默认值:#rtext()[true]。
如需让单个引号不启用智能特性,你也可以使用反斜杠对其转义。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set smartquote(enabled: false)
These are "dumb" quotes.
```
],[
#set align(horizon)
#image("images/4033.png",width: auto)
]
)
- *alternative*: bool
是否使用备用引号。默认值:#rtext()[false]。
对于没有备用引号的语言,或已设置显式引号的情况,该选项不生效。
#table(
columns: 1fr,
align: left,
stroke: none,
[
```typ
#set text(lang: "de")
#set smartquote(alternative: true)
"Das ist in anderen Anführungszeichen."
```
],
[
#set quote(block: true)
#show quote: set align(center)
#rect(
fill: luma(240),
width: 100%,
height: auto,
quote[
#image("images/4034.png",width: 80%)
]
)
]
)
- *quotes*: auto str array dictionary\ 要使用的引号。默认值:#rtext()[auto]。
- 设置为自动时,将使用适配文本语言的相应单引号。这是默认设置。
- 自定义引号可以通过字符串、数组或字典形式传入,可为以下任意一种
- #link(<String>)[string]:由两个字符组成的字符串,包含起始双引号与结束双引号(此处字符指Unicode字形簇)
- #link(<array>)[array]:包含起始双引号与结束双引号的数组
- #link(<dictionary>)[dictionary]:包含双引号和单引号的字典,每种引号可指定为#rtext()[auto]、string或array类型
#table(
columns: 1fr,
align: left,
stroke: none,
[
```typ
#set text(lang: "de")
'Das sind normale Anführungszeichen.'
#set smartquote(quotes: "()")
"Das sind eigene Anführungszeichen."
#set smartquote(quotes: (single: ("[[", "]]"), double: auto))
'Das sind eigene Anführungszeichen.'
```
],
[
#set quote(block: true)
#show quote: set align(center)
#rect(
fill: luma(240),
width: 100%,
height: auto,
quote[
#image("images/4035.png",width: 80%)
]
)
]
)
== 添加删除线(strike)<strike>
给文本添加删除线。
=== 示例(Example)
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
This is #strike[not] relevant.
```
],[
#set align(horizon)
#image("images/4036.png",width: auto)
]
)
=== 参数(Parameters)
```typc
strike(
stroke: auto length color gradient stroke tiling dictionary,
offset: auto length,
extent: length,
background: bool,
body:content,
) → content
```
- *stroke*: auto length color gradient stroke tiling dictionary
如何绘制描边线条。默认值:#rtext()[auto]。
若设置为自动,将采用文本颜色以及当前字体所定义的粗细。
注意:请勿将此用于正式内容涂黑遮挡,因为文本仍可被复制粘贴。
#table(
columns: 1fr,
align: left,
stroke: none,
[
```typ
This is #strike(stroke: 1.5pt + red)[very stricken through]. \
This is #strike(stroke: 10pt)[redacted].
```
],
[
#set quote(block: true)
#show quote: set align(center)
#rect(
fill: luma(240),
width: 100%,
height: auto,
quote[
#image("images/4037.png",width: 80%)
]
)
]
)
- *offset*: auto length
线条相对于基线的位置。若设置为自动,则从字体表读取该值。默认值:#rtext()[auto]。
如果你对字体自带的偏移量不满意,这个参数会很有用。
#table(
columns: 1fr,
align: left,
stroke: none,
[
```typ
#set text(font: "Inria Serif")
This is #strike(offset: auto)[low-ish]. \
This is #strike(offset: -3.5pt)[on-top].
```
],
[
#set quote(block: true)
#show quote: set align(center)
#rect(
fill: luma(240),
width: 100%,
height: auto,
quote[
#image("images/4038.png",width: 80%)
]
)
]
)
- *extent*: length
将线条向内容外侧延伸的距离(若数值为负,则向内容内侧缩进)。默认值:#rtext()[0pt]。
#table(
columns: 1fr,
align: left,
stroke: none,
[
```typ
This #strike(extent: -2pt)[skips] parts of the word.
This #strike(extent: 2pt)[extends] beyond the word.
```
],
[
#set quote(block: true)
#show quote: set align(center)
#rect(
fill: luma(240),
width: 100%,
height: auto,
quote[
#image("images/4039.png",width: 80%)
]
)
]
)
- *background*: bool
该行是否放置在内容后方。默认值:#rtext()[false]。
#table(
columns: 1fr,
align: left,
stroke: none,
[
```typ
#set strike(stroke: red + 2pt)
#strike(background: true)[This is behind.] \
#strike(background: false)[This is in front.]
```
],
[
#set quote(block: true)
#show quote: set align(center)
#rect(
fill: luma(240),
width: 100%,
height: auto,
quote[
#image("images/4040.png",width: 80%)
]
)
]
)
- *body*:content
需要加删除线的文本。
== 下标(sub)<sub>
将文本渲染为下标。
文本会以更小的字号显示,且基线位置下移。
=== 示例(Example)
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
Revenue#sub[yearly]
```
],[
#set align(horizon)
#image("images/4041.png",width: auto)
]
)
=== 参数(Parameters)
```typc
sub(
typographic: bool,
baseline: auto length,
size: auto length,
body:content,
) → content
```
- *typographic*: bool<sub_typographic>
是否使用字体自带的下标字形(如有)。默认值:#rtext()[true]。
理想情况下,下标字形由字体提供(通过OpenType的subs特性)。如果字体未提供,Typst可以通过下移并缩小普通字形来合成下标。
当该项设为false时,无论字体是否提供专用下标字形,都将使用合成字形。当该项设为true时,若字体缺少所需下标字形,仍可能使用合成字形。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
N#sub(typographic: true)[1]
N#sub(typographic: false)[1]
```
],[
#set align(horizon)
#image("images/4042.png",width: auto)
]
)
- *baseline*: auto length<sub_baseline>
合成下标用的基线向下偏移量。默认值:#rtext()[auto]。
该设置仅对合成下标生效。也就是说,如果启用排版字体(typographic为#rtext()[true])且字体自带所需的下标字形,则此设置无效。
若设为#rtext()[auto],基线将根据字体提供的度量信息进行偏移;当字体未定义相关度量信息时,回退使用#rtext()[0.2em]。
使用多字体时,可能需要手动指定基线和#link(<sub_size>)[字号]。可参考上标(#link(<super_baseline>)[super])的示例。
- *size*: auto length<sub_size>
合成下标所用的字体大小。默认值:#rtext()[auto]。
该设置仅对合成下标生效。也就是说,如果开启排版模式且字体自带所需的下标字形,则此设置无效。
若设为#rtext()[auto],大小会根据字体提供的度量信息进行缩放;当字体未定义相关度量信息时,将回退使用#rtext()[0.6em]。
- *body*:content<sub_body>
要作为下标显示的文本。
== 上标(super)<super>
将文本以上标形式呈现。
文本会缩小显示,且基线向上偏移。
=== 示例(Example)
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
1#super[st] try!
```
],[
#set align(horizon)
#image("images/4043.png",width: auto)
]
)
=== 参数(Parameters)
```typc
super(
typographic: bool,
baseline: auto length,
size: auto length,
body:content,
) → content
```
- *typographic*: bool<super_typographic>
是否在字体支持的情况下使用字体自带的上标字形。默认值:#rtext()[true]。
理想情况下,上标字形由字体提供(通过 sups OpenType 特性)。如果字体不支持,Typst 可以将普通字形上移并缩小来合成上标。
当该项设为 false 时,无论字体是否提供专用上标字形,都将使用合成字形。当该项设为 true 时,若字体没有所需的上标字形,仍可能使用合成字形。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
N#super(typographic: true)[1]
N#super(typographic: false)[1]
```
],[
#set align(horizon)
#image("images/4044.png",width: auto)
]
)
- *baseline*: auto length<super_baseline>
合成上标的基线向下偏移量。默认值:#rtext()[auto]。
该设置仅对合成上标生效。也就是说,如果开启了印刷字体模式且字体自带所需的上标字形,此设置不会产生任何效果。
若设置为#rtext()[auto],基线将根据字体提供的度量信息进行偏移;当字体未定义相关度量信息时,会回退使用 #rtext()[-0.5em]。
注意:由于基线偏移方向为向下,想要让内容显示在普通基线的上方,你需要设置一个负值。
有时需要显式指定基线和#link(<super_size>)[字号]。在下面的示例中,上标文本使用了多款度量标准不兼容的字体。为避免对齐错乱,我们对所有字体的度量参数进行强制覆盖。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#let tz(timezone) = text(
font: "Roboto",
smallcaps(timezone, all: true),
)
/ Per-font metrics:
14:00#super[#tz[UTC], not #tz[CET]]
#set super(
baseline: -0.4em,
size: 0.6em,
typographic: false,
)
/ Unified metrics:
14:00#super[#tz[UTC], not #tz[CET]]
```
],[
#set align(horizon)
#image("images/4045.png",width: auto)
]
)
- *size*: auto length<super_size>
合成上标的字体大小。默认值:#rtext()[auto]。
该设置仅适用于合成上标。也就是说,如果启用印刷排版模式且字体自带所需的上标字形,则该设置无效。
若设为自动,大小将根据字体提供的度量信息进行缩放;当字体未定义相关度量信息时,会回退至0.6em。
- *body*: content<super_body>
要作为上标显示的文本。
== 文本(text)<text>
以多种方式自定义文本的外观与布局。
该函数经常使用,既可配合预设规则使用,也可直接调用。虽然使用预设规则通常是更简便的选择,但在将文本作为参数传递给其他函数时,直接调用文本函数会很有用。
=== 示例(Example)
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set text(18pt)
With a set rule.
#emph(text(blue)[
With a function call.
])
```
],[
#set align(horizon)
#image("images/4046.png",width: auto)
]
)
=== 参数(Parameters)
```typc
text(
font: str array dictionary,
fallback: bool,
style: str,
weight: int str,
stretch: ratio,
size: length,
fill: color gradient tiling,
stroke: none length color gradient stroke tiling dictionary,
tracking: length,
spacing: relative,
cjk-latin-spacing: none auto,
baseline: length,
overhang: bool,
top-edge: length str,
bottom-edge: length str,
lang: str,
region: none str,
script: auto str,
dir: auto direction,
hyphenate: auto bool,
costs: dictionary,
kerning: bool,
alternates: bool int,
stylistic-set: none int array,
ligatures: bool,
discretionary-ligatures: bool,
historical-ligatures: bool,
number-type: auto str,
number-width: auto str,
slashed-zero: bool,
fractions: bool,
features: array dictionary,
variations: dictionary,
body: content,
text: str,
) → content
```
- *font*: str array dictionary<text_font>
字体族描述符,或是字体族描述符的优先级列表。默认值:```typc "libertinus serif"```。
字体族描述符可以是代表字体族名称的纯文本字符串,也可以是包含以下键的字典:
#set par(hanging-indent: 1.3cm)
-- name(必填):字体族名称。
-- covers(可选):定义该字体族适用的Unicode码点。可以为:
#set par(first-line-indent: 2cm,hanging-indent: 2cm)
$circle$ 预定义覆盖集:
$quad square$ “latin-in-cjk”涵盖所有码位,但不包含那些在拉丁字体中存在、却最好从中日韩字体获取的码位。
$circle$ 用于精确规定需要覆盖哪些码点的#link(<regex>)[正则表达式]。仅接受由单个点、字母或字符类构成的那部分正则表达式子集。
#set par(first-line-indent: 1cm,hanging-indent: 0cm)
处理文本时,Typst会按顺序尝试所有指定的字体系列,直到找到包含所需字形的字体。在下方示例中,优先使用 Inria Serif 字体,但由于该字体不含阿拉伯文字形,阿拉伯语文本会改用 Noto Sans Arabic。
Typst 旨在将同一系列下的不同字体统一为同一个系列名称。为此,它会自动去除字体系列名称中常见的样式后缀,例如“Bold”(粗体)或“Condensed”(压缩体)。不要通过字体名称选择这类变体,而应使用 Typst 的内置机制(如字重和拉伸参数)进行设置。同理,在 Typst 中使用可变字体时,应当省略“Variable”、“Var”以及“VF”这类后缀,因为 Typst 会自动剔除它们,从而把静态字体和可变字体归为同一个系列。
在同一系列的多款字体之间,Typst 会挑选与配置的#link(<text_style>)[文本样式]、#link(<text_weight>)[字重]以及#link(<text_stretch>)[拉伸度]匹配度最高的字体。如果静态字体和可变字体都支持某一配置,会优先选用可变字体。
可用字体集合因平台而异:
#set par(hanging-indent: 1.3cm)
-- 在网页应用中,点击“Ag”按钮即可查看可用字体列表。你可以将.ttf或.otf文件上传到项目中以添加额外字体,程序会自动识别这些字体。字体优先级:项目字体 > 服务器字体。
-- 在本地环境下,Typst会使用你已安装的系统字体,或是命令行工具内置字体,内置字体包括Libertinus Serif、New Computer Modern、New Computer Modern Math以及DejaVu Sans Mono。此外,你可以使用--font-path参数或TYPST_FONT_PATHS环境变量,添加用于扫描字体的目录。字体优先级:--font-path > 系统字体 > 内置字体。执行typst fonts命令,可以查看Typst在你的系统中识别到的字体。注意,你可以向命令行传入--ignore-system-fonts参数,让Typst不检索系统字体。
#set par(hanging-indent: 0cm)
#table(
columns: 1fr,
align: left,
stroke: none,
[
```typ
#set text(font: "PT Sans")
This is sans-serif.
#set text(font: (
"Inria Serif",
"Noto Sans Arabic",
))
This is Latin. \
هذا عربي.
// Change font only for numbers.
#set text(font: (
(name: "PT Sans", covers: regex("[0-9]")),
"Libertinus Serif"
))
The number 123.
// Mix Latin and CJK fonts.
#set text(font: (
(name: "Inria Serif", covers: "latin-in-cjk"),
"Noto Serif CJK SC"
))
分别设置“中文”和English字体
```
],
[
#set quote(block: true)
#show quote: set align(center)
#rect(
fill: luma(240),
width: 100%,
height: auto,
quote[
#image("images/4047.png",width: 80%)
]
)
]
)
- *fallback*: bool<text_fallback>
当主字体列表没有匹配项时,是否启用最后的字体回退机制。开启后,Typst会在所有可用字体中查找拥有所需字形、相似度最高的字体。默认值:#rtext()[true]。
注意:目前,若关闭回退机制且找不到对应字形时不会弹出警告。文本会以“豆腐块”形式显示:也就是用来表示缺少合适字形的小方框。未来版本中,你可以设置让Typst发出警告,以便及时发现这类问题。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set text(font: "Inria Serif")
هذا عربي
#set text(fallback: false)
هذا عربي
```
],[
#set align(horizon)
#image("images/4048.png",width: auto)
]
)
- *style*: str<text_style>
所需字体样式。默认值:```typc "normal"```。
当请求斜体(italic)样式,但仅有倾斜体(oblique)可用时,会使用倾斜体。同理反过来,斜体样式也可以替代倾斜体。如果斜体和倾斜体都不可用,Typst 将选用常规样式。由于大多数字体仅提供斜体或倾斜体其中一种,二者的差别通常很难察觉。
搭配合适的可变字体使用时,Typst 会根据该属性自动配置 ital(用于斜体样式)或 slnt(用于倾斜体样式)#link(<text_variations>)[字体变体]。
注意:如果你想强调文本,应当使用 emph 函数实现。这样后续如果想要更换强调的表现形式,调整样式会更加方便。
#table(
columns: 1fr,
align: left,
stroke: none,
[
```typ
#text(font: "Libertinus Serif", style: "italic")[Italic]
#text(font: "DejaVu Sans", style: "oblique")[Oblique]
```
],
[
#set quote(block: true)
#show quote: set align(center)
#rect(
fill: luma(240),
width: 100%,
height: auto,
quote[
#image("images/4049.png",width: 80%)
]
)
]
)
#table(
columns: (0.5fr,1.5fr),
align: left,
stroke: none,
table.header([Variant],[Details]),
table.hline(),
[\"normal\"],[默认的、通常为正体的样式。],
[\"italic\"],[一种带有自定义字形的草书字体。],
[\"oblique\"],[只是常规样式的倾斜版本。]
)
- *weight*: int str<text_weight>
字体字形的目标字重。可接受100至900之间的整数,或是预定义的字重名称。当所需字重不可用时,Typst会从该字族中选择字重最接近的字体。默认值:```typc "regular"```。
搭配合适的可变字体使用时,Typst会基于该属性自动配置wght#link(<text_variations>)[字体变体]。
注:如果你想对文本进行着重强调,应当改用strong函数。这样一来,若后续你想调整着重强调的样式,修改起来会更加方便。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set text(font: "IBM Plex Sans")
#text(weight: "light")[Light] \
#text(weight: "regular")[Regular] \
#text(weight: "medium")[Medium] \
#text(weight: 500)[Medium] \
#text(weight: "bold")[Bold]
```
],[
#set align(horizon)
#image("images/4050.png",width: auto)
]
)
#table(
columns: (0.5fr,1.5fr),
align: left,
stroke: none,
table.header([Variant],[Details]),
table.hline(),
[\"thin\"],[细字重(100)。],
[\"extralight\"],[特细字重(200)。],
[\"light\"],[细字重(300)。],
[\"regular\"],[常规字重(400)。],
[\"medium\"],[中等字重(500)。],
[\"semibold\"],[半粗字重(600)。],
[\"bold\"],[粗体字重(700)。],
[\"extrabold\"],[特粗字重(800)。],
[\"black\"],[黑粗字重(900)。],
)
- *stretch*: ratio<text_stretch>
字形的目标宽度。可接受介于50%到200%之间的比例值。当无法设置该目标宽度时,Typst会从字族中选取拉伸程度最接近的字体。仅当该字体存在压缩或扩展版本时,文本才会被拉伸。默认值:#rtext()[100%]。
搭配合适的可变字体使用时,Typst会基于该属性自动配置wdth#link(<text_variations>)[字体变化轴]。
如果你想要调整字符之间的间距,而不是拉伸字形本身,请改用字距(#link(<text_tracking>)[tracking])属性。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set text(font: "IBM Plex Sans")
#text(stretch: 75%)[Condensed] \
#text(stretch: 100%)[Normal]
```
],[
#set align(horizon)
#image("images/4051.png",width: auto)
]
)
- *size*: length<text_size>
字形的大小。该值是em单位的基准:1em等于字体大小。默认值:#rtext()[11pt]。
你也可以使用em单位来设置字体大小,此时字体大小会相对于上一级字体大小进行计算。
当搭配合适的可变字体使用时,Typst会根据该属性自动配置opsz(光学尺寸)#link(<text_variations>)[字体变体],针对当前字号优化文字可读性。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set text(size: 20pt)
very #text(1.5em)[big] text
```
],[
#set align(horizon)
#image("images/4052.png",width: auto)
]
)
- *fill*: color gradient tiling<text_fill>
字形填充颜料。默认值:luma(#rtext()[0%])。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set text(fill: red)
This text is red.
```
],[
#set align(horizon)
#image("images/4053.png",width: auto)
]
)
- *stroke*: none length color gradient stroke tiling dictionary<text_stroke>
如何给文字添加描边。默认值:#rtext()[none]。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#text(stroke: 0.5pt + red)[Stroked]
```
],[
#set align(horizon)
#image("images/4054.png",width: auto)
]
)
- *tracking*: length<text_tracking>
字符之间需要添加的间距值。默认值:#rtext()[0pt]。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set text(tracking: 1.5pt)
Distant text.
```
],[
#set align(horizon)
#image("images/4055.png",width: auto)
]
)
- *spacing*: relative<text_spacing>
单词之间的间距。默认值:#rtext()[100%+0pt]。
可以设置为固定长度,也可相对于字体中空格字符的宽度进行设置。
如果你想调整字符之间而非单词之间的间距,请改用字间距属性。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set text(spacing: 200%)
Text with distant words.
```
],[
#set align(horizon)
#image("images/4056.png",width: auto)
]
)
- *cjk-latin-spacing*: none auto<text_cjk-latin-spacing>
是否在中日韩文字与拉丁字符之间自动插入空格。默认值:#rtext()[auto]。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set text(cjk-latin-spacing: auto)
第4章介绍了基本的API。
#set text(cjk-latin-spacing: none)
第4章介绍了基本的API。
```
],[
#set align(horizon)
#image("images/4057.png",width: auto)
]
)
- *baseline*: length<text_baseline>
用于偏移文本基线的数值。默认值:#rtext()[0pt]。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
A #text(baseline: 3pt)[lowered]
word.
```
],[
#set align(horizon)
#image("images/4058.png",width: auto)
]
)
- *overhang*: bool<text_overhang>
两端对齐文本中,某些字形是否可以延伸到页边距区域。这样能让两端对齐的排版视觉效果更佳。默认值:#rtext()[true]。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set page(width: 220pt)
#set par(justify: true)
This justified text has a hyphen in
the paragraph's second line. Hanging
the hyphen slightly into the margin
results in a clearer paragraph edge.
#set text(overhang: false)
This justified text has a hyphen in
the paragraph's second line. Hanging
the hyphen slightly into the margin
results in a clearer paragraph edge.
```
],[
#set align(horizon)
#image("images/4059.png",width: auto)
]
)
- *top-edge*: length str<text_top-edge>
用于布局和定位的文本外围概念框的顶端。该属性会影响承载文本的容器大小。默认值:```typc "cap-height"```。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set rect(inset: 0pt)
#set text(size: 20pt)
#set text(top-edge: "ascender")
#rect(fill: aqua)[Typst]
#set text(top-edge: "cap-height")
#rect(fill: aqua)[Typst]
```
],[
#set align(horizon)
#image("images/4060.png",width: auto)
]
)
#table(
columns: (0.5fr,1.5fr),
align: left,
stroke: none,
table.header([Variant],[Details]),
table.hline(),
[\"ascender\"],[该字体的升部,通常超过所有字形的高度。],
[\"cap-height\"],[大写字母的近似高度。],
[\"x-height\"],[不含升部小写字母的近似高度。],
[\"baseline\"],[字母所依托的基线。],
[\"bounds\"],[字形边界框的顶边。],
)
- *bottom-edge*: length str<text_bottom-edge>
文本周围用于布局和定位的概念框架的底端。该属性会影响容纳文本的容器大小。默认值:```typc "baseline"```。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set rect(inset: 0pt)
#set text(size: 20pt)
#set text(bottom-edge: "baseline")
#rect(fill: aqua)[Typst]
#set text(bottom-edge: "descender")
#rect(fill: aqua)[Typst]
```
],[
#set align(horizon)
#image("images/4061.png",width: auto)
]
)
#table(
columns: (0.5fr,1.5fr),
align: left,
stroke: none,
table.header([Variant],[Details]),
table.hline(),
[\"baseline\"],[字母所处的基线。],
[\"descender\"],[字体的下伸部,其深度通常超过所有字形的下沿。],
[\"bounds\"],[字形边界框的底边。],
)
- *lang*: str<text_lang>
#link("https://en.wikipedia.org/wiki/ISO_639")[ISO 639-1/2/3语言代码]。默认值:```typc "en"```。
设置正确的语言会影响 Typst 的多个方面:
-- 文本处理流程可以做出更合理的判断。
-- 断词会使用对应语言的规则。
-- 智能引号会转换为该语言适用的引号样式。
-- 以及其他所有与语言相关的功能。
选择正确的语言对于无障碍访问十分重要。例如,屏幕阅读器会依据语言设置,选用与文本语言匹配的语音。如果文档使用英语(默认语言)之外的其他语言,你需要在文档开头、所有其他内容之前设置文本语言。举例来说,你可以将该设置紧跟在用于#link(<document_title>)[设定文档标题]的 ```typ #set document(/* ... */)``` 规则之后。
如果文档内包含与主体语言不同的段落,你应当仅针对这些部分局部修改文本语言,可使用作用域限定在#link(<Scripting_Blocks>)[文本块]的set规则,或是直接调用文本函数,例如 ```typ #text(lang: "de")[...]```。
若你的语言存在多种可用代码,应优先选用双字母代码(ISO 639-1),而非三字母代码(ISO 639-2/3)。当必须使用三字母代码,且该语言在 ISO 639-2 和 ISO 639-3 中的代码不一致时,PDF
1.7(Typst 默认PDF导出版本)及更低版本请使用 ISO 639-2;PDF 2.0 和 HTML 导出则使用 ISO 639-3。
语言代码不区分大小写,通过#link(<Context>)[上下文]读取时会转为小写。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set text(lang: "de")
#outline()
= Einleitung
In diesem Dokument, ...
```
],[
#set align(horizon)
#image("images/4062.png",width: auto)
]
)
- *region*: none str<text_region>
#link("https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2")[ISO 3166-1 alpha-2 区域代码]。默认值:```typc none```。
这可让文本处理流水线做出更合理的判断。
该区域代码不区分大小写,通过#link(<Context>)[上下文]读取时会转为大写。
- *script*: auto str<text_script>
OpenType书写文字体系。默认值:```typc auto```。
语言与文字体系的组合决定字体特性(例如字形替换)的实现方式。该值通常采用经过修改的(全小写)ISO 15924文字体系标识符,数学书写文字体系用于适配数学符号相关特性。
当设置为#rtext()[auto](默认且推荐设置)时,系统会为每一组拥有相同Unicode文字体系属性的字符块选取合适的文字体系。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set text(
font: "IBM Plex Sans",
size: 20pt,
)
#let scedilla = [Ş]
#scedilla // S with a cedilla
#set text(lang: "ro", script: "latn")
#scedilla // S with a subscript comma
#set text(lang: "ro", script: "grek")
#scedilla // S with a cedilla
```
],[
#set align(horizon)
#image("images/4063.png",width: auto)
]
)
- *dir*: auto direction<text_dir>
文本和行内对象的主导方向。默认值:```typc auto```。
可选值如下:
-- #rtext()[auto]:根据 lang 属性自动推断方向。
-- ltr:文本从左向右排布。
-- rtl:文本从右向左排布。
在书写阿拉伯语、希伯来语这类从右向左书写的文字时,你需要设置#link(<text_lang>)[文本语言]或文字方向。虽然独立文本片段会自动按正确方向排版,但设置主导方向可以为双向重排算法提供必要信息,从而正确放置标点符号和行内对象。此外,文字方向设置会影响起始端与结束端的对齐属性:在从左向右文本中,这两个属性分别等同于左对齐和右对齐;而在从右向左文本中则正好相反。
如果你将此项设置为从右向左(rtl)后遇到程序缺陷,或是出现显示效果异常的情况,请通过#link("https://forum.typst.app/")[论坛]、#link("https://discord.gg/2uDybryKPe")[Discord服务器]或者我们的#link("https://typst.app/contact")[联系表单]与我们取得联系。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set text(dir: rtl)
هذا عربي.
```
],[
#set align(horizon)
#image("images/4064.png",width: auto)
]
)
- *hyphenate*: auto bool<text_hyphenate>
是否对文本使用连字符以优化换行。设为#text(fill:red,"auto")时,仅当启用两端对齐时,文本才会使用连字符。默认值:```typc auto```。
设置#link(<text_lang>)[文本语言]可确保使用正确的断词规则。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set page(width: 200pt)
#set par(justify: true)
This text illustrates how
enabling hyphenation can
improve justification.
#set text(hyphenate: false)
This text illustrates how
enabling hyphenation can
improve justification.
```
],[
#set align(horizon)
#image("images/4065.png",width: auto)
]
)
- *costs*: dictionary<text_costs>
默认值:
```typc
(
hyphenation: 100%,
runt: 100%,
widow: 100%,
orphan: 100%,
)
```。
排版文本时各类选择的“代价”。代价越高,排版引擎就越少采用该选择。代价以默认代价的比值设定,因此50%的代价会让文本排版做出该选择的意愿提升一倍,而200%的代价则会让其做出该选择的意愿减半。
目前可自定义的开销项如下:
#set par(hanging-indent: 1cm)
-- hyphenation: 将一个单词拆分到多行\
-- runt: 段落末尾仅由一个单词单独占一行\
-- widow: 段落单独一行留在下一页\
-- orphan: 段落单独一行留在上一页
#set par(hanging-indent: 0cm)
断字一般会通过把整个单词放到下一行来避免,因此更高的断字代价会造成不自然的两端对齐间距。注:断字代价仅在换行设置为“优化”时生效(例如#link(<Paragraph>)[两端对齐模式]默认启用该设置)。
短行可以通过在上一行多放或少放单词来规避,因此更高的短行代价同样会导致两端对齐的间距效果变差。
文本排版默认会防止孤行与寡行,因为各类排版规范通常不建议出现这类情况。但在部分场景下允许保留孤行、寡行,原因是防止孤行寡行的处理方式会把一行移到下一页,这可能导致各页面的行数不均衡。孤行与寡行代价参数可关闭这类自动调整。(当前规则:设为0%时允许孤行/寡行;其他数值,包括默认值100%,都会阻止孤行寡行。后续计划为这类调整提供更精细的代价配置。)
#table(
columns: 1fr,
align: left,
stroke: none,
[
```typ
#set text(hyphenate: true, size: 11.4pt)
#set par(justify: true)
#lorem(10)
// Set hyphenation to ten times the normal cost.
#set text(costs: (hyphenation: 1000%))
#lorem(10)
```
],
[
#set quote(block: true)
#show quote: set align(center)
#rect(
fill: luma(240),
width: 100%,
height: auto,
quote[
#image("images/4065.png",width: 80%)
]
)
]
)
- *kerning*: bool<text_kerning>
是否应用字距调整。默认值:```typc true```。
启用后,特定字母对的间距会拉近或拉远,以获得更好的视觉效果。下方示例展示了缩小字母“T”和“o”之间的间隙后,观感会更加自然。将此项设为#text(fill: red,"false")会关闭OpenType字体的字距特性,从而禁用字距调整。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set text(size: 25pt)
Totally
#set text(kerning: false)
Totally
```
],[
#set align(horizon)
#image("images/4067.png",width: auto)
]
)
- *alternates*: bool int<text_alternates>
是否启用样式替换字符。默认值:```typc 0```。
部分字体针对同一编码点提供备选字形。将该项设为true时,会开启OpenType的salt字体特性以切换至这类备选字形。可使用整数在多种备选字形之间进行选择。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set text(
font: "IBM Plex Sans",
size: 20pt,
)
0, a, g, ß
#set text(alternates: true)
0, a, g, ß
```
],[
#set align(horizon)
#image("images/4068.png",width: auto)
]
)
- *stylistic-set*: none int array<text_stylistic-set>
要应用哪些样式集。字体设计师可以将替代字形归类到各个样式集中。由于该值高度依赖具体字体,你需要查阅所用字体的说明,了解可用的样式集。
该属性可以设置为一个整数或者整数数组,所有数值必须在1到20之间,以此开启从ss01到ss20对应的OpenType特性。若设置为none,则会禁用所有样式集。
#table(
columns: 1fr,
align: left,
stroke: none,
[
```typ
#set text(font: "IBM Plex Serif")
ß vs #text(stylistic-set: 5)[ß] \
10 years ago vs #text(stylistic-set: (1, 2, 3))[10 years ago]
```
],
[
#set quote(block: true)
#show quote: set align(center)
#rect(
fill: luma(240),
width: 100%,
height: auto,
quote[
#image("images/4069.png",width: 80%)
]
)
]
)
- *ligatures*: bool<text_ligatures>
是否启用标准连字。默认值:```typc true```。
某些字母组合(例如“fi”)通常会显示为一个合并字形,称为连字。将此项设为false会关闭OpenType字体的liga与clig特性,从而禁用这类连字。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set text(size: 20pt)
A fine ligature.
#set text(ligatures: false)
A fine ligature.
```
],[
#set align(horizon)
#image("images/4070.png",width: auto)
]
)
请注意,部分编程字体使用其他OpenType字体特性来实现“连字”,其中包括上下文替换(calt)特性,该特性默认同样处于启用状态。可使用通用#link(<text_features>)[特性]参数来控制这类特性。
- *discretionary-ligatures*: bool<text_discretionary-ligatures>
是否启用应谨慎使用的连字。将其设置为 true 可启用 OpenType dlig 字体功能。默认值:```typc false```。
- *historical-ligatures*: bool<text_historical-ligatures>
是否启用历史连字。将此项设为true会开启OpenType的hlig字体特性。默认值:```typc false```。
- *number-type*: auto str<text_number-type>
选择何种数字/字形。设置为自动时,将使用该字体的默认数字样式。默认值:```typc auto```。
- *number-width*: auto str<text_number-width>
数字/图形的宽度。设置为自动时,将使用该字体的默认数字样式。默认值:```typc auto```。
#table(
columns: 1fr,
align: left,
stroke: none,
[
```typ
#set text(font: "Noto Sans", 20pt)
#set text(number-width: "proportional")
A 12 B 34. \
A 56 B 78.
#set text(number-width: "tabular")
A 12 B 34. \
A 56 B 78.
```
],
[
#set quote(block: true)
#show quote: set align(center)
#rect(
fill: luma(240),
width: 100%,
height: auto,
quote[
#image("images/4071.png",width: 80%)
]
)
]
)
#table(
columns: (0.5fr,1.5fr),
align: left,
stroke: none,
table.header([Variant],[Details]),
table.hline(),
[\"proportional\"],[具有字形专属宽度的数字(OpenType pnum字体特性)。],
[\"tabular\"],[等宽数字(OpenType tnum字体特性)。],
)
- *slashed-zero*: bool<text_slashed-zero>
是否在数字0字形上加斜杠。将此项设为true会启用OpenType字体的零数字特性。默认值:```typc false```。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
0, #text(slashed-zero: true)[0]
```
],[
#set align(horizon)
#image("images/4072.png",width: auto)
]
)
- *fractions*: bool<text_fractions>
是否将数字转换为分数。将此项设为#text(fill: red,"true")可启用OpenType分数字体特性。默认值:```typc false```。
不建议全局启用该属性,因为它会影响所有斜杠后的数字显示(例如网址中的数字)。如需使用分数效果,请在局部启用。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
1/2 \
#text(fractions: true)[1/2]
```
],[
#set align(horizon)
#image("images/4073.png",width: auto)
]
)
- *features*: array dictionary<text_features>
要应用的原始 OpenType 特性。默认值:```typc (:)```。
#set par(hanging-indent: 1cm)
-- 如果提供字符串数组,将这些字符串标识的特性设置为 1。\
-- 如果提供映射到数字的字典,将这些键标识的特性设置为对应的值。这允许与非布尔特性(如 swsh)进行交互。
#set par(hanging-indent: 0cm)
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
// Enable the `frac` feature manually.
#set text(features: ("frac",))
1/2
```
],[
#set align(horizon)
#image("images/4074.png",width: auto)
]
)
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set text(font: "Cascadia Code")
=>
// Disable the contextual alternates (`calt`) feature.
#set text(features: (calt: 0))
=>
```
],[
#set align(horizon)
#image("images/4075.png",width: auto)
]
)
- *variations*: dictionary<text_variations>
要应用的原始OpenType字体变体。默认值:```typc (:)```。
传统静态字体的每一种样式组合都需要单独的字体文件,而可变字体带有变体轴,可通过变体轴生成多种不同样式。变体轴由区分大小写的四字符字符串标识。
有几个知名的可变字体轴,Typst 会根据文字#link(<text_weight>)[字重]、#link(<text_stretch>)[拉伸度]、#link(<text_style>)[样式]和#link(<text_size>)[字号]自动设置合适的数值,包括:
#set par(hanging-indent: 1cm)
-- wght:字重(例如 400 代表常规字重,700 代表粗体)\
--wdth:字宽(百分比,例如 100 代表正常宽度)\
-- slnt:倾斜角度(单位为度,负值代表向右倾斜)\
-- ital:斜体开关(0 为正体,1 为斜体)\
-- opsz:光学字号(单位为磅)
#set par(hanging-indent: 0cm)
字体也可以定义自定义变化轴,以实现任意视觉效果。例如,某个变化轴的数值设置得越高,字体样式就可以变得越富有奇趣感。
借助 variations 参数,你可以直接为当前字体所支持的变化轴设置数值。该参数仅在搭配支持指定变化轴的可变字体时生效。你既可以使用该参数覆盖通用变化轴的自动赋值,也可以为自定义变化轴设置数值。
参数值应为字典类型,将轴标签(四个字符的#link(<String>)[字符串])映射到对应的数值(#link(<float>)[浮点数])。
#table(
columns: 1fr,
align: left,
stroke: none,
[
```typ
#set text(font: "Fraunces", size: 60pt)
#text(variations: (SOFT: 0))[Soft? No.] \
#text(variations: (SOFT: 100))[Soft? Yes.]
```
],
[
#set quote(block: true)
#show quote: set align(center)
#rect(
fill: luma(240),
width: 100%,
height: auto,
quote[
#image("images/4076.png",width: 80%)
]
)
]
)
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#set text(
font: "Roboto Flex",
weight: 900,
stretch: 150%,
)
Wide and Heavy
#text(variations: (wght: 400))[
Forced back to normal,
but still wide.
]
```
],[
#set align(horizon)
#image("images/4077.png",width: auto)
]
)
- *body*: content<text_body>
所有文本均按照其他参数设置样式的内容。默认值:```typc []```。
- *text*: str<text_text>
文本。
== 下划线(underline)<underline>
给文字添加下划线。
=== 示例(Example)
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
This is #underline[important].
```
],[
#set align(horizon)
#image("images/4078.png",width: auto)
]
)
=== 参数(Parameters)
```typc
underline(
stroke: auto length color gradient stroke tiling dictionary,
offset: auto length,
extent: length,
evade: bool,
background: bool,
body:content,
) → content
```
- *stroke*: auto length color gradient stroke tiling dictionary<underline_stoke>
如何#link(<stroke>)[描]边。默认值:```typc auto```。
如果设置为自动,则采用文本的颜色以及当前字体所定义的粗细。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
Take #underline(
stroke: 1.5pt + red,
offset: 2pt,
[care],
)
```
],[
#set align(horizon)
#image("images/4079.png",width: auto)
]
)
- *offset*: auto length<underline_offset>
如果设为自动,则从字体表读取线条相对于基线的位置。默认值:```typc auto```。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#underline(offset: 5pt)[
The Tale Of A Faraway Line I
]
```
],[
#set align(horizon)
#image("images/4080.png",width: auto)
]
)
- *extent*: length<underline_extent>
将线条延伸至内容之外(若为负值,则向内容内部延伸)的长度。默认值:```typc 0pt```。
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#align(center,
underline(extent: 2pt)[Chapter 1]
)
]
```
],[
#set align(horizon)
#image("images/4081.png",width: auto)
]
)
- *evade*: bool<underline_evade>
该行是否跳过会与字形发生碰撞的区域。默认值:```typc true```。
#table(
columns: 1fr,
align: left,
stroke: none,
[
```typ
This #underline(evade: true)[is great].
This #underline(evade: false)[is less great].
```
],
[
#set quote(block: true)
#show quote: set align(center)
#rect(
fill: luma(240),
width: 100%,
height: auto,
quote[
#image("images/4082.png",width: 80%)
]
)
]
)
- *background*: bool
该线条是否置于其所下划线内容的后方。默认值:```typc false```。
#table(
columns: 1fr,
align: left,
stroke: none,
[
```typ
#set underline(stroke: aqua + 5pt, evade: false)
#underline(background: true)[Fully visible.] \
#underline(background: false)[Partially hidden.]
```
],
[
#set quote(block: true)
#show quote: set align(center)
#rect(
fill: luma(240),
width: 100%,
height: auto,
quote[
#image("images/4083.png",width: 80%)
]
)
]
)
- *body*:content
需要添加下划线的内容。
== 大写字母(upper)<upper>
将字符串或内容转换为大写。
=== 示例(Example)
#table(
columns: (1fr,1fr),
align: (left,left),
stroke: none,
fill: (rgb(250, 250, 250),luma(86.27%)),
[
```typ
#upper("abc") \
#upper[*my text*] \
#upper[ALREADY HIGH]
```
],[
#set align(horizon)
#image("images/4084.png",width: auto)
]
)
=== 参数(Parameters)
```typc
upper(text: str content) → strcontent
```
- *text*: str content
要转为大写的文本。
|