use cmdargs if passed for doc build

This commit is contained in:
lukas 2021-08-26 22:40:56 +02:00
parent a1be37c771
commit 89960a86ae

24
Main.go
View File

@ -25,7 +25,7 @@ func main() {
} }
func compileAndInstall() { func compileAndInstall() {
out, err := compileLatex("main.tex") out, err := compileLatex()
if err != nil { if err != nil {
fmt.Println("An error occured while compiling the document!") fmt.Println("An error occured while compiling the document!")
@ -100,8 +100,8 @@ func commandExists(cmd string) bool {
return err == nil return err == nil
} }
// parse the thumbail picture from video file // compile latex document with passed cmd args (or default ones if nothing passed) and return output or error
func compileLatex(filename string) (*string, error) { func compileLatex() (*string, error) {
app := "" app := ""
if commandExists("latexmk") { if commandExists("latexmk") {
app = "latexmk" app = "latexmk"
@ -111,12 +111,20 @@ func compileLatex(filename string) (*string, error) {
return nil, fmt.Errorf(ErrNoCompiler) return nil, fmt.Errorf(ErrNoCompiler)
} }
cmd := exec.Command(app, argsWithoutProg := os.Args[1:]
"-file-line-error", filename := "main.tex"
if len(argsWithoutProg) > 0 {
filename = argsWithoutProg[len(argsWithoutProg)-1]
// cut last arg --> filename
argsWithoutProg = argsWithoutProg[:len(argsWithoutProg)-1]
}
// insert default args
argsWithoutProg = append(argsWithoutProg, "-file-line-error",
"-interaction=nonstopmode", "-interaction=nonstopmode",
"-synctex=1", "-synctex=1",
"-output-format=pdf", "-output-format=pdf", filename)
filename) cmd := exec.Command(app, argsWithoutProg...)
stdout, _ := cmd.StdoutPipe() stdout, _ := cmd.StdoutPipe()
stderr, _ := cmd.StderrPipe() stderr, _ := cmd.StderrPipe()
@ -151,6 +159,7 @@ func compileLatex(filename string) (*string, error) {
var i = 0 var i = 0
// printPoint print a point with every 10th method call
func printPoint() { func printPoint() {
if i%10 == 0 { if i%10 == 0 {
fmt.Printf(".") fmt.Printf(".")
@ -163,6 +172,7 @@ func printPoint() {
} }
} }
// rootCheck perform a root user check
func rootCheck() bool { func rootCheck() bool {
cmd := exec.Command("id", "-u") cmd := exec.Command("id", "-u")
output, err := cmd.Output() output, err := cmd.Output()