Upgrade to Pro — share decks privately, control downloads, hide ads and more …

expl3 入門 / intro-expl3

Watson
October 15, 2017

expl3 入門 / intro-expl3

Watson

October 15, 2017
Tweet

More Decks by Watson

Other Decks in Programming

Transcript

  1. expl3 ೖ໳ 2017 ೥ͷ TEX ׆ಈ 1 ݄ pL A

    TEX2ε νʔτγʔτ࡞੒ DL CTAN ▶ ӳޠ൛ͷ L A TEX2ε Cheat Sheet ͕ݩωλ ▶ pL A TEX 2ε ʹରԠʢͨͩ͠ jclasses ͕લఏʣ 5 ݄ TUG@BachoTEX 2017ʢϙʔϥϯυʣʹࢀՃ ▶ ੿࡞ Gotoh ύοέʔδʹ͍ͭͯޱ಄ൃද DL CTAN ▶ ݩʑ͸େֶͷߨٛ՝୊ ▶ ੜ෺৘ใՊֶ෼໺Ͱ࠷΋جຊతͳΞϧΰϦζϜ ▶ W. J. Martin Prize ड৆ʹ࣍೥౓େձʹແྉট଴ 8 ݄ Whitesnowman ݴޠͷ։ൃ DL GitHub ▶ Whitespace ݴޠͷѥछʹ‚͚ͩͰϓϩάϥϛϯάՄೳʂ ▶ ΋ͪΖΜνϡʔϦϯά׬શ ▶ 100% TEX ݴޠ࣮૷ͷॲཧܥΛ։ൃ 2 / 27
  2. expl3 ೖ໳ TEX by Topic ྠಡձ ▶ ౦େ TEX Ѫ޷ձͰ݄

    2 ఔ౓։࠵ ▶ طʹ 2/3 Ҏ্ಡΈऴ͍͑ͯΔ ▶ ͱ͖Ͳ͖ώυ͍ϚΫϩΛಡΉ͜ͱ΋ʜʜ 1 \let\ex=\expandafter 2 \def\ifbefore 3 #1#2{\ifallchars#1$\are#2$\before} 4 \def\ifallchars#1#2\are#3#4\before 5 {\if#1$\say{true\ex}\else 6 \if#3$\say{false\ex\ex\ex}\else 7 \ifnum ‘#1>‘#3 \say{false% 8 \ex\ex\ex\ex\ex\ex\ex}\else 9 \ifnum ‘#1<‘#3 \say{true% 10 \ex\ex\ex\ex\ex\ex\ex 11 \ex\ex\ex\ex\ex\ex\ex\ex}\else 12 \ifrest#2\before#4\fi\fi\fi\fi} 13 \def\ifrest#1\before#2\fi\fi\fi\fi 14 {\fi\fi\fi\fi 15 \ifallchars#1\are#2\before} 16 \def\say#1{\csname if#1\endcsname} 4 / 27
  3. expl3 ೖ໳ expl3 ͱ͸ expl3 = L A TEX3 Programming

    Language† ▶ ಡΈํ͸ʮΤΫεϖϧɾεϦʔʯ ʢx-pel-3ʣ ▶ L A TEX3 νʔϜ͕։ൃ͍ͯ͠Δϓϩάϥϛϯάݴޠ ▶ TEX ݴޠͰ࣮૷͞Ε͓ͯΓɼTEX ্Ͱಈ࡞ † ݩʑ͸ “experimental” ͷҙ͕ͩͬͨɼࠓ͸ҧ͏ʢΑͬͯӬٱʹ expl3ʣ 7 / 27
  4. expl3 ೖ໳ L A TEX3 ϓϩδΣΫτͱ expl3 L A TEX3

    ͷ 3 ֊૚ߏ଄ʢܭըʣ 1. ϚʔΫΞοϓݴޠ ▶ Ϣʔβ͕จॻ࡞੒ʹ࢖༻ ▶ L A TEX2ε ͱຊ࣭తʹಉ֓͡೦ 2. ϨΠΞ΢τઃܭݴޠ ▶ Ϋϥεͷઃܭʹ࢖༻ ▶ L A TEX2ε Ͱ͸ 3. ͱಉԽ 3. ϓϩάϥϛϯάݴޠ ▶ L A TEX3 ͷ্૚΍ύοέʔδ ͷ࣮૷ʹ࢖༻ ▶ ࣮૷ࡁΈʹ expl3 ˠ࢓༷΋҆ఆ͖ͯͨ͠ ϓϩάϥϛϯά expl3 ϨΠΞ΢τઃܭ ʢ໊শະఆʣ ϚʔΫΞοϓ L A TEX3 ˑ expl3 ͸୯ಠͰ TEX Λίϯτϩʔϧ͢Δ͢΂ͯͷػೳΛఏڙ TEX on L A TEX ͸΋͏΍ΊΑ͏ʂ 8 / 27
  5. expl3 ೖ໳ expl3 ͷಛ௃ ओͳಛ௃ The expl3 package and L

    A TEX3 programming ʹΑΔͱʜʜ ▶ ؔ਺Λػೳ͝ͱʹ෼ྨ͠ɼϞδϡʔϧԽ ▶ ্هͷ෼ྨʹجͮ͘ɼؔ਺΍ม਺ͷମܥతͳ໋໊نଇ ▶ ʢؔ਺Ҿ਺ͷʣల։੍ޚΛγϯϓϧʹهड़͢Δػߏ ▶ ͢΂ͯͷػೳ͕ɼ໌֬ʹυΩϡϝϯτԽ͞Ε͍ͯΔ ͜ΕΒͷಛ௃͸ίʔυͷՄಡੑɾ҆શੑΛ޲্ͤ͞Δ 9 / 27
  6. expl3 ೖ໳ expl3 ͷΩϗϯ γϯλοΫε TEX on L A TEX

    ͱҎԼͷΑ͏ͳ఺ͰҟͳΔɿ ▶ ӳจࣈʹՃ͑ͯ _ ͱ : Λʮจࣈʯͱͯ͠࢖༻ ʲ஫ҙʳexpl3 Ͱ͸ @ ͸ʮจࣈʯͱͯ͠ѻΘͳ͍ʂ ▶ ൒֯εϖʔε͸͢΂ͯແࢹ͞ΕΔʂ ˠۭന͕ඞཁͳ৔߹͸୅ΘΓʹ ~ Λ༻͍Δ / \ _ - _________ ߦ຤ % Α ͞Β͹ʂ --------- _ - \ / \ \_[_]_ (") >-( : )-< (__:__) ؔ਺ͱม਺ TEX on L A TEX ͷʮϚΫϩʯ͸ɼ໌֬ͳ 2 छྨʹ෼ྨ͞ΕΔɿ ؔ਺ Ҿ਺ΛऔΔ͜ͱ͕Ͱ͖ɼల։·ͨ͸࣮ߦ͞ΕΔ ม਺ ஋Λ୅ೖͰ͖ɼؔ਺ͷҾ਺ͱͯ͠ར༻͞ΕΔ ؔ਺΋ม਺΋ɼػೳผͷʮϞδϡʔϧʯʹଐ͢Δ 10 / 27
  7. expl3 ೖ໳ ม਺ͷΧλνᶃ \⟨scope⟩_⟨module⟩_⟨description⟩_⟨type⟩ ⟨scope⟩ ͦͷม਺ʹΞΫηεͰ͖ΔൣғΛࣔ͢ ▶ cɿఆ਺ʹάϩʔόϧͰ͋Γɼ஋Λมߋ͢΂͖Ͱͳ͍ ▶ gɿάϩʔόϧม਺

    ▶ lɿϩʔΧϧม਺ ⟨module⟩ ؔ࿈͢Δؔ਺ɾม਺ΛूΊͨ΋ͷʢ໊લۭؒʣ ▶ Ϟδϡʔϧ໊͸ӳจࣈͷΈͰߏ੒ ▶ ύοέʔδ࡞੒࣌ʹඞཁͳΒ৽ن࡞੒Ͱ͖Δ ʲ஫ҙʳl3prefixes.csv ʹطଘͷϞδϡʔϧ໊͕ϦετΞοϓ ⟨description⟩ ม਺ͷ໊শɾ໾ׂͳͲ ▶ ӳจࣈͱ _ Ͱߏ੒ 11 / 27
  8. expl3 ೖ໳ ม਺ͷΧλνᶄ ⟨type⟩ σʔλͷछྨΛද͢ ▶ expl3 ඪ४ͷʮܕʯ͸ 15 छྨ

    bool ਅِ஋ int ੔਺ fp ුಈখ਺఺਺ box ϘοΫε str จࣈྻ seq γʔΫΤϯε ior / iow ೖग़ྗ dim ݫ֨ͳੇ๏ tl τʔΫϯϦετ clist ΧϯϚ۠੾ΓϦετ prop ϓϩύςΟϦετ coffin ߴڃͳϘοΫε muskip ਺ࣜ༻ͷੇ๏ skip ৳ॖՄೳͳੇ๏ ม਺ͷྫ \l_scfoo_number_of_buttons_int 12 / 27
  9. expl3 ೖ໳ ؔ਺ͷΧλν \⟨module⟩_⟨description⟩:⟨arg-spec⟩ ⟨arg-spec⟩ ؔ਺͕ͱΔҾ਺ͷܗΛࢦఆ͢Δ ▶ Ҿ਺ࢦఆࢠΛҾ਺ͷ਺͚ͩฒ΂Δ ▶ nɿී௨ͷҾ਺

    ▶ Nɿ୯ҰτʔΫϯʢయܕతʹ͸੍ޚ௲ʣ ʲ஫ҙʳϒϨʔεͰғͬͯ͸͍͚ͳ͍ ▶ pɿύϥϝλςΩετ ▶ T, Fɿಛघͳ nʢਅِʹԠͯ͡࢖༻͞ΕΔʣ ▶ wɿྫ֎ ྫ \exp_after:wN ▶ Ҿ਺͕ͳ͍৔߹͸ۭจࣈྻͰΑ͍ ྫ \scan_stop: ▶ ల։੍ޚΛߦ͏ಛघͳࢦఆࢠ΋ଘࡏʢޙड़ʣ ؔ਺ͷྫ ▶ \cs_new:Npn \foo_hello:n #1 { Hello~#1! } ▶ \cs_if_exist:NTF \foo_bar: { true } { false } 13 / 27
  10. expl3 ೖ໳ ؆୯ͳίʔυྫ ྫͱͯ͠ int ܕͷม਺΁ͷجຊૢ࡞Λߟ͑Δɿ 1 % ม ਺

    એ ݴ 2 \int_new:N \g_scfoo_number_int 3 4 % ά ϩ ʔ ό ϧ ʹ ஋ Λ ઃ ఆ 5 \int_gset:Nn \g_scfoo_number_int { 2 * 0 + 1 * 7 } 6 7 % ϧ ʔ ϓ ʢ4 Ҏ ্ ͷ ͱ ͖ ʣ 8 \int_do_while:nn { \g_scfoo_number_int >= 1 * 0 + 1 * 4 } 9 { 10 % σ Ϋ Ϧ ϝ ϯ τ 11 \int_gdecr:N \g_scfoo_number_int 12 % ‚ 13 \scsnowman 14 } 7 6 5 4 \g_scfoo_number_int 14 / 27
  11. expl3 ೖ໳ ಛघͳҾ਺ࢦఆࢠ ▶ cɿ੍ޚ௲Խ \foo_bar:c { baz } \expandafter\foo@bar

    \csname baz\endcsname ▶ xɿ׬શల։ \foo_bar:x { \baz } \edef\tmp{\noexpand \foo@bar{\baz}}\tmp ▶ oɿ1 ճల։ \foo_bar:o { \baz } \expandafter\foo@bar \expandafter{\baz} ▶ fɿઌ಄׬શల։ \foo_bar:f { \baz } \expandafter\foo@bar \expandafter{% \romannumeral -‘0\baz} ▶ Vɿม਺ͷ஋ΛऔΓग़ͯ͠࢖༻ ▶ vɿ੍ޚ௲Խͷ্ɼม਺ͷ஋ΛऔΓग़ͯ͠࢖༻ 15 / 27
  12. expl3 ೖ໳ ؔ਺ఆٛͱมछͷੜ੒ ▶ ؔ਺ఆٛʹ͸ \cs_new:Npn ؔ਺Λ༻͍Δ ▶ σϑΥϧτͰ \long

    ༗ޮ ▶ ఆٛࡁΈͷ৔߹͸Τϥʔ ▶ ؔ਺ఆٛͷؔ਺ʹ͸มछ͕ଟ਺͋Δ ▶ \cs_new:cpn - ಈతͳؔ਺ఆٛ ▶ \cs_new_nopar:Npn - \long ແޮ ▶ \cs_set:Npn - ఆٛΛ্ॻ͖ʢϩʔΧϧʣ ▶ ؔ਺ͷίϐʔʹ͸ \cs_new_eq:NN Λ༻͍Δ ▶ \cs_new_eq:cc ͳͲ͸େมศར ʲ஫ҙʳ͜ΕΛ TEX on L ATEX Ͱॻ͘ͱ͔ͳΓ௕͘ͳΔ ▶ ⟨arg-spec⟩ ͚͕ͩҟͳΔมछΛଟ਺ఆٛ͢Δͷ͸େมͰ͸ʁ ˠ\cs_generate_variant:Nn Ͱ؆୯ʹ࡞੒Մೳ ྫ \cs_generate_variant:Nn \demo_cmd:Nnn { cnx } 16 / 27
  13. expl3 ೖ໳ ศརϞδϡʔϧᶃ l3seq ▶ ͋ΒΏΔ ⟨balanced text⟩ Λ֨ೲͰ͖Δσʔλߏ଄ ▶

    ߴ଎ͳ mapping ▶ stack ͱͯ͠࢖͑Δ ▶ l3sort ͷػೳΛ༻͍ͯιʔτΛߦ͏͜ͱ΋Մೳ 1 \seq_set_split:Nnn \l_tmpa_seq { | } { 2 | 0 | -1 | 7 } 2 3 \seq_sort:Nn \l_tmpa_seq 4 {% ൺ ֱ ϩ δ ο Ϋ 5 \int_compare:nNnTF { #1 } > { #2 } 6 { \sort_return_swapped: } 7 { \sort_return_same: } 8 } 9 10 \seq_log:N \l_tmpa_seq 11 %The sequence \l_tmpa_seq contains the items: 12 %> {-1} 13 %> {0} 14 %> {2} 15 %> {7}. 17 / 27
  14. expl3 ೖ໳ ศརϞδϡʔϧᶄ l3keys ▶ key–val ϦετΛѻ͏Ϟδϡʔϧ ▶ બ୒Ωʔ΍ਅِΩʔ΋αϙʔτ ▶

    Ωʔͷఆٛ΋ key–val ܗࣜͰߦ͏ ▶ l3keys2e Ͱ L A TEX2ε ΫϥεΦϓγϣϯ౳΁΋֦ு 1 \keys_define:nn { hello } 2 { 3 to .code:n = Hello~#1\l_hello_end_tl, 4 end .choices:nn = { exclamation, snowman } 5 { 6 \int_case:nn { \l_keys_choice_int } 7 { 8 { 1 } { \tl_set:Nn \l_hello_end_tl { ! } } 9 { 2 } { \tl_set:Nn \l_hello_end_tl { ‚ } } 10 } 11 } 12 } 13 14 \keys_set:nn { hello } { end = snowman, to = World } Hello World ‚ 18 / 27
  15. expl3 ೖ໳ expl3 ίʔσΟϯά࡞๏ 1. TEX ϓϦϛςΟϒΛ࢖Θͳ͍ ▶ expl3 ࣜͷ໋ྩʹͳ͍ͬͯΕ͹࢖༻

    OK ྫ \exp_after:wN ▶ ͨͩ͠ l3names ͷ \tex_⟨primitive⟩:D ͸࢖༻ෆՄ ʲ஫ҙʳҾ਺ࢦఆͷ D ͸ “Do NOT use” ͷҙຯ 2. ֤Ϟδϡʔϧͷ಺෦ม਺΍಺෦ؔ਺΋࢖Θͳ͍ ▶ ϓϥΠϕʔτཁૉʹ͸ ⟨module⟩ ͷલʹ __ Λલஔ ྫ ม਺ \l__foo_bar_tlɼؔ਺ \__foo_bar:Nn 3. ଟগ৑௕Ͱ͋ͬͨͱͯ͠΋ɼՄಡੑΛॏࢹ ▶ ม਺໊΍ؔ਺໊͸े෼આ໌తʹ ▶ εϖʔγϯά΍վߦ͸ੵۃతʹ 4. ಺෦ؔ਺͸ͳΔ΂͘ \long Ͱ࣮૷ ʲ஫ҙʳཧ༝ͳ͘ \cs_new_nopar:Npn Λ࢖Θͳ͍ 5. ม਺͸ඞͣએݴ͔ͯ͠Β࢖༻ 19 / 27
  16. expl3 ೖ໳ expl3 ͷಈ࡞؀ڥ TEX90 ͷશϓϦϛςΟϒͱ ε-֦ுͷ΄ͱΜͲͷϓϦϛςΟϒɼ ͓Αͼ pdfTEX ͷ

    \pdfstrcmp ૬౰ͷػೳͷ͋ΔॲཧܥΛαϙʔτ αϙʔτॲཧܥ ▶ v1.40 Ҏ߱ͷ pdfTEX ▶ v0.9994 Ҏ߱ͷ X E TEX ▶ v0.70 Ҏ߱ͷ LuaTEX ▶ mid-2012 Ҏ߱ͷ ε-(u)pTEX expl3 Ͱ࣮૷͢Ε͹ɼ΋Εͳ͘ΫϩεɾΤϯδϯͳίʔυʹʂ 20 / 27
  17. expl3 ೖ໳ expl3 on L A TEX2ε (and others) L

    A TEX2ε ͷ৔߹ 1. expl3 ύοέʔδʢʹ L A TEX2ε ύοέʔδʣΛϩʔυ 2. expl3 ݴޠΛهड़͢ΔͨΊͷ؀ڥΛ։࢝ ▶ \ExplSyntaxOn Ͱ։࢝ʢ\ExplSyntaxOff Ͱऴྃʣ ʲ஫ҙʳ\ProvideExplPackage Ͱύοέʔδએݴͨ͠৔߹͸ෆཁ 3. Happy expl3ing!! ▶ ʢL A TEX2εʣϢʔβ༻ͷ໋ྩ͸ xparse Λ༻͍ͯఆٛ 1 \documentclass{article} 2 \usepackage{xparse}% ಺ ෦ Ͱ expl3 ύ ο έ ʔ δ Λ ϩ ʔ υ 3 \ExplSyntaxOn 4 % ‚ ‚ ‚ expl3 ͷ ε ς Ω ͳ ί ʔ υ ‚ ‚ ‚ 5 \ExplSyntaxOff L A TEX2ε Ҏ֎ͷ৔߹ expl3 ύοέʔδͷ୅ΘΓʹɼplain TEX ΠϯλʔϑΣʔεΛ࢖༻ɿ \input expl3-generic % 21 / 27
  18. expl3 ೖ໳ ։ൃࢧԉπʔϧͳͲ TEXworks Joseph ࢯʹΑΔ؆୯ͳγϯλοΫεɾϋΠϥΠτ͋Γ WinEdit ඪ४Ͱαϙʔτ Emacs AUCTEX

    ͕ expl3 ʹରԠ͍ͯ͠Δ Vim ੿࡞ vim-expl3 ͕࠷௿ݶͷػೳΛఏڙ DL GitHub ▶ γϯλοΫεɾϋΠϥΠτ ▶ Ϛονϯάɾϧʔϧ ▶ TODO: ▶ expl3 ίʔυͷࣗಈ൑ผ ▶ ิ׬ϧʔϧ ▶ ΩʔϚοϓʢඞཁʁʣ 22 / 27
  19. expl3 ೖ໳ expl3 ͷ՝୊ 1. ίʔυ͕৑௕ʹͳΓ΍͍͢ ▶ Մಡੑ΍อकੑͱτϨʔυɾΦϑͷؔ܎ʹඞཁѱ ▶ ௕͍ؔ਺໊ɾม਺໊ͳͲ͸։ൃ؀ڥͰΧόʔՄೳ

    2. ݴޠػೳͷෆ଍ ▶ ඪ४Ϟδϡʔϧ͚ͩͰ͸ෆे෼ ྫ ଟ࣍ݩͷσʔλߏ଄ ▶ ղܾ͠ͳ͍ͱʮंྠͷ࠶ൃ໌ʯ͕ଓ͘͜ͱʹʜʜ ▶ ࠓޙͷ֦ு΍Ϣʔβ਺૿ՃͰࣗવͱղܾ͢Δʢ͸ͣʣ 3. TEX ϨϕϧͷΤϥʔ͕ൃੜ͠ಘΔ ▶ ͜ͷ఺͸ L A TEX2εʢTEX on L A TEXʣͱมΘΒͳ͍ ▶ ࠜຊղܾʹ͸ TEX Good-bye ͔͠ͳ͍ 23 / 27
  20. expl3 ೖ໳ expl3 Ͱ࣮૷͞Εͨύοέʔδ 2017 ೥ 10 ݄ 14 ೔ݱࡏͷ

    TEX Live Ͱ expl3 ࣮૷ͷ L A TEX2ε ύοέʔδ͸ 171ݸ ʲ஫ҙʳgrep -rn $TEXMF -e ’ackage\s*{expl3’ ʹΑΔࡶͳܭଌ݁Ռ ྫ ▶ acro ύοέʔδɿ୹ॖޠͷ؅ཧɾग़ྗ ▶ siunitx ύοέʔδɿSI ୯Ґͷग़ྗ 24 / 27
  21. expl3 ೖ໳ L A TEX3 νʔϜͷศརͳ੒Ռ෺ xparse ύοέʔδ ▶ L

    A TEX 2ε ͷϢʔβ༻໋ྩΛఆٛ͢ΔͨΊͷύοέʔδ ▶ Z.R. ͞ΜʹΑΔৄࡉͳղઆʢ೔ຊޠʣ͋Γ https://qiita.com/zr_tex8r/items/50168ad7087516c3e139 l3build ▶ Lua ੡ L A TEX ύοέʔδ༻Ϗϧυπʔϧ ▶ ύοέʔδ͝ͱʹ build.lua Λ༻ҙͯ͠࢖༻ ▶ ศརͳαϒίϚϯυ͕ଟ਺ ▶ checkɿςετͷ࣮ߦ ▶ ctanɿCTAN ༻ΞʔΧΠϒΛ࡞੒ ▶ installɿΠϯετʔϧʢTDS ४ڌʣ 25 / 27
  22. expl3 ೖ໳ ϝϦοτͱσϝϦοτʢ·ͱΊʣ ϝϦοτ ▶ TEX ্ͷɹ ɾ Ϛ ɾ

    τ ɾ Ϟ ɾ ͳ ɹϓϩάϥϛϯά؀ڥͰ͋Δ ▶ ϞδϡʔϧԽʢ໊લۭؒͷ෼཭ʣͱମܥతͳ໋໊نଇ ▶ ల։੍ޚΛ༰қʹ͢Δؔ਺ͷػߏ ▶ ͢΂ͯͷػೳ͕υΩϡϝϯτԽ͞Ε͍ͯΔ ▶ ศརͳඪ४ϞδϡʔϧΛར༻Ͱ͖Δ ྫ l3regexp ▶ Կ΋ߟ͑ͳͯ͘΋ϚϧνɾΤϯδϯʹͳΔ σϝϦοτ ▶ ίʔυ͕৑௕ʹͳΓ͕ͪ ▶ ʢTEX ऀʹͱͬͯʣֶशίετ͕θϩͰ͸ͳ͍ 26 / 27
  23. expl3 ೖ໳ ࢀߟจݙͱँࣙ ࢀߟจݙ ͢΂ͯ L A TEX3 νʔϜʹΑΔެࣜυΩϡϝϯτɿ [1]

    The expl3 package and L A TEX3 programming (expl3.pdf) [2] The l3build Package (l3build.pdf) [3] The L A TEX3 Interfaces (interface3.pdf) [4] The L A TEX3 kernel: style guide for code authors (l3styleguide.pdf) Special Thanks ▶ Frank Mittelbach ▶ Joseph Wright Happy expl3ing!! 27 / 27