开发者

Latex - extract substring/ignore characters

I have the following problem. I have defined a macro, \func as follows

\newcommand{\func}[1]{% do something with #1  
X #1 Y
}

I now want to define another macro

\newcommand{\MyFunc}[1]{  
% parse #1 and if it contains "\func{....}", ignore all except this part
% otherwise ignore #1 
}

Can someone tell me how to implement \MyFu开发者_如何学Gonc?

Here is what should happen:

\MyFunc{123abcdefg}              % should print nothing
\MyFunc{123\func{abcd}efg}       % should print X abcd Y

I can only change the code of \MyFunc. \func should remain as it is.


This can be done with standard LaTeX programming. Something like:

\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}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜