Created
May 17, 2013 21:26
-
-
Save kenoss/5602081 to your computer and use it in GitHub Desktop.
TeXで括弧の対応をとる, 上手くいく例.
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
% -*- coding: utf-8 -*- | |
\documentclass[10pt,draft]{jsarticle} | |
%\usepackage{amsmath,amssymb} | |
%\usepackage{kmathmacro} | |
%\usepackage{etex} | |
%\usepackage{etoolbox} | |
\makeatletter | |
\def\:{\global\let\mwm@sptoken= }\: % | |
\let\mwm@bgtoken={ | |
\def\adicsp{% | |
\getcorrparen\adicsp@recieve | |
} | |
\def\adicsp@recieve{% | |
\gcp@@result^{\mathrm{ad}}% | |
} | |
\def\paren{% | |
\getcorrparen\paren@recieve | |
} | |
\def\paren@recieve{% | |
\expandafter\paren@aux\gcp@@result\@nil | |
} | |
\def\paren@aux(#1)\@nil{% | |
\left(#1\right) | |
} | |
\def\getcorrparen#1{% | |
\gcp@begin#1% | |
} | |
\newcount\gcp@@count | |
\def\gcp@const@@open{(} | |
\def\gcp@const@@close{)} | |
\def\gcp@begin#1{% | |
\begingroup | |
\let\gcp@return#1 | |
\gcp@@count = 0 | |
\def\gcp@@res{}% | |
\gcp@loop | |
} | |
\def\gcp@loop{% | |
\futurelet\gcp@token\gcp@loop@a | |
} | |
\def\gcp@loop@a{% | |
\ifx\gcp@token\mwm@sptoken | |
\toks0\expandafter{\gcp@@res}% | |
\toks1{ }% | |
\edef\gcp@@res{\the\toks0 \the\toks1}% | |
\fi | |
\gcp@loop@b | |
} | |
\def\gcp@loop@b#1{% | |
\def\@tempa{#1}% | |
\ifx\@tempa\gcp@const@@close | |
\advance \gcp@@count by -1 | |
\else\ifx\@tempa\gcp@const@@open | |
\advance \gcp@@count by 1 | |
\fi\fi | |
\toks0\expandafter{\gcp@@res}% | |
\ifx\gcp@token\mwm@bgtoken | |
\toks1{{#1}}% | |
\else | |
\toks1{#1}% | |
\fi | |
\edef\gcp@@res{\the\toks0 \the\toks1}% | |
\ifnum\gcp@@count>0 | |
\expandafter\gcp@loop | |
\else | |
\expandafter\gcp@end | |
\fi | |
} | |
\def\gcp@end{% | |
\toks0\expandafter{\gcp@@res} | |
\global\edef\gcp@@result{\the\toks0} | |
\global\let\mwm@next\gcp@return | |
\endgroup | |
\mwm@next | |
} | |
\def\res#1 to #2;{#1|_{#2}} | |
\begin{document} | |
$\adicsp M$ | |
$\adicsp( M)$ % OK | |
$\adicsp (M)$ % OK | |
$\adicsp(ABCDE)$ % OK | |
$\adicsp(ABC D EF)$ % OK | |
$\adicsp(A(B)C)$ % OK | |
$\adicsp(A \adicsp(B) C)$ % OK | |
$\adicsp(A \adicsp B C)$ % OK | |
$\adicsp(\res f to U ;)$ % OK | |
$\adicsp(f|_{U \times V})$ % OK | |
%$\adicsp(\map f from X to Y ;)$ % OK | |
$\paren(N^{N^N} + \paren(\frac 1 2 + \paren(3)))$ % OK | |
$\paren(N_{N^N} + \paren(\frac 1 2 + \paren(3)))$ % OK | |
%\def\A{\greedysubscript{A}} | |
%$\paren(\A_0_L \tensor_L \Lbar)$ | |
\end{document} | |
\makeatother |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment