首页 > 解决方案 > 我需要将文本放在他们的图形/表格引用附近。我的实际文本放在文档末尾。使用perl如何实现?

问题描述

%%Figure-9
\begin{figure}[t]
\figurebox{}{}{1}[fgene-10-00561-g009]
\caption{Ectopic expression of \textit{TaPP2C135} in 
\textit{Arabidopsis}. \textbf{(A)}~Expression levels of}
\end{figure}

需要将上图文本放置在段落的引用末尾附近,引用将在文本“.... (\hyperref[F9]{\textbf{Figure~9}})”中。

请帮助天才,我是初学者!

标签: perl

解决方案


在 tex 文件中,我们找不到具有简单逻辑的结尾段落。因此,我将图形放在图形引用的末尾。

use strict;
use warnings;

my $texcontent = ' Sample content...
Need to place the above figure text near to citation end of paragraph, Citation would be in text ".... (\hyperref[F9]{\textbf{Figure~1}})."

Need to place the above figure text near to citation end of paragraph, Citation would be in text ".... (\hyperref[F9]{\textbf{Figure~2}})."

Need to place the above figure text near to citation end of paragraph, Citation would be in text ".... (\hyperref[F9]{\textbf{Figure~9}})."

Need to place the above figure text near to citation end of paragraph, Citation would be in text ".... (\hyperref[F9]{\textbf{Figure~3}})."

%%Figure-1
\begin{figure}[t]
\figurebox{}{}{1}[fgene-10-00561-g009]
\caption{Ectopic expression of \textit{TaPP2C135} in 
\textit{Arabidopsis}. \textbf{(A)}~Expression levels of}
\end{figure}

%%Figure-2
\begin{figure}[t]
\figurebox{}{}{1}[fgene-10-00561-g009]
\caption{Ectopic expression of \textit{TaPP2C135} in 
\textit{Arabidopsis}. \textbf{(A)}~Expression levels of}
\end{figure}

%%Figure-3
\begin{figure}[t]
\figurebox{}{}{1}[fgene-10-00561-g009]
\caption{Ectopic expression of \textit{TaPP2C135} in 
\textit{Arabidopsis}. \textbf{(A)}~Expression levels of}
\end{figure}

';

my ($pre,$match,$post) = "";
while($texcontent=~m/\%\%(Figure\-(?:[\w]+))\n?\\begin\{(figure\*?)\}((?:(?!\\end\{\2\}).)*)\\end\{\2\}/gs)
{
    $pre = $pre.$`; $match = $&; $post = $'; (my $figId = $1)=~s/\-/\~/i; #%%Figure-1 replaced with Figure~1

    if($pre=~m/$figId\}\}\)/i) #Searching the ID
    {
        $match=~s/\{figure/\{completedfigure/i; #Completed the figures changed to completedfigures.
        $pre=~s/$figId\}\}\)/$&\n<figplacedhere>$match<figplacedhere>/i; #TAG Placed figures identification 
        $match = "";
    }

    $pre = $pre.$match; $texcontent = $post;
}

if(length $pre) {  $texcontent = $pre.$post;  }

$texcontent=~s/<figplacedhere>//g; $texcontent=~s/\{completedfigure/\{figure/g;

print "--\n$texcontent\n--\n";

纯粹根据您的输入,我已经更新了代码,除非样本输入不同,否则代码可能不起作用。


推荐阅读