@@ -73,25 +73,50 @@ func (c *Compiler) Compile(texFile string) (string, error) {
7373
7474 var cmd * exec.Cmd
7575 // Create command to run
76+ var cmdErr error
77+
7678 if dirOutput == "." {
7779 cmdStr := fmt .Sprintf ("%s -interaction=nonstopmode -jobname=%s %s" , engine , baseNameOutput , texFile )
7880 cmd = exec .Command ("sh" , "-c" , cmdStr )
7981 log .Printf ("Running command: %s" , cmd .String ())
80- if err := cmd .Run (); err != nil {
81- log .Printf ("Error running command: %s" , err )
82+ cmdErr = cmd .Run ()
83+ if cmdErr != nil {
84+ log .Printf ("Warning: LaTeX command reported errors: %s" , cmdErr )
85+ // Don't return error yet - check if file was created
8286 }
8387 } else {
8488 cmdStr := fmt .Sprintf ("%s -interaction=nonstopmode -jobname=%s -output-directory=%s %s" , engine , baseNameOutput , dirOutput , texFile )
8589 cmd = exec .Command ("sh" , "-c" , cmdStr )
8690 log .Printf ("Running command: %s" , cmd .String ())
87- if err := cmd .Run (); err != nil {
88- log .Printf ("Error running command: %s" , err )
91+ cmdErr = cmd .Run ()
92+ if cmdErr != nil {
93+ log .Printf ("Warning: LaTeX command reported errors: %s" , cmdErr )
94+ // Don't return error yet - check if file was created
8995 }
9096 }
9197
92- // Check if output PDF exists
93- if _ , err := os .Stat (fmt .Sprintf ("%s.pdf" , outputPDF )); os .IsNotExist (err ) {
94- return "" , errors .New ("PDF output file was not created" )
98+ // Normalize output path with .pdf extension
99+ outputPDFWithExt := outputPDF
100+ if ! strings .HasSuffix (outputPDF , ".pdf" ) {
101+ outputPDFWithExt = outputPDF + ".pdf"
102+ }
103+
104+ // Check if output PDF exists and has content
105+ fileInfo , statErr := os .Stat (outputPDFWithExt )
106+ if statErr != nil {
107+ if os .IsNotExist (statErr ) {
108+ // File doesn't exist, return the original command error
109+ if cmdErr != nil {
110+ return "" , fmt .Errorf ("PDF output file was not created: %w" , cmdErr )
111+ }
112+ return "" , errors .New ("PDF output file was not created" )
113+ }
114+ return "" , fmt .Errorf ("error checking output file: %w" , statErr )
115+ }
116+
117+ // Check if file is empty
118+ if fileInfo .Size () == 0 {
119+ return "" , errors .New ("PDF output file was created but is empty" )
95120 }
96121
97122 return outputPDF , nil
@@ -188,4 +213,4 @@ var CompileCmd = &bonzai.Cmd{
188213 }
189214 return nil
190215 },
191- }
216+ }
0 commit comments