Created
June 4, 2022 13:58
-
-
Save h20y6m/3072888edd2886aef20e946949435018 to your computer and use it in GitHub Desktop.
LaTeX: 全角にする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% | |
%% This is file 'zenkaku.sty'. | |
%% | |
%% Copyright (c) 2022 Yukimasa Morimi (h20y6m) | |
%% GitHub: https://github.com/h20y6m | |
%% | |
%% This package is distributed under the MIT License. | |
%% | |
\NeedsTeXFormat{LaTeX2e} | |
\RequirePackage{expl3} | |
\ProvidesExplPackage{zenkaku}{2022-06-04}{0.1.0}{zenkaku conversion} | |
%% variables and helpers | |
\scan_new:N \s__zenkaku_stop | |
\quark_new:N \q__zenkaku_recursion_tail | |
\quark_new:N \q__zenkaku_recursion_stop | |
\cs_new:Npn \__zenkaku_use_i_delimit_by_q_recursion_stop:nw | |
#1 #2 \q__zenkaku_recursion_stop {#1} | |
\cs_new:Npn \__zenkaku_if_recursion_tail_stop_do:Nn #1 | |
{ | |
\if_meaning:w \q__zenkaku_recursion_tail #1 | |
\exp_after:wN \__zenkaku_use_i_delimit_by_q_recursion_stop:nw | |
\else: | |
\exp_after:wN \use_none:n | |
\fi: | |
} | |
\tl_new:N \l__zenkaku_convert_numeral_tl | |
\tl_new:N \l__zenkaku_convert_alphabet_tl | |
\tl_new:N \l__zenkaku_convert_alphanumeral_tl | |
\tl_new:N \l__zenkaku_convert_symbol_tl | |
\tl_new:N \l__zenkaku_convert_numeral_symbol_tl | |
\tl_new:N \l__zenkaku_convert_alphabet_symbol_tl | |
\tl_new:N \l__zenkaku_convert_alphanumeral_symbol_tl | |
\tl_set:Nn \l__zenkaku_convert_numeral_tl | |
{ | |
0 { 0 } 1 { 1 } 2 { 2 } 3 { 3 } 4 { 4 } 5 { 5 } 6 { 6 } 7 { 7 } 8 { 8 } 9 { 9 } | |
} | |
\tl_set:Nn \l__zenkaku_convert_alphabet_tl | |
{ | |
A { A } B { B } C { C } D { D } E { E } F { F } G { G } H { H } I { I } J { J } K { K } L { L } M { M } | |
N { N } O { O } P { P } Q { Q } R { R } S { S } T { T } U { U } V { V } W { W } X { X } Y { Y } Z { Z } | |
a { a } b { b } c { c } d { d } e { e } f { f } g { g } h { h } i { i } j { j } k { k } l { l } m { m } | |
n { n } o { o } p { p } q { q } r { r } s { s } t { t } u { u } v { v } w { w } x { x } y { y } z { z } | |
} | |
\tl_set:Nn \l__zenkaku_convert_symbol_tl | |
{ | |
! { ! } " { ” } ' { ’ } ( { ( } ) { ) } * { * } + { + } , { , } - { - } . { . } | |
/ { / } ; { ; } < { < } = { = } > { > } ? { ? } [ { [ } ] { ] } ` { ‘ } | { | } | |
\# { # } \$ { $ } \% { % } \& { & } \_ { _ } \{ { { } \} { } } | |
\textbackslash { ¥ } | |
\textasciicircum { ^ } | |
\textasciitilde {  ̄ } | |
} | |
\exp_args:NNf \tl_put_right:Nn \l__zenkaku_convert_symbol_tl { \char_generate:nn { `: } { 12 } { : } } | |
\exp_args:NNf \tl_put_right:Nn \l__zenkaku_convert_symbol_tl { \char_generate:nn { `@ } { 12 } { @ } } | |
\tl_put_right:NV \l__zenkaku_convert_alphanumeral_tl \l__zenkaku_convert_numeral_tl | |
\tl_put_right:NV \l__zenkaku_convert_alphanumeral_tl \l__zenkaku_convert_alphabet_tl | |
\tl_put_right:NV \l__zenkaku_convert_numeral_symbol_tl \l__zenkaku_convert_numeral_tl | |
\tl_put_right:NV \l__zenkaku_convert_numeral_symbol_tl \l__zenkaku_convert_symbol_tl | |
\tl_put_right:NV \l__zenkaku_convert_alphabet_symbol_tl \l__zenkaku_convert_alphabet_tl | |
\tl_put_right:NV \l__zenkaku_convert_alphabet_symbol_tl \l__zenkaku_convert_symbol_tl | |
\tl_put_right:NV \l__zenkaku_convert_alphanumeral_symbol_tl \l__zenkaku_convert_alphanumeral_tl | |
\tl_put_right:NV \l__zenkaku_convert_alphanumeral_symbol_tl \l__zenkaku_convert_symbol_tl | |
\tl_new:N \l__zenkaku_convert_space_zenkaku_tl | |
\tl_new:N \l__zenkaku_convert_space_hankaku_tl | |
\tl_set:Nn \l__zenkaku_convert_space_zenkaku_tl { } | |
\tl_set:Nn \l__zenkaku_convert_space_hankaku_tl { ~ } | |
%% functions | |
\cs_new:Npn \zenkaku_numeral:n #1 | |
{ \__zenkaku_convert:nnn { numeral } { hankaku } {#1} } | |
\cs_new:Npn \zenkaku_alphabet:n #1 | |
{ \__zenkaku_convert:nnn { alphabet } { hankaku } {#1} } | |
\cs_new:Npn \zenkaku_alphanumeral:n #1 | |
{ \__zenkaku_convert:nnn { alphanumeral } { hankaku } {#1} } | |
\cs_new:Npn \zenkaku_numeral_space:n #1 | |
{ \__zenkaku_convert:nnn { numeral } { zenkaku } {#1} } | |
\cs_new:Npn \zenkaku_alphabet_space:n #1 | |
{ \__zenkaku_convert:nnn { alphabet } { zenkaku } {#1} } | |
\cs_new:Npn \zenkaku_alphanumeral_space:n #1 | |
{ \__zenkaku_convert:nnn { alphanumeral } { zenkaku } {#1} } | |
\cs_new:Npn \zenkaku_symbol:n #1 | |
{ \__zenkaku_convert:nnn { symbol } { hankaku } {#1} } | |
\cs_new:Npn \zenkaku_symbol_space:n #1 | |
{ \__zenkaku_convert:nnn { symbol } { zenkaku } {#1} } | |
\cs_new:Npn \zenkaku_numeral_symbol:n #1 | |
{ \__zenkaku_convert:nnn { numeral_symbol } { hankaku } {#1} } | |
\cs_new:Npn \zenkaku_alphabet_symbol:n #1 | |
{ \__zenkaku_convert:nnn { alphabet_symbol } { hankaku } {#1} } | |
\cs_new:Npn \zenkaku_alphanumeral_symbol:n #1 | |
{ \__zenkaku_convert:nnn { alphanumeral_symbol } { hankaku } {#1} } | |
\cs_new:Npn \zenkaku_numeral_symbol_space:n #1 | |
{ \__zenkaku_convert:nnn { numeral_symbol } { zenkaku } {#1} } | |
\cs_new:Npn \zenkaku_alphabet_symbol_space:n #1 | |
{ \__zenkaku_convert:nnn { alphabet_symbol } { zenkaku } {#1} } | |
\cs_new:Npn \zenkaku_alphanumeral_symbol_space:n #1 | |
{ \__zenkaku_convert:nnn { alphanumeral_symbol } { zenkaku } {#1} } | |
\cs_new:Npn \__zenkaku_convert:nnn #1#2#3 | |
{ \exp:w \__zenkaku_convert_aux:nnn {#1} {#2} {#3} } | |
\cs_new:Npn \__zenkaku_convert_aux:nnn #1#2#3 | |
{ | |
\__zenkaku_convert_loop:nnnw {#1} {#2} {} #3 \q__zenkaku_recursion_tail \q__zenkaku_recursion_stop | |
} | |
\cs_new:Npn \__zenkaku_convert_loop:nnnw #1#2#3#4 \q__zenkaku_recursion_stop | |
{ | |
\tl_if_head_is_N_type:nTF {#4} | |
{ \__zenkaku_convert_N_type:nnnN } | |
{ | |
\tl_if_head_is_group:nTF {#4} | |
{ \__zenkaku_convert_group:nnnn } | |
{ \__zenkaku_convert_space:nnnw } | |
} | |
{#1} {#2} {#3} #4 \q__zenkaku_recursion_stop | |
} | |
\cs_new:Npn \__zenkaku_convert_next_loop:nnnn #1#2#3#4 | |
{ \__zenkaku_convert_loop:nnnw {#2} {#3} { #4 #1 } } | |
\cs_new:Npn \__zenkaku_convert_N_type:nnnN #1#2#3#4 | |
{ | |
\__zenkaku_if_recursion_tail_stop_do:Nn #4 | |
{ \exp_end: #3 } | |
\exp_args:No \__zenkaku_convert_next_loop:nnnn | |
{ \exp:w \__zenkaku_convert_N_type_aux:nN {#1} #4 } | |
{#1} {#2} {#3} | |
} | |
\cs_new:Npn \__zenkaku_convert_N_type_aux:nN #1#2 | |
{ | |
\exp_args:NNv \__zenkaku_convert_N_type_aux:Nn #2 { l__zenkaku_convert_ #1 _tl } | |
} | |
\cs_new:Npn \__zenkaku_convert_N_type_aux:Nn #1#2 | |
{ | |
\__zenkaku_convert_N_type_aux:NNnw #1 #2 \s__zenkaku_stop | |
} | |
\cs_new:Npn \__zenkaku_convert_N_type_aux:NNnw #1#2#3#4 \s__zenkaku_stop | |
{ | |
\token_if_eq_meaning:NNTF #1#2 | |
{ \exp_end: #3 } | |
{ | |
\tl_if_empty:nTF {#4} | |
{ \exp_end: #1 } | |
{ | |
\__zenkaku_convert_N_type_aux:NNnw #1 #4 \s__zenkaku_stop | |
} | |
} | |
} | |
\cs_new:Npn \__zenkaku_convert_group:nnnn #1#2#3#4 | |
{ | |
\exp_args:No \__zenkaku_convert_next_loop:nnnn | |
{ \exp_after:wN { \exp:w \__zenkaku_convert_aux:nnn {#1} {#2} {#4} } } | |
{#1} {#2} {#3} | |
} | |
\use:x { \cs_new:Npn \exp_not:N \__zenkaku_convert_space:nnnw ##1##2##3 \c_space_tl } | |
{ | |
\exp_args:Nv \__zenkaku_convert_next_loop:nnnn | |
{ l__zenkaku_convert_space_ #2 _tl } | |
{#1} {#2} {#3} | |
} | |
%% LaTeX2e interfaces | |
\cs_new_eq:NN \MakeZenkakuNumeral \zenkaku_numeral:n | |
\cs_new_eq:NN \MakeZenkakuAlphabet \zenkaku_alphabet:n | |
\cs_new_eq:NN \MakeZenkakuAlphanumeral \zenkaku_alphanumeral:n | |
\cs_new_eq:NN \MakeZenkakuNumeralSpace \zenkaku_numeral_space:n | |
\cs_new_eq:NN \MakeZenkakuAlphabetSpace \zenkaku_alphabet_space:n | |
\cs_new_eq:NN \MakeZenkakuAlphanumeralSpace \zenkaku_alphanumeral_space:n | |
\cs_new_eq:NN \MakeZenkakuSymbol \zenkaku_symbol:n | |
\cs_new_eq:NN \MakeZenkakuSymbolSpace \zenkaku_symbol_space:n | |
\cs_new_eq:NN \MakeZenkakuNumeralSymbol \zenkaku_numeral_symbol:n | |
\cs_new_eq:NN \MakeZenkakuAlphabetSymbol \zenkaku_alphabet_symbol:n | |
\cs_new_eq:NN \MakeZenkakuAlphanumeralSymbol \zenkaku_alphanumeral_symbol:n | |
\cs_new_eq:NN \MakeZenkakuNumeralSymbolSpace \zenkaku_numeral_symbol_space:n | |
\cs_new_eq:NN \MakeZenkakuAlphabetSymbolSpace \zenkaku_alphabet_symbol_space:n | |
\cs_new_eq:NN \MakeZenkakuAlphanumeralSymbolSpace \zenkaku_alphanumeral_symbol_space:n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example