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

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

问题描述

我有以下问题.我定义了一个宏,func如下


ewcommand{func}[1]{% do something with #1X #1 是}

我现在想定义另一个宏


ewcommand{MyFunc}[1]{% parse #1 如果它包含func{....}",则忽略除此部分之外的所有内容% 否则忽略 #1}

谁能告诉我如何实现MyFunc?

这是应该发生的事情:

MyFunc{123abcdefg} % 不应该打印任何内容MyFunc{123func{abcd}efg} % 应该打印 X abcd Y

我只能更改 MyFunc 的代码.func 应该保持原样.

解决方案

这可以通过标准的 LaTeX 编程来完成.比如:

<上一页>documentclass{文章} ewcommandfunc[1]{X #1 Y}makeatletter ewcommandMyFunc[1]{%in@{func}{#1}%ifin@ignore@all@but@func#1@nilfi}defignore@all@but@func#1func#2#3@nil{func{#2}}makeatother开始{文档}[MyFunc{123abcdefg}] % 不应该打印任何内容[MyFunc{123func{abcd}efg}] % 应该打印 X abcd Y结束{文档}

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


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

I now want to define another macro


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

Can someone tell me how to implement MyFunc?

Here is what should happen:

MyFunc{123abcdefg}              % should print nothing
MyFunc{123func{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}

ewcommandfunc[1]{X #1 Y}
makeatletter

ewcommandMyFunc[1]{%
  in@{func}{#1}%
  ifin@
    ignore@all@but@func#1@nil
  fi
}
defignore@all@but@func#1func#2#3@nil{func{#2}}
makeatother
egin{document}
[MyFunc{123abcdefg}]              % should print nothing
[MyFunc{123func{abcd}efg}]       % should print X abcd Y
end{document}

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

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