在 estout 命令生成的文件中添加 TeX 代码



我正在使用社区贡献estout命令生成具有回归结果的TeX文件,我想知道是否可以为这些文件添加额外的TeX行。

更具体地说,我想在生成的文件的开头添加以下行:

documentclass[leqno,11pt]{article}
usepackage{booktabs}
usepackage{tabularx}
begin{document}

我还想在文件末尾添加以下行:

end{document}

我之所以问这个问题,是因为我会反复生成相同的表,并且每次运行回归时,我想查看编译的pdf而不是TeX代码。

社区贡献的命令tabout具有我上面描述的选项。

estout有类似的选择吗?

获取所需内容的一种方法是编写一个程序,该程序使用file命令创建复合标记文档:

program define mytex
version 14
local texfile "`1'"
tempname myreadfile mywritefile
file open `mywritefile' using "new_`texfile'", write replace text
file write `mywritefile' "documentclass[leqno,11pt]{article}" _newline
file write `mywritefile' "usepackage{booktabs}" _newline
file write `mywritefile' "usepackage{tabularx}" _newline
file write `mywritefile' "begin{document}" _newline
file write `mywritefile' _newline
file close `mywritefile'
file open `myreadfile' using "`texfile'", read text
file open `mywritefile' using "new_`texfile'", write append text
file read `myreadfile' line
file write `mywritefile' `"`line'"' _newline
while r(eof) == 0 {
file read `myreadfile' line
file write `mywritefile' `"`line'"' _newline
}
file close `myreadfile'
file close `mywritefile'
file open `mywritefile' using "new_`texfile'", write append text
file write `mywritefile' "end{document}" _newline
file close `mywritefile'
end

现在假设您有一个estout生成的TeX文件example.tex其中包含以下内容:

. type example.tex
title{Introduction to LaTeX{}}
author{Author's Name}
maketitle
begin{abstract}
The abstract text goes here.
end{abstract}
section{Introduction}
Here is the text of your introduction.
begin{equation}
label{simple_equation}
alpha = sqrt{ beta }
end{equation}
subsection{Subsection Heading Here}
Write your subsection text here.
section{Conclusion}
Write your conclusion here.

通过运行这个小程序,你会得到一个文件new_example.tex

. mytex example.tex
. type new_example.tex  
documentclass[leqno,11pt]{article}
usepackage{booktabs}
usepackage{tabularx}
begin{document}

title{Introduction to LaTeX{}}
author{Author's Name}
maketitle
begin{abstract}
The abstract text goes here.
end{abstract}
section{Introduction}
Here is the text of your introduction.
begin{equation}
label{simple_equation}
alpha = sqrt{ beta }
end{equation}
subsection{Subsection Heading Here}
Write your subsection text here.
section{Conclusion}
Write your conclusion here.

end{document}

当然,源TeX文件的内容(来自estout(可以是任何TeX标记。


编辑:

正如OP现在在评论中提到的那样,estout具有preheadpostfoot选项,用于在生成的表格之前和之后添加文本。这些似乎支持TeX标记。

但是,这里提出的解决方案更加灵活(例如,对于多行(,可扩展,当然还可以推广到estout之外。


最新更新