
Insiro muitas tabelas em um arquivo tex e quero substituir "Erros padrão entre parênteses" em cada tabela por "Qualquer coisa que eu quiser".
exemplo
\documentclass[12pt,a4paper]{article}
\usepackage[UTF8]{ctex}
\begin{document}
\input{table.tex}
\input{table.tex}
\end{document}
tabela.tex
\begin{table}[htbp]\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{table \label{tab3}}
\begin{tabular}{l*{3}{c}}
\hline\hline
&\multicolumn{1}{c}{(1)E}&\multicolumn{1}{c}{(2)W}&\multicolumn{1}{c}{(3)M}\\
\hline
ln$\chi$ & 3.163\sym{***}& 4.133\sym{***}& 2.017\sym{***}\\
& (0.696) & (0.451) & (0.442) \\
\hline
FE & Y & Y & Y \\
N & 1005 & 980 & 825 \\
R2 & 0.660 & 0.583 & 0.624 \\
\hline\hline
\multicolumn{4}{l}{\footnotesize Standard errors in parentheses}\\
\multicolumn{4}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
\end{tabular}
\end{table}
IDE:Texpad 1.731
Motor: Xelatex, BibTex
Responder1
Se usar LuaLaTeX for uma opção para você, seguir a abordagem mostrada no exemplo a seguir pode funcionar para você. Uma função Lua, chamada dosub
, é configurada para realizar as operações de substituição de strings, e o código LaTeX é fornecido para limitar a operação desta função aos table
ambientes. Conseqüentemente, as instâncias da string "Erros padrão entre parênteses" que podem ocorrer fora table
dos ambientes internos são deixadas intactas.
% !TeX program = lualatex
\RequirePackage{filecontents}
%% create the files 'table1.tex' and 'table2.tex'
\begin{filecontents}{table1.tex}
\begin{table}[htbp]
\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{A first table \label{tab1}}
\begin{tabular}{l*{3}{c}}
\hline\hline
&\multicolumn{1}{c}{(1)E}&\multicolumn{1}{c}{(2)W}&\multicolumn{1}{c}{(3)M}\\
\hline
$\ln\chi$ & 3.163\sym{***}& 4.133\sym{***}& 2.017\sym{***}\\
& (0.696) & (0.451) & (0.442) \\
\hline
FE & Y & Y & Y \\
N & 1005 & 980 & 825 \\
R\sym{2} & 0.660 & 0.583 & 0.624 \\
\hline\hline
\multicolumn{4}{l}{\footnotesize Standard errors in parentheses}\\
\multicolumn{4}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
\end{tabular}
\end{table}
\end{filecontents}
\begin{filecontents}{table2.tex}
\begin{table}[htbp]
\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{A second table \label{tab2}}
\begin{tabular}{l*{3}{c}}
\hline\hline
&\multicolumn{1}{c}{(1)A}&\multicolumn{1}{c}{(2)B}&\multicolumn{1}{c}{(3)C}\\
\hline
$\ln\chi$ & 3.163\sym{***}& 4.133\sym{***}& 2.017\sym{***}\\
& (0.696) & (0.451) & (0.442) \\
\hline
FE & Y & Y & Y \\
N & 1005 & 980 & 825 \\
R\sym{2} & 0.660 & 0.583 & 0.624 \\
\hline\hline
\multicolumn{4}{l}{\footnotesize Standard errors in parentheses}\\
\multicolumn{4}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
\end{tabular}
\end{table}
\end{filecontents}
\documentclass[12pt,a4paper]{article}
%%\usepackage[UTF8]{ctex}
%>>>> --- new code starts here ---
\usepackage{luacode,etoolbox}
\begin{luacode}
function dosub ( s )
return ( string.gsub ( s , "Standard errors in parentheses",
"Anything I want" ) )
end
\end{luacode}
\AtBeginEnvironment{table}{\directlua{
luatexbase.add_to_callback("process_input_buffer", dosub, "dosub" ) }}
\AtEndEnvironment{table}{\directlua{
luatexbase.remove_from_callback("process_input_buffer", "dosub" ) }}
%<<<< --- new code ends here ---
\begin{document}
\input table1
This instance of ``Standard errors in parentheses'' is not modified.
\input table2
\end{document}
Responder2
Eu usaria GNU grep
e GNU perl
para isso se você estiver usando um sistema baseado em Unix.Você precisará conhecer o terminal de linha de comando se planeja substituir texto arbitrário em um número arbitrário de arquivos.
Se estiver usando um sistema baseado em DOS, você pode simplesmente instalar algo como Babun para uma máquina virtual Linux mínima e rápida e um emulador de terminal.
Configurar simulação em pasta vazia
1. Crie 10 tabelas com a string desejada
for i in $(echo table{01..10}.tex); do touch $i && echo "Standard errors in parentheses & col2 & col3 \\\\" > $i;done
2. Use expressão regular (dialeto Perl) recursivamente para listar correspondências (para fins de inspeção)
grep -Prn 'Standard errors in parentheses'
3. Substitua o texto recursivamente usando Perl e saída do Grep
perl -i -pe 's/Standard errors in parentheses/whatever/g' $(grep -Prl 'Standard errors in parentheses')
Notas
Se quiser garantir que a substituição esteja funcionando corretamente antes de gravar nos arquivos, você pode gravar no terminal.
perl -pe 's/Standard errors in parentheses/whatever/g' $(grep -Prl 'Standard errors in parentheses')
ou salve o backup com extensão .bak
perl -i.bak -pe 's/Standard errors in parentheses/whatever/g' $(grep -Prl 'Standard errors in parentheses')
Tenho trabalhado profissionalmente com textos grandes há vários anos e experimentei diferentes dialetos de linguagem de expressão regular. Pela minha experiência, Perl é o dialeto mais útil e aceito.
- retrospectivas e retrospectivas, que são extremamente úteis
- operador não ganancioso (domesticar os espaços reservados como,
*
por?)
exemplo, Você deseja encontrar o conteúdo de todos\paragraph{...}
os s, mas algum outro\macro{}
pode estar na mesma linha. Basta digitargrep -Prn '\\paragraph\{.*?\}'
para parar no primeiro}
.