Skip to content

Commit 3cfa442

Browse files
committed
feat: compile twice if engine is not latex
1 parent 392d449 commit 3cfa442

File tree

6 files changed

+80
-19
lines changed

6 files changed

+80
-19
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ go.work
22
go.work.off
33
go.work.sum
44
dist
5+
autopdf
6+
main
57

68
.auctex-auto

autopdf

-16.9 MB
Binary file not shown.

internal/tex/compile.go

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,49 @@ func (c *Compiler) Compile(texFile string) (string, error) {
7474
var cmd *exec.Cmd
7575
// Create command to run
7676
var cmdErr error
77-
78-
if dirOutput == "." {
79-
cmdStr := fmt.Sprintf("%s -interaction=nonstopmode -jobname=%s %s", engine, baseNameOutput, texFile)
80-
cmd = exec.Command("sh", "-c", cmdStr)
81-
log.Printf("Running command: %s", cmd.String())
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
77+
78+
if engine != "pdflatex" {
79+
for i := 0; i < 2; i++ {
80+
if dirOutput == "." {
81+
cmdStr := fmt.Sprintf("%s -interaction=nonstopmode -jobname=%s %s", engine, baseNameOutput, texFile)
82+
cmd = exec.Command("sh", "-c", cmdStr)
83+
log.Printf("Running command: %s", cmd.String())
84+
cmdErr = cmd.Run()
85+
if cmdErr != nil {
86+
log.Printf("Warning: LaTeX command reported errors: %s", cmdErr)
87+
// Don't return error yet - check if file was created
88+
}
89+
} else {
90+
cmdStr := fmt.Sprintf("%s -interaction=nonstopmode -jobname=%s -output-directory=%s %s", engine, baseNameOutput, dirOutput, texFile)
91+
cmd = exec.Command("sh", "-c", cmdStr)
92+
log.Printf("Running command: %s", cmd.String())
93+
cmdErr = cmd.Run()
94+
if cmdErr != nil {
95+
log.Printf("Warning: LaTeX command reported errors: %s", cmdErr)
96+
// Don't return error yet - check if file was created
97+
}
98+
}
8699
}
87100
} else {
88-
cmdStr := fmt.Sprintf("%s -interaction=nonstopmode -jobname=%s -output-directory=%s %s", engine, baseNameOutput, dirOutput, texFile)
89-
cmd = exec.Command("sh", "-c", cmdStr)
90-
log.Printf("Running command: %s", cmd.String())
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
95-
}
101+
if dirOutput == "." {
102+
cmdStr := fmt.Sprintf("%s -interaction=nonstopmode -jobname=%s %s", engine, baseNameOutput, texFile)
103+
cmd = exec.Command("sh", "-c", cmdStr)
104+
log.Printf("Running command: %s", cmd.String())
105+
cmdErr = cmd.Run()
106+
if cmdErr != nil {
107+
log.Printf("Warning: LaTeX command reported errors: %s", cmdErr)
108+
// Don't return error yet - check if file was created
109+
}
110+
} else {
111+
cmdStr := fmt.Sprintf("%s -interaction=nonstopmode -jobname=%s -output-directory=%s %s", engine, baseNameOutput, dirOutput, texFile)
112+
cmd = exec.Command("sh", "-c", cmdStr)
113+
log.Printf("Running command: %s", cmd.String())
114+
cmdErr = cmd.Run()
115+
if cmdErr != nil {
116+
log.Printf("Warning: LaTeX command reported errors: %s", cmdErr)
117+
// Don't return error yet - check if file was created
118+
}
119+
}
96120
}
97121

98122
// Normalize output path with .pdf extension
@@ -113,7 +137,7 @@ func (c *Compiler) Compile(texFile string) (string, error) {
113137
}
114138
return "", fmt.Errorf("error checking output file: %w", statErr)
115139
}
116-
140+
117141
// Check if file is empty
118142
if fileInfo.Size() == 0 {
119143
return "", errors.New("PDF output file was created but is empty")
@@ -213,4 +237,4 @@ var CompileCmd = &bonzai.Cmd{
213237
}
214238
return nil
215239
},
216-
}
240+
}

test/model_xelatex/config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
template: "./main.tex"
2+
output: "./out/output"
3+
variables:
4+
engine: "lualatex"
5+
conversion:
6+
enabled: false

test/model_xelatex/main.tex

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
\documentclass{scrartcl}
2+
\usepackage[utf8]{inputenc}
3+
\usepackage[T1]{fontenc}
4+
\usepackage[dvipsnames]{xcolor}
5+
\usepackage[object=vectorian]{pgfornament}
6+
\usetikzlibrary{calc}
7+
\definecolor{fondpaille}{cmyk}{0,0,0.1,0}
8+
9+
\begin{document}
10+
\pagecolor{fondpaille}
11+
\color{Maroon}
12+
\begin{tikzpicture}[every node/.style={inner sep=0pt}]
13+
\node[text width=8cm,align=center](Text){%
14+
main pdf
15+
} ;
16+
\node[shift={(-1cm,1cm)},anchor=north west](CNW) at (Text.north west)
17+
{\pgfornament[width=2cm]{61}};
18+
\node[shift={(1cm,1cm)},anchor=north east](CNE) at (Text.north east)
19+
{\pgfornament[width=2cm,symmetry=v]{61}};
20+
\node[shift={(-1cm,-1cm)},anchor=south west](CSW) at (Text.south west)
21+
{\pgfornament[width=2cm,symmetry=h]{61}};
22+
\node[shift={(1cm,-1cm)},anchor=south east](CSE) at (Text.south east)
23+
{\pgfornament[width=2cm,symmetry=c]{61}};
24+
\pgfornamenthline{CNW}{CNE}{north}{87}
25+
\pgfornamenthline{CSW}{CSE}{south}{87}
26+
\pgfornamentvline{CNW}{CSW}{west}{87}
27+
\pgfornamentvline{CNE}{CSE}{east}{87}
28+
\end{tikzpicture}
29+
\end{document}

test/model_xelatex/out/output.pdf

2.25 MB
Binary file not shown.

0 commit comments

Comments
 (0)