gfngfn

֓ཁ
4"5:4'*ʢαςΟεϑΝΠʣͱ͸w ߨԋऀ͕೥౓*1"ະ౿ࣄ‫ۀ‬ͷϓϩδΣΫτͱͯ͠։ൃͨ͠
ൺֱత৽͍͠૊൛ॲཧγεςϜw ੩త‫͖ͭܕ‬ͷ͍ΘΏΔവ਺‫ܕ‬ͷϓϩάϥϛϯά‫Ͱޠݴ‬ύοέʔδ΍จॻຊମ͕ॻ͚Δr ҰൠతͳϓϩάϥϜͱಉ͡ཁྖͰಡΈॻ͖Ͱ͖ΔͷͰΧελϚΠζੑ͕ߴ͍w DG5&9-"5&9ɿෳࡶͳҙຯ࿦Ώ͑ʹύοέʔδ࡞੒ʹ͸஁࿉Λཁ͢Δ্ɼ
ख़࿅ऀͰ΋ଞਓͷॻ͍࣮ͨ૷͸ಡΜͰվม͢Δͷ͕೉͍͠r ‫هͨͬޡ‬ड़Λͨ͠ͱ͖΋ɼ‫ʹࠪݕܕ‬Αͬͯਝ଎ʢయ‫ܕ‬తʹ͸ඵ΄Ͳʣ͔ͭ‫ݪ‬ҼͷղΓ΍͍͢ΤϥʔใࠂΛग़ͯ͘͠ΕΔ܏޲ʹ͋Δ

w DG5&9-"5&9ɿࠣࡉͳϛεͰ΋े਺ඵ଴͔ͬͯΒղΓʹ͍͘Τϥʔ͕ग़͕ͪ

ຊߨԋͷ಺༰
4"5:4'*ͷ঺հw ։ൃಈ‫ػ‬ɾ໨తҙࣝͷ‫ڞ‬༗
w 11-ʹࢀՃ͞ΕΔํʑͷؔ৺ͱরΒ͠߹Θͤɼ૊൛ॲཧɾจॻ࡞੒ͱ͍ͬͨ༻్ʹཁ੥͞Εͯ
4"5:4'*ʹͲΜͳEPNBJOTQFDJpDͳҙຯ࿦΍‫ܕ‬γεςϜ͕౥ࡌ͞Ε͍ͯΔ͔Λ֓આw ͦͷଞɼ༗ࢤͷํʑʹΑΔ4"5:4'*ύοέʔδ΍पลπʔϧͷ঺հ໨࣍w ։ൃಈ‫ػ‬ɾ໨తҙࣝw ಈ࡞σϞw จࣈ૊൛ͷఆࣜԽͱͦͷ‫͚ͭܕ‬w จॻͷϚʔΫΞοϓํ๏ͷఆࣜԽw ߦ෼ׂॲཧͷ࢓૊Έw ଟஈ֊‫ࢉܭ‬ϕʔεͷϚΫϩ‫ʹߏػ‬ΑΔ%4-w ༗ࢤͷํʑʹΑΔपลπʔϧɾύοέʔδ
w ·ͱΊ



จॻ࡞੒ιϑτ΢ΣΞͷ‫ܗ‬ଶେผͯ͠छྨɿ
ϚʔΫΞοϓ‫ޠݴ‬ʴॲཧ‫ܥ‬

8:4*8:(ΤσΟλɾ[Knuth 1978]
લॲཧ༻్

RE:VIEW[Lamport 1985]

troff[Microsoft 1983] [Adobe 1991][Osanna 1973][੨໦ et al. 2002][Gruber 2004][Quark 1987]



ϚʔΫΞοϓ‫ࣜํޠݴ‬ͷੑ࣭
8:4*8:(ΤσΟλํࣜͱൺ΂ͯɼ܏޲ͱͯ͠ɿ😄
• ࠩ෼؅ཧ͕୯७• ϢʔβఆٛίϚϯυʹΑΓɿ😩
• Ϣʔβ͕ෆద֨ͳίʔυΛೖྗͱͯ͠༩͑΍͍͢• ෳࡶͳࣗಈॲཧ͕࣮‫ݱ‬Մೳ• จॻͷମࡋ͕
‫͔ޙ‬ΒॊೈʹมߋՄೳ͜ͷಛ௃Λ‫͍͔ͨ͠׆‬ਓ͕૝ఆϢʔβͲͷΑ͏ʹΤϥʔ͕ใࠂ͞ΕΔ͔͕
ࣥචޮ཰ʹӨ‫ڹ‬‫ط‬ଘγεςϜͷऑ఺ྫɿ5&9-"5&9

w Τϥʔใࠂ͕ෆ਌੾Ͱ஗͍܏޲ʹ͋Δ
! Undefined control sequence.
! Missing $ inserted.
! Missing number, treated as zero.

r ͜ΕΏ͑ʹɼগ͠‫ॲͨͬڽ‬ཧΛఆٛ͠Α͏ͱ͢Δͱσόοά͕ࠔ೉r ॲཧ‫ܥ‬ͷ࣮૷͕ଵଦͳͷͰ͸ͳ͘ɼ5&9ͷ΋ͭૢ࡞తҙຯ࿦ͷ౎߹্ෆ਌੾ͳΤϥʔʹͳΒ͟ΔΛಘͳ͍ͱ͍͏ଆ໘͕େ͖͍

खͷࠐΜͩࣗಈॲཧ͕ఆٛͰ͖ͭͭɼl໌Β͔ͳϛεzʹ͸਌੾ͳΤϥʔ͕
ग़ͤΔΑ͏ͳߏจɾҙຯ࿦ͷ‫͍ͨ͠ʹޠݴ‬࠷ॳͷҊɿ‫͖ͭܕ‬ͷXSBQQFSΛͭ͘Δ
੩త‫Ͱ͖ͭܕ‬ɼ5&9-"5&9ίʔυΛग़ྗ͢ΔΑ͏ͳ‫ޠݴ‬Λ૑Ε͹Α͍ͷͰ͸ͳ͍͔ʁ

೥ࠒʹ.BDSPEPXOͱ͍͏.-‫͠૷࣮ͯ͠ͱޠݴܥ‬ɼͦΕͳΓʹ࢖͑Δ΋ͷʹ͸ͳͬͨ‫ࡏݦ‬Խͨ͠ऑ఺ɿ

w ϖʔδ਺΍ࢴ໘্ͷ෯ͱ͍ͬͨ૊൛্ͷ֓೦ʹґଘ͢Δॲཧ͸XSBQQFSଆͰ࣮૷͠ʹ͘͘ɼґવͱͯ͠-"5&9ଆͰͷ࣮૷͕ඞཁr ಛʹΫϥεϑΝΠϧͷ࣮૷ͳͲ͸XSBQQFSଆͰ͸౸ఈ‫͍ͳ݁͠׬‬͸ͣ

l5&9‫ޠݴ‬zͷૢ࡞తҙຯ࿦ͷ֓આXSBQQFS‫͕ޠݴ‬༩͑ʹ͔ͬͨ͘ΓΤϥʔใࠂ͕ෆ਌੾ͩͬͨΓ͢ΔཁҼ͸ɼओʹ5&9ͷ΋ͭૢ࡞తҙຯ࿦ͷෳࡶո‫͋ʹ͞ح‬Δɿ

w ࣈ۟ղੳʹ͍ۙ͜ͱ͸͢Δ͕ɼந৅ߏจ໦ͷ֓೦͸ͳ͍w ੍‫ޚ‬௲ʢ\fooʣͷల։͸‫ޙ‬ଓτʔΫϯྻʹର͢ΔύλʔϯϚονϯάr l‫{ހׅ‬ʜ}͕௼Γ߹͍ύλʔϯʹ߹க͢Δ࠷୹ͷτʔΫϯྻzΛҾ਺ͱΈͳ͢w ഁյతʹมߋՄೳͳม਺ͷ‫͕ߏػ‬ଟ༻͞ΕΔ
w ࣈ۟ղੳ͸lMB[ZzͰɼલํͰධՁ૬౰ͷॲཧ͕ߦͳΘΕ͍ͯͯ΋‫ํޙ‬͸·ͩτʔΫϯԽ͞Ε͍ͯͳ͍จࣈྻͰ͋ΓɼલํͷධՁ݁Ռ͕‫ํޙ‬ͷࣈ۟ղੳํ๏Λมߋ͠͏Δw Ҏ্ͷΑ͏ͳෳࡶͳ‫͕ߏػ‬૊൛ॲཧͱີ݁߹Ͱɼආ͚ʹ͍͘੩తʹಛఆͷੑ࣭Λอূ͢Δͱ͍͏ࢼΈ͸͋·Γ๬Έ͕࣋ͯͳ͍
খ͍͞αϒηοτͰ΋͋·Γ‫͍ڧ‬อূ͸Ͱ͖ͳ͍༷ࢠ<&SEXFH0TUFSNBOO>



໨తҙࣝ
-"5&9όοΫΤϯυΛXSBQͨ͠‫ʹͣͤ·ࡁͰޠݴ‬ɼࣗલͰ૊൛ॲཧ·Ͱߦͳ͑Δ‫ॲͱޠݴ‬ཧ‫ܥ‬Λઃ‫ܭ‬ɾ࣮૷͍ͨ͠
ओཁͳཁ݅ɿ

w ຊ࣭తʹ૊൛ॲཧʹؔΘΔΑ͏ͳෳࡶͳࣗಈॲཧ͕Ͱ͖Δ͜ͱr ଞਓͷॻ͍ͨࣗಈॲཧͷ࣮૷΋େ͖ͳࢧোͳ͘ಡΜͰվม͠΍͍͢͜ͱ΋‫ؚ‬Ήw ໌Β͔ͳΤϥʔʹ͍ͭͯ͸੩తʹʢʹ૊൛ॲཧΛ࢝ΊΔΑΓલʹʣ‫ݕ‬஌͠ɼͦͷ‫ݪ‬ҼΛͳΔ΂͘ಛఆ͠΍͍͢‫Ͱܗ‬ใࠂͰ͖Δ͜ͱऄ଍ɿ΋ͬͱࡶͳ໰୊ҙࣝ(*‫ͯ͑׶‬΍΍௅ઓతʹॻ͘ͳΒɿw

5&9-"5&9͸΋ͪΖΜ҃Δ໘Ͱ͸ૉ੖Β͍͠ιϑτ΢ΣΞ͕ͩɼ͜Ε͚ͩ‫ޠݴ‬ઃ‫ܭ‬ͷ஌‫͍ͯͬ·ཷ͕ݟ‬Δ‫Ͱࡏݱ‬΋ѻ͍ʹ͍͘ҙຯ࿦Λ΋ͭ5&9ʹͣͬͱґଘ͠ଓ͚Δͷ͸޻ֶతʹ݈શͳঢ়ଶͱ͸‫͍͘ʹ͍ݴ‬ͷͰ͸ͳ͍͔ʁ

r DG൚༻ͷ‫Ͱޠݴػࢉܭ‬͸༷ʑͳ‫ޠݴ‬ઃ‫͕ܭ‬೔໷ఏҊ͞Ε͍ͯΔ

w ೔ʑϓϩάϥϜͷੑ࣭Λ੩తʹอূ͢Δ͜ͱΛͻͨ͢Β೤৺ʹߟ͍͑ͯΔͷʹɼ͍͟࿦จΛॻ͘ࡍͷಓ۩Ͱ͸ͦͷ݁ՌΛ‫ڗ‬डͤͣෆ਌੾ͳΤϥʔ͹͔Γ‫͍ͯݟ‬Δͷ͸ɼࠠ԰ͷന‫Ͱއ‬͸ͳ͍͔ʁ

*)





੒Ռ෺
৽͍͠૊൛ॲཧγεςϜhttps://github.com/gfngfn/SATySFi

Static Analysis-based TYpesetting System
for Functional Implementationʢ͔ͳΓ‫ڧ‬Ҿͳ͚ͭ͜͡ʣ

ಛ௃ߏจ͕େผͯ͠૚ʹ෼͔Ε͍ͯΔlϚʔΫΞοϓ૚z+section{\SATySFi;ͷ‫<}ྫߘݪ‬+p{
PPLͰ͸\emph{2ճ໨ͷൃද}Ͱ͢ɽ
͓ੈ࿩ʹͳΓ·͢ɽ}lϓϩάϥϜ૚z
let-inline ctx \emph it =let ctx =ctx |> set-font
Latin italic-fontinread-inline ctx it>•-"5&9෩

•ΠϯϥΠϯ{ʜ}ͱ
ϒϩοΫ<ʜ>ͷ۠ผ͕͋Δ•

0$BNM෩

ಛ௃lϓϩάϥϜ૚zͰ͸ίϚϯυఆ͕ٛ0$BNM෩ͷ‫͚ॻͰޠݴ‬Δw lάϩʔόϧͳঢ়ଶzΛ͋·Γ‫ॲʹͣͤʹؾ‬ཧ͕ॻ͚Δr ˞ࢭΉΛಘͣNVUBCMFSFGFSFODFͷ‫ػ‬ೳ͸͋Γɼ࠾൪ͳͲʹ࢖༻w ‫ܕ‬γεςϜΛ༻͍ͨ੩తͳʢʹ૊൛ॲཧʹઌཱͬͨʣΤϥʔใࠂೳྗ
r ௨ৗͷMFUଟ૬ʴЋఔ౓w Ϩίʔυ‫<ࢉܭ‬0IPSJ><3ÉNZ><(BTUFS+POFT>
w ΦϓγϣϯҾ਺r ґଘ‫ܕ‬΍ᝲ‫ܕ‬͸ແ͠r ૊൛ॲཧ΍υΩϡϝϯτॲཧʹؔΘΔଟ਺ͷ‫ج‬ຊ‫ͱܕ‬૊ࠐΈവ਺w ͜Ε͕ࠓճ঺հ͢Δओͳର৅໨࣍w ։ൃಈ‫ػ‬ɾ໨తҙࣝw ಈ࡞σϞw จࣈ૊൛ͷఆࣜԽͱͦͷ‫͚ͭܕ‬w จॻͷϚʔΫΞοϓํ๏ͷఆࣜԽw ߦ෼ׂॲཧͷ࢓૊Έw ଟஈ֊‫ࢉܭ‬ϕʔεͷϚΫϩ‫ʹߏػ‬ΑΔ%4-w ༗ࢤͷํʑʹΑΔपลπʔϧɾύοέʔδ
w ·ͱΊ



ಈ࡞σϞɿਖ਼ৗ‫ܥ‬ʢσϞө૾ɿhttps://drive.google.com/file/d/
1muaWGgyAGfIYJNyKfKvvAzN8vur1sTG3/view?usp=sharingʣಈ࡞σϞɿҟৗ‫ܥ‬ҎԼͷΑ͏ͳʮ͍Ζ͸ՎΛ෯DNͷ࿮Ͱғͬͯ૊Ήʯग़ྗΛ͠Α͏ͱͯ͠
΍Γ͕ͪͳෆద֨ͳίʔυΛॻ͍ͯ͠·ͬͨͱ͖ͷΤϥʔใࠂΛ-"5&9ͱ4"5:4'*Ͱൺֱ"- 5 9ͷ৔߹&ʢσϞө૾ɿhttps://drive.google.com/file/d/
1r14gHwCUxe3DQjoxkGHDWWkwtHWqMwaY/view?usp=sharingʣ

4"5:4'*ͷ৔߹ʢσϞө૾ɿhttps://drive.google.com/file/d/
1DyKB0V2xIKz6SMYNGdEWnupPAxXkWCeE/view?usp=sharingʣ໨࣍
w ։ൃಈ‫ػ‬ɾ໨తҙࣝw ಈ࡞σϞw จࣈ૊൛ͷఆࣜԽͱͦͷ‫͚ͭܕ‬w จॻͷϚʔΫΞοϓํ๏ͷఆࣜԽw ߦ෼ׂॲཧͷ࢓૊Έw ଟஈ֊‫ࢉܭ‬ϕʔεͷϚΫϩ‫ʹߏػ‬ΑΔ%4-w ༗ࢤͷํʑʹΑΔपลπʔϧɾύοέʔδ
w ·ͱΊ





ॲཧ‫ܥ‬ͷߏ੒ͷ໛ࣜਤϑϩϯτΤϯυʢ‫ߏػࠪݕ‬ʣʴόοΫΤϯυʢΠϯλϓϦλʣ
ධՁ‫ث‬
ߏจ
ղੳ‫ث‬
จॻ

‫ثࠪݕܕ‬
ʢίϚϯυΛ‫ؚ‬Ήʣ
ςΩετ

ίϚϯυू

ม‫ث׵‬
“ശ” ͷਫฏͳ࿈ͳΓύοέʔδ‫܈‬

OpenType
ϑΥϯτ

ߦ෼ׂॲཧ
ߦͷ࿈ͳΓ

ϖʔδ෼ׂॲཧ
֤ϖʔδͷ಺༰

PDFग़ྗ‫ߏػ‬ॲཧ‫ܥ‬ͷߏ੒ͷ໛ࣜਤϑϩϯτΤϯυʢ‫ߏػࠪݕ‬ʣʴόοΫΤϯυʢΠϯλϓϦλʣ
ධՁ‫ث‬
ߏจ
ղੳ‫ث‬
จॻ

‫ثࠪݕܕ‬
ʢίϚϯυΛ‫ؚ‬Ήʣ
ςΩετ

ίϚϯυू

ม‫ث׵‬
“ശ” ͷਫฏͳ࿈ͳΓύοέʔδ‫܈‬

OpenType
ϑΥϯτ

ߦ෼ׂॲཧ
ߦͷ࿈ͳΓ

ϖʔδ෼ׂॲཧ
֤ϖʔδͷ಺༰

PDFग़ྗ‫ߏػ‬ॲཧ‫ܥ‬ͷߏ੒ͷ໛ࣜਤධՁ‫ث‬‫ثࠪݕܕ‬
ʢίϚϯυΛ‫ؚ‬ΉʣςΩετ{The quick brown fox ʜ }

ม‫ث׵‬
ʜ

“ശ” ͷਫฏͳ࿈ͳΓ

ߦ෼ׂॲཧ
ߦͷ࿈ͳΓ

ϖʔδ෼ׂॲཧ
֤ϖʔδͷ಺༰

PDFग़ྗ‫ߏػ‬

ʜʜ

OpenTypeϑΥϯτॲཧ‫ܥ‬ͷߏ੒ͷ໛ࣜਤධՁ‫ث‬‫ثࠪݕܕ‬
ʢίϚϯυΛ‫ؚ‬Ήʣ
ςΩετ

ม‫ث׵‬
“ശ” ͷਫฏͳ࿈ͳΓ

OpenType
ϑΥϯτ

ߦ෼ׂॲཧ

ࣗಈॲཧͷ࣮૷Ͱ͸͜ͷ͋ͨΓͷ૊൛ॲཧʹհೖͰ͖ͯ΄͍͠ߦͷ࿈ͳΓϖʔδ෼ׂॲཧ
֤ϖʔδͷ಺༰

PDFग़ྗ‫ߏػ‬ࣗಈॲཧͷఆ͕ٛ‫ʹࠪݕܕ‬௨Ε͹ɼධՁ࣌ʹ͜͜Ͱ
σʔλͷෆ੔߹͕‫͍ͳ͖ى‬Α͏ͳ‫ܕ‬γεςϜΛ༻ҙ͍ͨ͠Ұൠͷ૊൛ॲཧʹԙ͚Δจࣈͷѻ͍ํw άϦϑ glyph ɿਤ‫ͯ͠ͱܗ‬ͷจࣈΛѻ͏୯Ґw άϦϑ͸ϕʔεϥΠϯ baseline Λ‫ج‬४ʹͯ͠ฒͿw ֤άϦϑ͸ҎԼͷσʔλΛ΋ͭɿr Ξ΢τϥΠϯɿࢀর఺ reference point ͔Βͷ૬ର࠲ඪͰ‫ه‬࿥͞Εͨด‫ۂ‬ઢr ਐߦ෯ advance width ɿͦͷจࣈͷ഑ஔʹΑͬͯࢀর఺ΛͲΕ͚ͩਐΊΔ͔Ξ΢τϥΠϯΛͳ͢ͭͷ#É[JFS‫ۂ‬ઢ͕
ͭ͘ΔgͷྖҬ
ϕʔεϥΠϯ

ࢀর఺άϦϑgͷ
ਐߦ෯

࣍ͷࢀর఺



Ұൠͷ૊൛ॲཧʹԙ͚Δจࣈͷѻ͍ํw άϦϑ glyph ɿਤ‫ͯ͠ͱܗ‬ͷจࣈΛѻ͏୯Ґw άϦϑ͸ϕʔεϥΠϯ baseline Λ‫ج‬४ʹͯ͠ฒͿw ֤άϦϑ͸ҎԼͷσʔλΛ΋ͭɿr Ξ΢τϥΠϯɿࢀর఺ reference point ͔Βͷ૬ର࠲ඪͰ‫ه‬࿥͞Εͨด‫ۂ‬ઢr ਐߦ෯ advance width ɿͦͷจࣈͷ഑ஔʹΑͬͯࢀর఺ΛͲΕ͚ͩਐΊΔ͔͞ΒʹҎԼͰߴ͞ͱਂ͞Λఆٛ͠ɼ
άϦϑ͸Ծ૝తͳlശzΛ΋ͭͱΈͳ͢
ߴ͞ɿNBY  ด‫ۂ‬ઢͷ࠷ߴ౸ୡ࠲ඪ w
ߴ͞w ਂ͞ɿNBY   ด‫ۂ‬ઢͷ࠷௿౸ୡ࠲ඪ ϕʔεϥΠϯਂ͞ࢀর఺άϦϑgͷਐߦ෯˞͜Ε͸ීวతͳఆࣜԽͱ·Ͱ͸‫͕͍ͳ͑ݴ‬ɼগͳ͘ͱ΋5&9ͷ૊൛ॲཧ<,OVUI>Ͱ͸࣮࣭తʹ͜Εʹ૬౰͢Δํ๏Λ࠾͓ͬͯΓɼ
4"5:4'*Ͱ΋౿ऻҰൠͷ૊൛ॲཧʹԙ͚Δจࣈͷѻ͍ํw άϦϑ glyph ɿਤ‫ͯ͠ͱܗ‬ͷจࣈΛѻ͏୯Ґw άϦϑ͸ϕʔεϥΠϯ baseline Λ‫ج‬४ʹͯ͠ฒͿw ֤άϦϑ͸ҎԼͷσʔλΛ΋ͭɿr Ξ΢τϥΠϯɿࢀর఺ reference point ͔Βͷ૬ର࠲ඪͰ‫ه‬࿥͞Εͨด‫ۂ‬ઢr ਐߦ෯ advance width ɿͦͷจࣈͷ഑ஔʹΑͬͯࢀর఺ΛͲΕ͚ͩਐΊΔ͔ϕʔεϥΠϯ

จࣈ໨ͷ
ࢀর఺άϦϑgͷਐߦ෯จࣈ໨ͷ
ࢀর఺૊൛ॲཧʹԙ͚ΔจࣈͷఆࣜԽΞ΢τϥΠϯͱਐߦ෯͚ͩͰ͸ࢧোΛ͖ͨ͢৔߹΋͋ΔͷͰɼಛผͳ૊Έ߹Θͤʹରͯ͠ͷΈద༻͞ΕΔॲཧ͕͋Δ

w ϑΥϯτϑΝΠϧ಺ʹͦͷͨΊͷσʔλ͕֨ೲ͞Ε͍ͯΔ
߹ࣈ ligature ɿΧʔχϯά kerning ɿ૬ੑ͕ѱ͍‫ܗ‬ঢ়ͷάϦϑ͕ฒͿͱ͖͸߹ମͯ͠άϦϑʹ͢Δ

ਐߦ෯ʹै͏ͱࣈ͕ؒෆࣗવʹͳΔ૊Έ߹ΘͤͰ͸ௐ੔Λߦͳ͏࣮ࡍʹ૊·Εͨ߹ࣈɾΧʔχϯάͷྫʢσϞ࠶‫ܝ‬ʣlശzͷ࿈ͳΓͱͯ͠ͷߦ΍ஈམάϦϑͷlശz͸ਫฏํ޲ʹฒΜͰlߦzΛͳ͢w ͜ͷlߦzΛΠϯϥΠϯϘοΫεྻͱ‫Ϳݺ‬ʜΠϯϥΠϯํ޲

lߦz͸ߦ෼ׂॲཧ line breaking ʹΑͬͯ੾Γ෼͚ΒΕͯlஈམzʹͳΔ

w ۭനͳͲ͸ద੾ʹ৳ॖ͠ɼߦ௕͕ἧ͏Α͏ʹ੔‫ܗ‬w lஈམz΋ԣʹࡉ௕͍lശz͕Ԗ௚ํ޲ʹ࿈ͳͬͨ΋ͷͰɼϒϩοΫϘοΫεྻͱ‫Ϳݺ‬
ϒ
ϩ
ỽ
Ϋ
ํ
޲

ʜ

ʜ



ૢ࡞ର৅ͱͯ͠ͷϘοΫεྻͷఆࣜԽΠϯϥΠϯϘοΫεྻΛϓϩάϥϜͰૢ࡞͢Δର৅ͱͯ͠௥Ճɿ

v ::= λx . e | ⋯ | ibΠϯϥΠϯ ib ::= [ib]*‫ݸ‬Ҏ্ͷϘοΫεྻ஋

ib ::=||⋮

༗‫ݸݶ‬ͷྻ

| ⋯ |

| ⋯

άϦϑ
ۭന

ΠϯϥΠϯϘοΫεྻʹ͸ྻશମͰinlineboxesͱ͍͏‫ج‬ຊ‫ܕ‬Λ͚ͭΔɿΓ ⊢ ib : inlineboxesҎԼͷ૊ࠐΈവ਺Ͱ࿈݁Ͱ͖Δɿ
(++): inlineboxes → inlineboxes → inlineboxesૢ࡞ର৅ͱͯ͠ͷϘοΫεྻͷఆࣜԽϒϩοΫϘοΫεྻ΋ૢ࡞ର৅ͱͯ͠௥Ճɿ

v ::= λx . e | ⋯ | bbϒϩοΫ‫ݸ‬Ҏ্ͷ༗‫ݸݶ‬ͷྻɼϘοΫεྻ bb ::= [bb]*௚‫ͯ͠ͱ؍‬͸ॎʹ࿈ͳ͍ͬͯΔbb ::=
|
ߦͷ಺༰
⋯
|
ߦؒͷۭന
⋮
஋

ϒϩοΫϘοΫεྻʹ͸ྻશମͰblockboxesͱ͍͏‫ج‬ຊ‫ܕ‬Λ͚ͭΔɿΓ ⊢ bb : blockboxes΍͸Γ૊ࠐΈവ਺Ͱ࿈݁Ͱ͖Δɿ
(+++): blockboxes → blockboxes → blockboxes૊ࠐΈവ਺ʹΑΔߦ෼ׂॲཧͷఏ‫ڙ‬ҎԼͷΑ͏ͳ૊ࠐΈവ਺line-breakͱͯ͠

⏞
v ⋯ v

ߦ෼ׂॲཧΛఏ‫ͯ͠ڙ‬Ϣʔβ͕࢖༻Ͱ͖ΔͱΑͦ͞͏ɿԿΒ͔ͷઃఆ஋ʢߦ௕ͳͲʣ

line-break

1

ʜ

n

ʜ

ʜ

line-breakͷ‫ܕ‬͸ҎԼͷ‫ܗ‬ɿ

τ1 → ⋯ → τn → inlineboxes → blockboxes





͜͜·Ͱͷ·ͱΊw άϦϑͷͳ͢lശz͕ਫฏʹฒΜͩ΋ͷɿΠϯϥΠϯϘοΫεྻib
w ࡉ௕͍lߦͷശz͕ॎʹฒΜͩ΋ͷɿϒϩοΫϘοΫεྻbb
v ::= ⋯
| ib
| bb

w ibͷྫɿʜʜ

w bbͷྫɿʜw ‫ج‬ຊ‫ܕ‬ͷ௥Ճɿτ ::= ⋯ | inlineboxes | blockboxes

w ߦ෼ׂॲཧ͸ҎԼͷ૊ࠐΈവ਺Ͱఏ‫ڙ‬ɿline-break: τ1 → ⋯ → τn → inlineboxes → blockboxes໨࣍w ։ൃಈ‫ػ‬ɾ໨తҙࣝw ಈ࡞σϞw จࣈ૊൛ͷఆࣜԽͱͦͷ‫͚ͭܕ‬w จॻͷϚʔΫΞοϓํ๏ͷఆࣜԽw ߦ෼ׂॲཧͷ࢓૊Έw ଟஈ֊‫ࢉܭ‬ϕʔεͷϚΫϩ‫ʹߏػ‬ΑΔ%4-w ༗ࢤͷํʑʹΑΔपลπʔϧɾύοέʔδ
w ·ͱΊ



จॻͷϚʔΫΞοϓํ๏ͷఆࣜԽ
͜͜·ͰͰϘοΫεྻͷॲཧํ๏ͷେ࿮͸ఆࣜԽͰ͖͕ͨɼ
౰વͳ͕ΒΤϯυϢʔβ͕άϦϑΛ௚઀༩͑ͨΓ͸͠ͳ͍ͷͰɼԿΒ͔ͷϚʔΫΞοϓ͕ࢪ͞ΕͨςΩετ‫ࣜܗ‬ͷ‫͔ߘݪ‬ΒϘοΫεྻ΁ͱม‫࠷ͯ͠׵‬ऴతʹจॻΛ૊ΊΔΑ͏ͳ࢓૊Έ͕ඞཁͲΜͳ‫هͰࣜܗ‬ड़͢Δ‫͢ʹޠݴ‬Δ͔ʁ໨తҙ͔ࣝΒͯ͠ҎԼΛຬ͍ͨͯ͠Δ͜ͱ͕؊ཁɿ

w ԿΒ͔ͷํ๏Ͱ੩తʹଥ౰ੑΛ‫͖Ͱࠪݕ‬Δw Ϣʔβࣗ਎͕ϚʔΫΞοϓʹ࢖͏ίϚϯυΛ৽‫ʹن‬ఆٛͰ͖Δ

"%5Ͱ‫ߘݪ‬Λ‫ه‬ड़͢Δʹ͸໰୊͋Γ
9.-ʹ͍ۙཁྖͰɼ‫ߘݪ‬Λ"%5ʢ୅਺తσʔλ‫ܕ‬ʣͰѻ͏ʁΫϥεϑΝΠϧ͕"%5Λఆٛ͢Δ͜ͱͰϚʔΫΞοϓํ๏Λ‫ن‬ఆ͢Δͱɼ
ΫϥεϑΝΠϧΛ࢖͏ΤϯυϢʔβଆͰ͸ϚʔΫΞοϓͷఆٛΛ֦ு͠ʹ͍͘w ͍ΘΏΔ&YQSFTTJPOQSPCMFN
w 0QFOEBUBUZQFT<-ÖI)JO[F>͕͋Ε͹֦ுͰ͖Δ͕ɼσʔλΛ࢖͏ଆͷവ਺ͷෳࡶԽ͕ґવආ͚ʹ͍͘

r 0$BNMͰ͍͏type t += C of τ&YQSFTTJPOQSPCMFNͱແԑʹͳΔΑ͏ͳఆࣜԽ͸Ͱ͖ͳ͍͔ʁ

͍ΘΏΔ5BHMFTTpOBMతͳఆࣜԽΛ͢ΔͱΑͦ͞͏‫ݱ‬ঢ়ͷ‫هߘݪ‬ड़ํ๏w
w <ʜ>ɿϒϩοΫςΩετ
w \fooɿΠϯϥΠϯίϚϯυ{ʜ}ɿΠϯϥΠϯςΩετ‫ߘݪ‬ͷྫʢ࠶‫ܝ‬ʣɿ+section{\SATySFi;ͷ‫<}ྫߘݪ‬+p{
PPLͰ͸\emph{2ճ໨ͷൃද}Ͱ͢ɽ

r ΠϯϥΠϯςΩετதͷϚʔΫΞοϓ͓ੈ࿩ʹͳΓ·͢ɽ

w +fooɿϒϩοΫίϚϯυ}r ϒϩοΫςΩετதͷϚʔΫΞοϓ>ΠϯϥΠϯςΩετ{it}ͷ‫ࣜܗ‬ɿ

it ::= [it]*it ::= char
| \foo [e]*จࣈʢʹ6OJDPEFίʔυϙΠϯτʣίϚϯυద༻

‫ݱ‬ঢ়ͷ‫ॲߘݪ‬ཧํ๏ͷఆࣜԽ·ͣɼίϚϯυద༻͕ͳ͘จࣈྻ͚ͩͷ৔߹ͷม‫׵‬͸؆୯ɿ

{The quick brown fox jumps ʜ }ม‫ʹ׵‬ඞཁͳ෇Ճ৘ใ

w ϑΥϯτϑΝϛϦʔw จࣈαΠζw จࣈ৭w ⋮ʜ෇Ճ৘ใ͸ͦΕΒΛશ෦ूΊͨϨίʔυͷΑ͏ͳ஋ͱͯ͠
ϓϩάϥϜ্Ͱѻ͏͜ͱʹ͠ɼ͜ͷ஋ΛςΩετॲཧจ຺ͱ‫Ϳݺ‬ςΩετॲཧจ຺ͷఆࣜԽ௕͞ఆ਺ʢྫɿ12ptʣ

v ::= ⋯ | Ctx
Ctx ::= {fontsize = ℓ, …}
τ ::= ⋯ | context

Γ ⊢ Ctx : context

҆қʹߋ৽Ͱ͖ͯ΄͘͠ͳ͍಺༰΋͋ΔͷͰɼϨίʔυͰ͋Δ͜ͱ͸Ϣʔβ͔Β͸‫ͣ͑ݟ‬ɼ֤߲໨ͷlHFUUFSzͱlTFUUFSz͕૊ࠐΈവ਺ͱͯ͠ఆٛ͞Ε͍ͯΔɿ௕͞ͷ‫ܕ‬

w get-font-size: context → lengthr ֨ೲ͞Ε͍ͯΔจࣈαΠζΛऔΓग़͢

w set-font-size: length → context → contextr (Ctx|> set-font-size ℓ)ͰจࣈαΠζΛℓʹߋ৽ͨ͠CtxΛฦ͢ϘοΫεྻ΁ͷม‫׵‬ͷ૊ࠐΈവ਺ҎԼͷΑ͏ͳ૊ࠐΈവ਺read-inlineͱͯ͠ఏ‫ڙ‬ɿread-inline Ctx {The quick brown fox jumpsʜ}ʜ‫ܕ‬͸read-inline: context → inlinetext → inlineboxesΠϯϥΠϯςΩετʹͭ͘‫ج‬ຊ‫ܕ‬ίϚϯυద༻Λ‫ؚ‬Ή৔߹ʹҰൠԽίϚϯυΛద੾ʹఆٛ͢Ε͹ҎԼͷཁྖͰม‫͖Ͱ׵‬ΔΑ͏ʹ͍ͨ͠ɿread-inline Ctx {The \emph{quick brown} foxʜ}ʜ{The \emph{quick brown} fox ʜ }͜ͷద༻ͷ෦෼ΛʮςΩετॲཧจ຺Λड͚औΔͱ
ΠϯϥΠϯϘοΫεྻʹͳΔ΋ͷʯͱଊ͑Δ\emph{quick brown}: context → inlineboxesͱΈͳͤΔ\emph: inlinetext → context → inlineboxesͱΈͳͤΔ

ίϚϯυఆٛ
\emph: inlinetext → context → inlineboxes͸ҎԼͷΑ͏ʹఆٛͰ͖ͦ͏ɿ
let \emph (it : inline-text) (ctx : context) =let ctx = ctx |> set-italic-font inread-inline ctx itϑΥϯτΛΠλϦοΫମʹߋ৽͢Δɼcontext → context‫ܕ‬ͷิॿവ਺࣮ࡍͷ4"5:4'*Ͱ͸ҎԼͰ\emphΛఆٛ͢Δɿ
ςΩετॲཧจ຺Λड͚औΔม਺͕ߏจ্Ͱखલʹདྷ͚ͨͩ

let-inline ctx \emph it =let ctx = ctx |> set-italic-font inread-inline ctx itίϚϯυద༻ͷධՁͷΠϝʔδ
read-inline Ctx {The \emph{quick brown} foxʜ}ʜͱ͍͏ධՁͷ్த‫ܦ‬աΛ‫ͯݟ‬ΈΔ

Ctx
The \emph{quick brown} foxʜίϚϯυద༻ͷධՁͷΠϝʔδ
read-inline Ctx {The \emph{quick brown} foxʜ}ʜͱ͍͏ධՁͷ్த‫ܦ‬աΛ‫ͯݟ‬ΈΔCtx\emph{quick brown} foxʜίϚϯυద༻ͷධՁͷΠϝʔδ
read-inline Ctx {The \emph{quick brown} foxʜ}ʜͱ͍͏ධՁͷ్த‫ܦ‬աΛ‫ͯݟ‬ΈΔCtx\emph{quick brown} foxʜ
let-inline ctx \emph it =let ctx = ctx |> set-italic-font inread-inline ctx itίϚϯυద༻ͷධՁͷΠϝʔδ
read-inline Ctx {The \emph{quick brown} foxʜ}ʜͱ͍͏ධՁͷ్த‫ܦ‬աΛ‫ͯݟ‬ΈΔCtx\emph{quick brown} foxʜ
let-inline ctx \emph it =let ctx = ctx |> set-italic-font inread-inline ctx it

Ctx ͷϑΥϯτΛΠλϦοΫʹߋ৽ͨ͠จ຺Ctx′͕ͭ͘ΒΕɼೖΕࢠͰread-inline Ctx′ {quick brown}͕ධՁ͞ΕΔ

ίϚϯυద༻ͷධՁͷΠϝʔδ
read-inline Ctx {The \emph{quick brown} foxʜ}ʜͱ͍͏ධՁͷ్த‫ܦ‬աΛ‫ͯݟ‬ΈΔCtx\emph{quick brown} foxʜCtx′
quick brownίϚϯυద༻ͷධՁͷΠϝʔδ
read-inline Ctx {The \emph{quick brown} foxʜ}ʜͱ͍͏ධՁͷ్த‫ܦ‬աΛ‫ͯݟ‬ΈΔCtx\emph{quick brown} foxʜ

Ctx′
brown



ίϚϯυద༻ͷධՁͷΠϝʔδ
read-inline Ctx {The \emph{quick brown} foxʜ}ʜͱ͍͏ධՁͷ్த‫ܦ‬աΛ‫ͯݟ‬ΈΔCtx\emph{quick brown} foxʜ

Ctx′



ίϚϯυద༻ͷධՁͷΠϝʔδ
read-inline Ctx {The \emph{quick brown} foxʜ}ʜͱ͍͏ධՁͷ్த‫ܦ‬աΛ‫ͯݟ‬ΈΔ

Ctx
foxʜ

໭Γ஋͕ίϚϯυద༻ͷ͋ͬͨՕॴʹૠೖ͞ΕΔ

ίϚϯυద༻ͷධՁͷΠϝʔδ
read-inline Ctx {The \emph{quick brown} foxʜ}ʜͱ͍͏ධՁͷ్த‫ܦ‬աΛ‫ͯݟ‬ΈΔ

Ctx
foxʜ

ίϚϯυద༻ͷධՁͷΠϝʔδ
read-inline Ctx {The \emph{quick brown} foxʜ}ʜͱ͍͏ධՁͷ్த‫ܦ‬աΛ‫ͯݟ‬ΈΔ

Ctx
ʜ



ίϚϯυͷ‫ܕ‬\emph͸࣮ࡍͷ4"5:4'*Ͱ͸[inlinetext] inlinecmd‫͚͕ͭܕ‬ΒΕΔ

w લड़ͷ௨Γҙຯ࿦తʹ͸inlinetext → context → inlineboxes‫ܕ‬ͷവ਺
let-inline ctx \emph it =let ctx = ctx |> set-italic-font inread-inline ctx itΑΓҰൠʹɼτ1, …, τn‫ܕ‬ͷҾ਺ΛͱΔnҾ਺ͷίϚϯυ͸[τ1; …; τn] inlinecmd‫͚͕ͭܕ‬ΒΕΔ

w ҙຯ࿦తʹ͸τ1 → ⋯ → τn → context → inlineboxes‫ܕ‬ͷവ਺w ͜ͷ‫ʹ͚ͭܕ‬ΑΓɼ‫ߘݪ‬Λॻ͘ࡍ͸ςΩετॲཧจ຺Λҙࣝ͢Δඞཁ͕ͳ͘ͳΔϒϩοΫςΩετͷ৔߹ϒϩοΫςΩετ<bt>ͷཁૉ͸ίϚϯυద༻ͷΈɿ

bt ::= [bt]*bt ::= +foo [e]*ϒϩοΫίϚϯυ΋ಉ༷ʹτ1 → ⋯ → τn → context → blockboxes‫ܕ‬ͷവ਺ͱΈͳͤͯɼ[τ1; …; τn] blockcmd‫ܕ‬Λ͚ͭͯѻ͏
read-block: context → blocktext → blockboxesஈམΛ૊ΉίϚϯυ+p͸ҎԼͷ‫Ͱܗ‬ఆٛͰ͖ɼ[inlinetext] blockcmd‫ܕ‬
let-block ctx +p it = ʜʢ+pͷ࣮૷ํ๏͸࣍અͰ‫ޙ‬ड़ʣ͜͜·Ͱͷ·ͱΊw ΠϯϥΠϯςΩετɼϒϩοΫςΩετɼςΩετॲཧจ຺Λ௥Ճɿv ::= ⋯ | ib | bb | {it} | <bt> | Ctx
it ::= [it]*bt ::= [bt]*it ::= char | \foo [e]*bt ::= +foo [e]*τ ::= ⋯ | inlineboxes | blockboxes | inlinetext | blocktext| context | length | [[τ]*] inlinecmd | [[τ]*] blockcmd

w ૊ࠐΈവ਺
r line-break: τ1 → ⋯ → τn → inlinetext → inlineboxes
r read-inline: context → inlinetext → inlineboxes
r read-block: context → inlinetext → inlineboxesr ςΩετॲཧจ຺ͷHFUUFSͱTFUUFS
w get-font-size: context → length





͜͜·Ͱͷ·ͱΊ
ϒϩοΫ

ΠϯϥΠϯ

ς
Ω
ε
τ

{The quick brown fox jumps ʜ }read-inline

read-block

ʜ
ʜ
ʜ

Ϙ
ỽ
Ϋ
ε
ྻ

< +p{
The quickbrown fox ʜ} >line-break໨࣍w ։ൃಈ‫ػ‬ɾ໨తҙࣝw ಈ࡞σϞw จࣈ૊൛ͷఆࣜԽͱͦͷ‫͚ͭܕ‬w จॻͷϚʔΫΞοϓํ๏ͷఆࣜԽw ߦ෼ׂॲཧͷ࢓૊Έw ଟஈ֊‫ࢉܭ‬ϕʔεͷϚΫϩ‫ʹߏػ‬ΑΔ%4-w ༗ࢤͷํʑʹΑΔपลπʔϧɾύοέʔδ
w ·ͱΊ



࣮ࡍͷߦ෼ׂॲཧͷ૊ࠐΈവ਺line-break b1 b2 Ctx

ʜ

ʜ

ʜ

line-break: bool → bool → context → inlineboxes → blockboxeswb1ɼb2ɿͭͷਅِ஋r ߦ෼ׂॲཧࣗମͱؔΘΔઃఆ஋Ͱ͸ͳ͍ͷͰࠓճ͸৮Εͳ͍w CtxɿςΩετॲཧจ຺

r ߦ௕ͳͲɼߦ෼ׂॲཧʹඞཁͳઃఆ஋͸͔͜͜ΒऔΓग़ͯ͠࢖͏

ߦ෼ׂॲཧͷ࢓૊Έߦ෼ׂॲཧ໰୊

w ೖྗɿΠϯϥΠϯϘοΫεྻibɼॴ๬ͷߦ௕ℓr ଞͷύϥϝʔλ͸ᘭ຤ͳͷͰࠓճ͸ࣺ৅͢Δ

w ग़ྗɿibΛۭനΛద੾ʹ৳ॖ͢ΔͳͲ֤ͯ͠ߦͷ௕͕͞ℓʹͳΔΑ͏ʹ੾Γ෼͚ͯͰ͖ΔϒϩοΫϘοΫεྻͷ͏ͪ࠷΋‫ݟ‬ө͑ͷྑ͍΋ͷr ‫ݟ‬ө͑ͷྑ͞͸ԿΒ͔ͷධՁํ๏Ͱద੾ʹఆٛ͢Δඞཁ͋Γ˞lલ͔Βॱʹ٧Ί͍͖ͯɼᷓΕͨΒͦ͜Ͱߦ෼ׂzͱ͍͏ᩦཉ๏Ͱ͸Ұൠʹ͸࠷ྑͷ݁Ռʹ͸ͳΒͳ͍

4"5:4'*ͷߦ෼ׂॲཧͰ͸ɼ5&9ͷͨΊʹఏҊ͞Εͨ,OVUIr1MBTTΞϧΰϦζϜ<,OVUI1MBTT>ͷఆࣜԽΛ౿ऻw ଟগͷಠ֦ࣗு͋Γ,OVUIr1MBTTΞϧΰϦζϜ<,OVUI1MBTT>ߦ෼ׂॲཧ໰୊ΛॏΈ͖ͭ༗޲ඇ८ճάϥϑ্ͷ࠷୹‫ܦ‬࿏໰୊ʹ‫ؼ‬ண͢Δ
಺༰ibͱߦ௕ࢦఆℓ͔ΒG = (V, E; d)Λߏ੒w ௖఺ू߹V := ( ib தͷߦ෼ׂՄೳͳՕॴશମ ) ⊎ {ઌ಄, ຤ඌ}r ໛ࣜਤɿ ઌ಄

v1

v2

v3

v4

v5

຤ඌ

ʜ

v

p

v′

w ลʢib಺Ͱv͸v′ΑΓ΋खલͷ఺ʣr lvͰߦ෼ׂͯͦ͠ͷ࣍ʹv′Ͱߦ෼ׂͨ͠ͱ͖ɼvͱv′ͷؒͷ಺༰Λ௕͕͞ℓʹͳΔΑ͏ʹߦͱͯ͠૊Ήͱɼͦͷ‫ݟ‬ө͑ͷධՁ͸pz

w p͸େ͖͍΄Ͳ‫ݟ‬ө͕͑ѱ͍͜ͱΛද͢ϖφϧςΟ஋ʢܾఆํ๏͸࣍ทͰઆ໌ʣ
Gͷʮઌ಄ʯ͔Βʮ຤ඌʯ΁ࢸΔ࠷୹‫ܦ‬࿏Λ‫ٻ‬ΊΔͱɼͦΕ͕௨Δ֤௖఺͕
ϖφϧςΟ૯࿨Λ࠷খԽ͢Δʢʹ࠷΋‫ݟ‬ө͑ͷྑ͘ͳΔʣ੾Γ෼͚Օॴߦͷ‫ݟ‬ө͑ͷධՁํ๏

<,OVUI1MBTT>ߦ෼ׂީิՕॴvͱͦͷ࣍ͷީิՕॴv′ΛܾΊͨΒɼۭനΛ৳ॖͯ͠

vͱv′ͷؒͷ಺༰͕௕͞ℓʹͳΔΑ͏ʹ͠ɼͦͷ‫ݟ‬ө͑ΛධՁ

v

v′

ℓ
‫ݟ‬ө͑ධՁͷͨΊʹɼۭന͸ࣗવ௕ ৳ͼΔ‫ڐ‬༰ྔ ॖΉ‫ڐ‬༰ྔ ͱ͍͏ͭͷύϥϝʔλΛ͍࣋ͬͯΔ

w όωͷΑ͏ͳΠϝʔδw ࣗવ௕ʹ͍ۙ΄Ͳ‫ݟ‬ө͕͑ྑ͍
͜ͱΛද͢ɼԼʹತͳධՁവ਺Λ΋ͭ

࠷΋
ϖ
φ ृѱ
ϧ
ς
ỹ
஋
࠷ྑ
࠷
୹

ࣗ
વ
௕

࠷
௕

ҰൠԽ͞Εͨߦ෼ׂՄೳՕॴͷࢦఆํ๏࣮ࡍͷߦ෼ׂՄೳՕॴ͸୯‫ؒޠ‬ͷۭന͚ͩͱ͸‫ݶ‬Βͣɼ΋͏গ͠ҰൠԽ͞Εͨ࢓૊Έʹͳ͍ͬͯΔib ::= [ib]*ib ::=
|

| ⋯ |

ib
|
{ib / ib}
p
⋮

ib0
ɿ
{ib1 / ib2}
p

| ⋯

άϦϑ
৳ॖ͢Δۭന
EJTDSFUJPOBSZCSFBLl͜͜Ͱߦ෼ׂ͢Δ͔͠ͳ͍͔બ΂Δɽߦ෼ׂ͠ͳ͍ͳΒib0ͱ౳ՁͰ͋ΓɼҰํ͜͜Ͱߦ෼ׂ͢ΔͳΒखલͷߦ຤ʹib1Λɼ‫ํޙ‬ͷߦ಄ʹib2ΛͦΕͧΕ݁߹͠ɼ͔ͭ
෼ׂͦͷ΋ͷʹΑΓϖφϧςΟp͕ੜ͡Δz{ε / ε}100୯‫ؒޠ‬ͷۭന͸ͱද‫͞ݱ‬ΕΔ

εɿۭྻ



%JTDSFUJPOBSZCSFBLʹΑΔछʑͷߦ෼ׂͷද‫ݱ‬
EJTDSFUJPOBSZCSFBLͷ࢓૊ΈʹΑΓ༷ʑͳߦ෼ׂํ๏͕ද‫͖Ͱݱ‬Δɿ

w ϋΠϑωʔγϣϯʹΑΔ୯‫ޠ‬தͰͷߦ෼ׂɿε{ / ε}1000
r ୯‫ޠ‬தͷҰ෦Օॴ͸ߦ෼ׂͯ͠Α͘ɼ෼ׂ࣌͸खલͷߦ຤ʹϋΠϑϯ͕ೖΔ
w ྫɿlUBCMFz͸lUBCMFzͱ෼ׂͯ͠Α͍ͷͰ্ਤͷΑ͏ʹѻ͏w ӳ‫ͱͩޠ‬෼ׂͯ͠Α͍Օॴ͸୯‫͍ͯͬ·ܾʹͱ͝ޠ‬Δ͕ɼ۪௚ʹදҾ͖ͤͣͱ΋
-JBOHr,OVUIΞϧΰϦζϜ<-JBOH>ͱ͍͏ਪఆํ๏͕࢖͑Δr ϋΠϑωʔγϣϯ͸୯‫Ͱؒޠ‬ͷ෼ׂΑΓ΋޷·͘͠ͳ͍ͱ͍͏͜ͱΛ൓ө͠ɼϖφϧςΟΛߴΊʹઃఆr ࣮ࡍ͸୯‫ޠ‬தͰ෼ׂ͢Δ͔͠ͳ͍͔Ͱ߹ࣈʹ͢Δ͔΍Χʔχϯά͢Δ͔͕
มΘΓ͏ΔͷͰ΋͏গ͠ෳࡶͳ࢓૊Έ

%JTDSFUJPOBSZCSFBLʹΑΔछʑͷߦ෼ׂͷද‫ݱ‬w ࿨จ૊൛r ҎԼͷΑ͏ͳ‫ن‬ଇʹ͓͓Αͦ४‫ڌ‬w ʰ೔ຊ‫ޠ‬૊൛ॲཧͷཁ݅ʱɼ௨শ+-SFR<8$೔ຊ‫ޠ‬૊൛λεΫϑΥʔε>
w 6OJDPEF-JOF#SFBLJOH"MHPSJUIN<6OJDPEF$POTPSUJVN>

r େ఍ͷจࣈؒ͸ߦ෼ׂͯ͠Α͍w ‫ݪ‬ଇͱ֤ͯ͠จࣈؒʹࣗવ௕ͷۭനΛ΋ͭEJTDSFUJPOBSZCSFBL͕ೖΔ{ε / ε}100{ε / ε}100r ͨͩ͠ɼߦ಄ߦ຤‫ې‬ଇ͸͋Δ
w ߦ಄ෆՄͷจࣈɿด͡‫ހׅ‬ɼ۟ಡ఺ɼʮΌʯɼʮʔʯͳͲ
w ߦ຤ෆՄͷจࣈɿ։͖‫Ͳͳހׅ‬{ε / ε}100{ε / ε}100{ε / ε}100%JTDSFUJPOBSZCSFBLʹΑΔछʑͷߦ෼ׂͷද‫ݱ‬r ߦ಄ͷ։͖‫ހׅ‬ͷ௚લ΍ɼߦ຤ͷด͡‫ހׅ‬΍۟ಡ఺ͷ௚‫ޙ‬͸ɼߦதͱ͸ҟͳΓೋ෼ΞΩʢʹ͍ΘΏΔ൒֯෯ͷۭനʣΛೖΕͳ͍w ֘౰Օॴ͸ࣗવ௕͕ೋ෼ΞΩͷۭനΛ΋ͭEJTDSFUJPOBSZCSFBLʹͳΔ{ε / ε}100{ε / ε}100{ε / ε}100{ε / ε}100{ε / ε}100





ߦ෼ׂॲཧͷར༻ྫஈམΛ૊ΉίϚϯυ+p: [inlinetext] blockcmd͸૊ࠐΈവ਺line-breakΛ༻͍࣮ͯ૷ɿ
let-block ctx +p it =let ib = read-inline ctx it in
let indent = inline-skip (get-font-size ctx) inline-break true true ctx (indent ++ ib ++ inline-fil)ଞͷ૊ࠐΈവ਺ɿ

indentw inline-skip: length → inlineboxesr ࢦఆͨ͠௕͞ͷ৳ॖͰ͖ͳ͍ۭനΛฦ͢r ͜͜Ͱ͸ஈམ๯಄ͷࣈԼ͛ʹ࢖༻

w inline-fil: inlineboxes

ibʜ

inline-filr ࣗવ௕͕Ͱɼ͔ͭϖφϧςΟͳ͘Ͳ͜·Ͱ΋৳ͼΒΕΔಛघͳۭന
r ͜͜Ͱ͸ʮஈམ࠷ऴߦ͸ߦ຤·Ͱ౸ୡ͠ͳͯ͘Α͍ʯ͜ͱͷ࣮‫༻࢖ʹݱ‬໨࣍w ։ൃಈ‫ػ‬ɾ໨తҙࣝw ಈ࡞σϞw จࣈ૊൛ͷఆࣜԽͱͦͷ‫͚ͭܕ‬w จॻͷϚʔΫΞοϓํ๏ͷఆࣜԽw ߦ෼ׂॲཧͷ࢓૊Έw ଟஈ֊‫ࢉܭ‬ϕʔεͷϚΫϩ‫ʹߏػ‬ΑΔ%4-w ༗ࢤͷํʑʹΑΔपลπʔϧɾύοέʔδ
w ·ͱΊ



จॻ‫ه‬ड़্ͷߋͳΔ໰୊ҙࣝw ੩తʹ‫Ͱ͔͓͕͛ͭ͘ܕ‬ਝ଎Ͱଟ͘ͷ৔߹਌੾ͳΤϥʔใࠂ͕ߦͳΘΕɼ҃Δఔ౓࢖͍΍͍͢΋ͷʹͳͬͨr ͱΓΘ͚ύοέʔδͷ࣮૷ʹ͸ͳ͔ͳ͔ҖྗΛൃ‫ش‬
w 5&9-"5&9ͱ4"5:4'*྆ํͰ೤৺ʹύοέʔδΛॻ͔ΕΔํʹ
ʢ5&9ͱൺ΂ͯʣʮϓϩάϥϛϯά‫ͯ͠ͱޠݴ‬͸໌Β͔ʹָʯͱ͍͏‫ײ‬૝Λ໯͑ͨw ҰํͰɼ‫͚ͭܕ‬ͷ౎߹্Ͳ͏ͯ͠΋‫ߘݪ‬ͷ‫ه‬ड़͕൥ࡶʹͳͬͯ͠·͏৔໘͕ग़ͯ͘Δr ಛʹจॻ࡞੒ͷ༻్Ͱ͸ʢ൚༻ͷ‫ޠݴػࢉܭ‬Ҏ্ʹʣෳࡶͳσʔλ΋؆ܿʹ‫ه‬ड़Ͱ͖Δ͜ͱΛ๬·Ε͕ͪ‫ه‬ड़ෳࡶԽʹର͢ΔφΠʔϰͳճආࡦ‫಺ޠݴ‬%4-ͷಋೖw จࣈྻΛड͚औͬͯߏจղੳ͢ΔΑ͏ʹίϚϯυΛఆٛ͢Δ
w ؆୯ͳྫɿ͋Έͩ͘͡ͷ‫ه‬ड़ΛΞεΩʔΞʔτͰͰ͖ΔΑ͏ʹ͢Δ
̙
̨
̡
ํ
ࣜ

\amidakuji(```|X|-|=|/| || |-|\|-|X||=|X|-|\|=||-|\|-|=|-||X|=|-|\| |
```);

௨
ৗ
ͷ
࣮
૷

\amidakuji([[Cross; Line; ʜ ];[Empty; Line; ʜ ];[Double; Cross; ʜ ];
ʜ
]);



φΠʔϰͳճආࡦͷ໰୊఺ͱͦͷղܾࡦ
%4-ͷղऍ͸ಈతʹʢʹ૊൛ॲཧ։࢝‫ʹޙ‬ʣߦͳΘΕΔͨΊɼΤϥʔ͕͋ͬͨ৔߹ʹൃ‫͕ݟ‬஗͍

w %4-Λ࢖͚ͬͨͩͰಈతʹΤϥʔ͕ग़Δੈքʹ‫ٯ‬໭Γ
%4-ͷղऍ͸૊൛ॲཧʹґଘ͢Δ͜ͱͳ͘ՄೳͳͷͰɼ‫ޠݴ‬ຊମʹϚΫϩ‫ߏػ‬Λಋೖͯ͠લॲཧͰ͖ΔΑ͏ʹ͢Ε͹Α͍͔҆͠͠қʹϚΫϩ‫ߏػ‬ΛೖΕΔͱࠓ౓͸Τϥʔ͕ෆ਌੾ʹͳΓ΍͍͢ͷͰɼ
Ͱ͖Δ͚ͩ‫ݪ‬ҼͷΘ͔Γ΍͍͢Τϥʔ͕ग़Δ࢓૊Έʹ͍ͨ͠ଟஈ֊‫ ࢉܭ‬multi-stage programming ʹ‫ͮ͘ج‬ϚΫϩ‫ߏػ‬Λಋೖ͠Α͏





ଟஈ֊‫ͱࢉܭ‬͸w ಈతʹίʔυΛੜ੒ͯ͠ߋʹͦΕΛ࣮ߦ͢ΔΑ͏ͳ‫ߏػ‬Λඋ͑ͨɼ
‫͕ࢉܭ‬ෳ਺ͷεςʔδ stage ͔ΒͳΔମ‫ܥ‬ʴͦͷΑ͏ͳૢ࡞Λ҆શʹߦͳ͏ͨΊͷ‫ܕ‬γεςϜw

ྫɿ.FUB.-<5BIB4IFBSE>ɼЕ˓<%BWJFT>ɼ
.FUB0$BNM<,JTFMZPW>ɼଞଟ਺

w ಛʹεςʔδͷ৔߹ɿୈεςʔδʢʹl௨ৗͷධՁzʣୈεςʔδʢʹlલॲཧzʣw ৄࡉ͸໌೔ʂɿ

ϚΫϩ‫ߏػ‬ͷ‫ޠݴ‬ઃ‫ܭ‬εςʔδͷ.FUB.-<5BIB4IFBSE>Λϕʔεʹͨ͠.BDSP.-<(BO[ 4BCSZ5BIB>ʹ͍ۙϚΫϩ‫ߏػ‬ͷఆࣜԽΛ࠾༻w ϚΫϩͷ࢖༻ྫɿ
\repeat@~(3){\foo{A}}% ௨ৗͷධՁ͕࢝·ΔλΠϛϯάͰ͸ɼ࠷ॳ͔Β% \foo{A}\foo{A}\foo{A} ͱॻ͍ͯ͋ͬͨͷͱಉ͡ѻ͍ʹͳΔr ~(ʜ)͸ϚΫϩల։தʹ࢖ΘΕΔୈεςʔδͷ஋ͷҾ਺r ~ͳ͠ͷҾ਺͸ల։‫ޙ‬ͷίʔυͷҰ෦ͱͳΔ

w ϚΫϩͷఆٛࣗମ͕ల։ΑΓલʹ‫ࠪ͞ݕܕ‬Εɼ‫͚͕ͭܕ‬͹ల։݁Ռ͸ඞͣXFMMUZQFEw య‫ܕ‬తʹ͸ϚΫϩల։ʢʹίʔυੜ੒ʣ͸ҰॠͰऴΘΔͷͰɼϚΫϩల։தʹQBOJD͢Ε͹lࣄ্࣮੩తʹzΤϥʔ͕ใࠂ͞ΕΔ
‫ࠪݕܕ‬

ϚΫϩల։
௨ৗͷධՁ



ϚΫϩ‫ʹߏػ‬ΑΔ%4-ॲཧୈεςʔδͷҾ਺ͱͯ͠%4-Λ‫ه‬ड़͢Δɿ

\amidakuji@~(@```|X|-|=|/| || |-|\|-|X||=|X|-|\|=||-|\|-|=|-||X|=|-|\| |
```);

ల։

\amidakuji([[Cross; Line; ʜ ];[Empty; Line; ʜ ];[Double; Cross; ʜ ];ʜ]);w ϚΫϩల։࣌ʹ%4-Λॲཧ͠ɼߏจΤϥʔ͕͋Ε͹QBOJD͢Δr Τϥʔ͸lࣄ্࣮੩తʹzʹग़Δ
r %4-ίʔυதͷͲ͕͜‫ݪ‬ҼͰΤϥʔ͕‫͔͖ͨى‬ΛϚΫϩ಺͔ΒΘ͔Γ΍͘͢ใࠂͰ͖ΔΑ͏ʹɼઌ಄Ґஔ͕ͲͷϑΝΠϧͷԿߦ໨͔
ࣗಈͰิΘΕΔจࣈྻϦςϥϧ@`ʜ`Λ࢖͏w ਖ਼ৗʹల։͞Εͨ৔߹ɼ݁ՌͷςΩετ͸ධՁ࣌ʹ௨ৗͲ͓ΓॲཧϚΫϩ‫ߏػ‬ͷಈ࡞σϞɿਖ਼ৗ‫ܥ‬ʢσϞө૾ɿhttps://drive.google.com/file/d/
1l9HeT6Hn_lNn0ptVobVDYwW6T9A8xKvZ/view?usp=sharingʣϚΫϩ‫ߏػ‬ͷಈ࡞σϞɿҟৗ‫ܥ‬ʢσϞө૾ɿhttps://drive.google.com/file/d/
1pbTOSWiflEkTghS3TzlerG5NCcb2iIoI/view?usp=sharingʣ໨࣍
w ։ൃಈ‫ػ‬ɾ໨తҙࣝw ಈ࡞σϞw จࣈ૊൛ͷఆࣜԽͱͦͷ‫͚ͭܕ‬w จॻͷϚʔΫΞοϓํ๏ͷఆࣜԽw ߦ෼ׂॲཧͷ࢓૊Έw ଟஈ֊‫ࢉܭ‬ϕʔεͷϚΫϩ‫ʹߏػ‬ΑΔ%4-w ༗ࢤͷํʑʹΑΔपลπʔϧɾύοέʔδ
w ·ͱΊ



༗ࢤͷํʑʹΑΔπʔϧɾύοέʔδ͋Γ͕͍ͨ͜ͱʹ༗ࢤͷํʑʹΑͬͯछʑͷपลπʔϧ΍ύοέʔδͷ։ൃ͕ਐߦத
•4"5:4'*༻ύοέʔδϚωʔδϟ4BUZSPHSBQIPT<4BLBNPUP>

– github.com/na4zagin3/satyrographos– 0$BNMͷύοέʔδϚωʔδϟͰ͋Δ01".ͱซ༻͢Δઃ‫ܭ‬– ϑΥϯτ΍ઃఆϑΝΠϧ΋؅ཧՄೳ

•ొ࿥͞Ε͍ͯΔύοέʔδҰཡ͕‫ݟ‬ΒΕΔϖʔδ<.BUTVOBHB>
– satyrographos-packages.netlify.app– ‫ࡏݱ‬໿ 50 ύοέʔδ• TBUZTGJCBTF</JTIJXBLJ .VSBTF,BOFLP>
– github.com/nyuichi/satysfi-base–ඪ४ϥΠϒϥϦͷେ෯֦ॆ–ύʔαίϯϏωʔλͳͲ΋༻ҙ͞Ε͍ͯΔ༗ࢤͷํʑʹΑΔπʔϧɾύοέʔδ• FBTZUBCMF<monaqa> github.com/monaqa/satysfi-easytable–ද૊ΈΛ؆ܿʹ࣮‫͢ݱ‬ΔͨΊͷύοέʔδ• NBUSJYDE<"CF> github.com/abenori/satysfi-matrixcd– -"5&9ͷUJL[DEͷΑ͏ʹՄ‫׵‬ਤࣜΛඳͨ͘Ίͷύοέʔδ• NBLFMBUFY<,BOFLP> github.com/puripuri2100/SATySFi-make-latex– ςΩετग़ྗϞʔυʹΑΓɼ4"5:4'*ιʔεΛ-"5&9ιʔεʹม‫ͯ͠׵‬ग़ྗ͢ΔͨΊͷύοέʔδ•‫ޠݴ‬ଆͰѻ͑ͳ͍͜ͱʹΑΓ਺ࣜ͸ະରԠ• 4UFBNFS<*TIJJ>ɼ4-Z%*'J<monaqa>
––github.com/konn/satysfi-steamer
github.com/monaqa/slydifi–͍ͣΕ΋εϥΠυ࡞੒༻ͷΫϥεϑΝΠϧ

ଞʹ΋਺ଟ͘ͷπʔϧ΍ύοέʔδ͕ެ։͞Ε͍ͯ·͢એ఻#൑ϖʔδແঈެ։தɿ
https://booth.pm/
ja/items/1127224

satysfi book

‫ࡧݕ‬



ँࣙ
ҎԼͷํʑʹਂ͘‫ँײ‬ਃ্͛͠·͢ɿw ։ൃΛࢧԉ௖͍ͨօ༷
r ೥౓*1"ະ౿*5ਓࡐൃ۷ɾҭ੒ࣄ‫ۀ‬r ‫ࣜג‬ձࣾυϫϯΰʢΞϧόΠτͱͯ͠ʣ
r 5IF4"5:4'*CPPLΛ͝ߪೖ௖͍ͨօ༷

w ೤৺ʹ1VMM3FRVFTU΍ॿ‫ݴ‬ΛԼͬͨ͞։ൃऀͷօ༷
r %BJLJ.BUTVOBHB matsud224 ͞Μɼ%BJDIJ0PIBTIJ leque ͞Μɼ/PSJBLJ4BLBNPUP na4zagin3 ͞Μɼ5BLVNB*TIJLBXB nekketsuuu ͞Μɼ
elpinal͞Μɼ.BTBLJ)BSB qnighy ͞Μɼsakas--͞Μɼଞଟ਺໊

w ύοέʔδɾपลπʔϧ։ൃऀͷօ༷
w 4"5:4'*4MBDLɾ4"5:4'*$POG౳ɼίϛϡχςΟΛӡӦͯ͠Լ͞Δօ༷
r /BPLJ,BOFLP puripuri2100 ͞Μɼmonaqa͞Μɼଞଟ਺໊໨࣍w ։ൃಈ‫ػ‬ɾ໨తҙࣝw ಈ࡞σϞw จࣈ૊൛ͷఆࣜԽͱͦͷ‫͚ͭܕ‬w จॻͷϚʔΫΞοϓํ๏ͷఆࣜԽw ߦ෼ׂॲཧͷ࢓૊Έw ଟஈ֊‫ࢉܭ‬ϕʔεͷϚΫϩ‫ʹߏػ‬ΑΔ%4-w ༗ࢤͷํʑʹΑΔपลπʔϧɾύοέʔδ
w ·ͱΊ



·ͱΊ
വ਺‫ܕ‬ͷ‫ޠݴ‬ઃ‫ܭ‬Λϕʔεͱ͢Δɼ੩త‫͖ͭܕ‬ͷ૊൛ॲཧγεςϜ4"5:4'*ʹ͍ͭͯ঺հ͠·ͨ͠w ҙຯ࿦্ͷओͳಛ௃ɿ
r ϘοΫεྻʹΑΔάϦϑͳͲͷऔΓѻ͍r ςΩετͱจ຺ΛϘοΫεྻʹม‫͢׵‬Δവ਺ͱͯ͠ͷίϚϯυr छʑͷ૊ࠐΈവ਺Ͱ੍‫͖Ͱޚ‬Δߦ෼ׂॲཧ
r ‫಺ޠݴ‬%4-Λ࢖༻ͯ͠΋ΤϥʔใࠂΛਝ଎͔ͭ໌շʹอͭͨΊͷɼଟஈ֊‫ͮ͘جʹࢉܭ‬ϚΫϩ‫ߏػ‬w ͋Γ͕͍ͨ͜ͱʹ༗ࢤͷํʑʹΑΓपลπʔϧ΍ύοέʔδ΋ਫ਼ྗతʹ։ൃ͞Ε͍ͯΔࢀߟจ‫ݙ‬• Rowan Davies. A temporal-logic approach to binding-time analysis. In Proc. of LICS’96, pp. 184–195, 1996.
• Sebastian Erdweg and Klaus Ostermann. Featherweight TeX and parser correctness. In SLE 2010. LNCS,
vol. 6563, pp. 397–416, 2011.
• Steve Ganz, Amr Sabry, and Walid Taha. Macros as multi-stage computations: type-safe, generative,
binding macros in MacroML. In Proc. of ICFP’01, pages 74–85, 2001.
• Benedict Gaster and Mark Jones. A polymorphic type system for extensible records and variants, 1996.
• Oleg Kiselyov. The design and implementation of BER MetaOCaml. In Functional and Logic Programming.
FLOPS 2014. Lecture Notes in Computer Science, vol 8475, 2014.
• Donald Knuth and Michael Plass. Breaking paragraphs into lines. So︎ftware–Practice and Experience, 11,pages 1119–1184, 1981.
• Franklin Liang. Word Hy-phen-a-tion by Com-put-er. Ph. D. thesis, Stanford University, 1983.
• Andres Löh and Ralf Hinze. Open data types and open functions. In Proc. of PPDP’06, pp. 133–144, 2006.
• Atsushi Ohori. A polymorphic record calculus and its compilation. In ACM Transactions on Programming
Languages and Systems, 17(6), pages 844–895, 1995.
• Didier Rémy. Type inference for records in a natural extension of ML. Theoretical Aspects of ObjectOriented Programming. Types, Semantics and Language Design, pages 67–95, 1993.
• Walid Taha and Tim Sheard. Multi-stage programming with explicit annotations. Theoretical Computer
Science, 248 (1-2), pp. 211–242, 2000.
• Unicode Consortium. Unicode Standard Annex #14: Unicode Line Breaki︎ng Algorithm (Unicode 10.0.0).
http://unicode.org/reports/tr14/, 2017.
• W3C ೔ຊ‫ޠ‬૊൛λεΫϑΥʔεʰW3C ٕज़ϊʔτ ೔ຊ‫ޠ‬૊൛ॲཧͷཁ݅ʱ౦‫ػిژ‬େֶग़൛‫ہ‬, 2012.

