Jus*_*s12 6 parsing latex if-statement token tex
我有以下问题.我已经定义了一个宏,\func如下所示
\newcommand{\func}[1]{% do something with #1
X #1 Y
}
Run Code Online (Sandbox Code Playgroud)
我现在想要定义另一个宏
\newcommand{\MyFunc}[1]{
% parse #1 and if it contains "\func{....}", ignore all except this part
% otherwise ignore #1
}
Run Code Online (Sandbox Code Playgroud)
谁能告诉我如何实施\MyFunc?
这是应该发生的事情:
\MyFunc{123abcdefg} % should print nothing
\MyFunc{123\func{abcd}efg} % should print X abcd Y
Run Code Online (Sandbox Code Playgroud)
我只能改变代码\MyFunc.\func应保持原样.
Wil*_*son 11
这可以通过标准的LaTeX编程来完成.就像是:
\documentclass{article}
\newcommand\func[1]{X #1 Y}
\makeatletter
\newcommand\MyFunc[1]{%
\in@{\func}{#1}%
\ifin@
\ignore@all@but@func#1\@nil
\fi
}
\def\ignore@all@but@func#1\func#2#3\@nil{\func{#2}}
\makeatother
\begin{document}
[\MyFunc{123abcdefg}] % should print nothing
[\MyFunc{123\func{abcd}efg}] % should print X abcd Y
\end{document}