Created
June 14, 2016 11:45
-
-
Save dohyunkim/57390c95052fdecbea8b1d32e0be6429 to your computer and use it in GitHub Desktop.
tex macro, gsub
This file contains hidden or 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
| \documentclass{article} | |
| \makeatletter | |
| \def\gsub#1#2#3{% | |
| \in@{#2}{#3}\ifin@ | |
| \errhelp{`#3' contains `#2', which is not allowed.}% | |
| \errmessage{Nested Substitution}% | |
| \fi | |
| \in@{#2}{#1}\ifin@ | |
| \def\gsubresult##1#2##2\par{##1#3##2}% | |
| \def\next{\expandafter\gsub\expandafter{\gsubresult#1\par}{#2}{#3}}% | |
| \else | |
| \def\next{\def\gsubresult{#1}}% | |
| \fi | |
| \next | |
| } | |
| \protected\def\segment#1{% | |
| \gsub{#1}{.}{dot}% | |
| \expandafter\gsub\expandafter{\gsubresult}{?}{QM}% | |
| % \expandafter\gsub\expandafter{\gsubresult}{O}{Oh!}% | |
| \expandafter\gsub\expandafter{\gsubresult}{!}{EXCL}% | |
| \gsubresult | |
| } | |
| \makeatother | |
| \usepackage{trace} | |
| \begin{document} | |
| |\segment{OO \TeX20.9 ?}| | |
| \end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment