빈 폴더에 시뮬레이션 설정

빈 폴더에 시뮬레이션 설정

tex 파일에 많은 테이블을 입력하고 각 테이블의 "괄호 안의 표준 오류"를 "내가 원하는 모든 것"으로 바꾸고 싶습니다.

\documentclass[12pt,a4paper]{article}
\usepackage[UTF8]{ctex}

\begin{document}

\input{table.tex}
\input{table.tex}

\end{document}

테이블.텍스

\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:텍스트패드 1.731

엔진: Xelatex, BibTex

답변1

LuaLaTeX를 사용하는 것이 선택 사항이라면 다음 예제에 표시된 접근 방식을 추구하는 것이 도움이 될 수 있습니다. dosub문자열 대체 작업을 수행하도록 Lua 함수가 설정되고 이 함수의 작업을 table환경으로 제한하기 위해 LaTeX 코드가 제공됩니다. 따라서 내부 환경 이외에서 발생할 수 있는 "괄호 안의 표준 오류" 문자열 인스턴스는 table그대로 유지됩니다.

여기에 이미지 설명을 입력하세요

% !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}

답변2

Unix 기반 시스템을 사용하는 경우 이를 위해 GNU grep와 GNU를 사용합니다 .perl임의의 수의 파일에서 임의의 텍스트를 바꾸려는 경우 명령줄 터미널을 사용하는 방법을 알아야 합니다.

DOS 기반을 사용하는 경우 빠른 최소 Linux 가상 머신 및 터미널 에뮬레이터를 위해 Babun과 같은 것을 설치할 수 있습니다.

빈 폴더에 시뮬레이션 설정

1. 원하는 문자열로 테이블 10개 생성

for i in $(echo table{01..10}.tex); do touch $i && echo "Standard errors in parentheses & col2 & col3 \\\\" > $i;done

2. 정규식(Perl Dialect)을 반복적으로 사용하여 일치 항목 나열(검사 목적)

grep -Prn 'Standard errors in parentheses'

3. Perl과 Grep의 출력을 사용하여 재귀적으로 텍스트 바꾸기

perl -i -pe 's/Standard errors in parentheses/whatever/g' $(grep -Prl 'Standard errors in parentheses')

노트

파일에 쓰기 전에 교체가 제대로 작동하는지 확인하려면 터미널에 쓸 수 있습니다.

perl -pe 's/Standard errors in parentheses/whatever/g' $(grep -Prl 'Standard errors in parentheses')

또는 .bak 확장자로 백업을 저장하세요.

perl -i.bak -pe 's/Standard errors in parentheses/whatever/g' $(grep -Prl 'Standard errors in parentheses')

나는 몇 년 동안 전문적으로 큰 텍스트를 다루어 왔으며 다양한 정규식 언어 방언을 실험해 왔습니다. 내 경험에 따르면 Perl은 가장 유용하고 널리 사용되는 방언입니다.

  • 매우 유용한 미리보기 및 되돌아보기
  • 탐욕스럽지 않은 연산자( 예: *와 같은 자리 표시자 길들이기 ?)) ​​모든 s의 내용을 찾고 싶지만 \paragraph{...}다른 내용이 \macro{}같은 줄에 있을 수 있습니다. 간단히 입력하여 grep -Prn '\\paragraph\{.*?\}'첫 번째 에서 중지하세요 }.

관련 정보