Latex - 提取子字符串/忽略字符 [英] Latex - extract substring/ignore characters

查看:200
本文介绍了Latex - 提取子字符串/忽略字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题。我已经定义了一个宏 \ func ,如下所示

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

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

我现在要定义另一个宏

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

有人能告诉我如何实现 \ MyFyFunc

Can someone tell me how to implement \MyFunc?

以下是应该发生的事情:

Here is what should happen:

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

我只能更改 \ MyFyFunc 的代码。 \ func 应保持原样。

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

推荐答案

这可以是完成标准的LaTeX编程。类似于:

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}

这篇关于Latex - 提取子字符串/忽略字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆