Last active
March 30, 2022 12:01
-
-
Save k16shikano/1ae1e079fb2949f9c361c9f5b3abb4d7 to your computer and use it in GitHub Desktop.
platexで文字の置換をexpl3でやる
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
% platexで文字の置換 https://ja.stackoverflow.com/questions/53898/platex%E3%81%A7%E6%96%87%E5%AD%97%E3%81%AE%E7%BD%AE%E6%8F%9B をexpl3でやってみる。 | |
% おそらくenvironの制限で、この書き方だとinstead環境のネストには対応していない。 | |
% xparseの新しい引数指定オプションbを使うと環境の本体がとれて、これだとうまくいくかもしれない。 | |
\documentclass[uplatex]{jsarticle} | |
\usepackage{xparse} | |
\usepackage{environ} | |
\ExplSyntaxOn | |
\tl_new:N \g__body_tl | |
\tl_new:N \g__outer_body_tl | |
\cs_new:Nn \set_the_body:n { | |
\tl_if_empty:NTF \g__body_tl | |
{ } | |
{ \tl_set_eq:NN \g__outer_body_tl \g__body_tl } | |
\tl_set:Nx \g__body_tl { #1 } | |
} | |
\makeatletter | |
\NewDocumentEnvironment{instead}{m m}{% | |
\Collect@Body \set_the_body:n | |
}{ | |
\tl_replace_all:Nnn \g__body_tl { #1 } { #2 } | |
\tl_use:N \g__body_tl \par | |
} | |
\makeatother | |
\ExplSyntaxOff | |
\begin{document} | |
\def\い{い} | |
\begin{instead}{い}{あ} | |
い←「あ」と出力させた\い い | |
\end{instead} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment