-
Notifications
You must be signed in to change notification settings - Fork 4
/
TexAppend.ado
33 lines (24 loc) · 888 Bytes
/
TexAppend.ado
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
program TexAppend
version 10
set more off
syntax anything(name=filepath) [, using(string) landscape compile slide]
splitpath `filepath'
local filepath `r(directory)'`r(filename)'.tex
splitpath `using'
local using `r(directory)'`r(filename)'.tex
local using=subinstr("`using'","/","\/", .)
if "`landscape'"==""{
local replacement "\\input{`using'}"
}
else{
local replacement "\\begin{landscape}`prefix'input{`using'}`prefix'end{landscape}"
}
if "`slide'" != ""{
local replacement "\\begin{frame} `replacement' \\end{frame}"
}
* if `replacement' is not found in `filepath', replace end document by `replacement' (with sed) and add \end{document} as a new line (with echo)
!grep -q -e "`replacement'" `filepath' || (sed -i"" -e 's/\(\\\end{document}\)/`replacement'/' "`filepath'" && echo '\\end{document}' >> `filepath')
if "`compile'"~=""{
TexCompile `filepath', open
}
end