我有一个名为a.tex的.tex文件,其中包含多行文本,如下例所示:
\begin{pycode}
Some text right here, let's say Text 1A: like: There are #cat and #dog.
\end{pycode}
Some text right here, let's say Text 1B: like: One day the #dog tried to run away.
\begin{pycode}
Some text right here, let's say Text 2A: like: There are #cat and #dog and #pig.
\end{pycode}
Some text right here, let's say Text 2B: like: There is #something here.
我想将任何#改为"所提及文本的编号",例如,句子"有#只cat 和#只狗".应该变成"这是一只狗和一只cat ."因为它在文本1a中."有一天,这只#狗试图逃跑."变成了"有一天那只狗试图逃跑.""有#只cat 、#只狗和#只猪."改为"有2只cat 、2只狗和2只猪",依此类推.
输出是一个.tex文件,此更改应用于整个文档.
所以我想要的是:
\begin{pycode}
Some text right here, let's say Text 1A: like: There are 1cat and 1dog.
\end{pycode}
Some text right here, let's say Text 1B: like: One day the 1dog tried to run away.
\begin{pycode}
Some text right here, let's say Text 2A: like: There are 2cat and 2dog and 2pig.
\end{pycode}
Some text right here, let's say Text 2B: like: There is 2something here.
我在这方面没有最低限度的工作.我的 idea 是从第一行开始搜索和替换.例如,如果我们看到"Begin{pycode}"则s=s+1(对于某些计数变量s)并搜索#,然后用s替换它,直到我们遇到下一个"Begin{pycode}".
我正在用这种方式寻找解决方案,但仍然需要时间来找到解决方案.
谢谢你的帮助.